I understand that v8 contexts are supposed to be wholly separate from
each other. However, is there a "right" way to pass objects between
contexts? I'm trying to add new scoping rules to javascript. An
example may make more clear what I'm trying to accomplish:
x =5;
function someFunction(a1,a2)
{
x=7;
....
}
var newContext = newContext();
arg1 = new Object();
arg1.val =3;
arg2 = 4;
newContext.execute(someFunction, arg1,arg2);
I would want to call someFunction with a blank global object, instead
of the one already associated with the script (ie the one that has
properties x, someFunction, newContext, etc.). However, I would still
want to be able to pass arg1 and arg2 in as arguments to someFunction
when it was being executed in the other context. In the above
example, for instance, even though someFunction is executed in
newContext, the value of x in the script's global object should still
be 5.
Currently, on an execute call, I'm trying the following strategy:
- I save the arguments passed into the execute call.
- I exit all contexts I am currently in.
- Create and enter a new context.
- Take the string value of the function object, and call compile on
it.
- Find the property associated with the function's name in the new
context, cast that property to a function.
- Call "Call" on that function with the final two arguments that
were passed into the execute call (from first point).
It seems like such an approach is a) inefficient; b) potentially
unsound: ie may encounter problems with garbage collection, etc. Can
v8 be used to handle the problem I described (building the new scoping
rules I am describing)? If so, is there a better way, particularly
for passing objects between contexts? Please let me know. Thanks.
-Behram
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users