This project is read-only.

Recursive JavascriptContexts

Aug 5, 2010 at 7:15 AM

My JavaScript code hooks into C# code that recursively starts up another piece of JavaScript.  This causes a problem because JavaScriptContext::Enter/Exit are not reentrant.  I have fixed this problem in my copy of the library by replacing sCurrentContext with a List<JavascriptContext^>^, which I use as a stack.  However I wonder whether this is the best way.  Can we instead use v8's GetCurrent() to implement JavascriptContext::GetCurrent()?  But if so, how would we get from the v8 Context back to a JavascriptContext?

Aug 10, 2010 at 4:18 PM

Some design shortcuts were taken, especially regarding context handling with GetCurrent( ). I believe the stack you created should let you work around your problem.

This issue will not be fixed in release 0.3 (by next week) but it should be handled shortly in an incoming release.




Aug 16, 2010 at 2:28 PM

Hi Oliver,

I'm running into the same issue.
Would you mind sharing the code changes for your solution? 

Aug 24, 2010 at 1:36 AM

Sorry for the slow reply.  I replaced my List-based fix with one close to the originals:

    sOldContext = sCurrentContext;
    sCurrentContext = this;

    sCurrentContext = sOldContext;

This takes advantage of the fact that a recursive execution of the JavaScript engine should have its own JavascriptContext object.