Creating a sub-context

52 views
Skip to first unread message

Florent S.

unread,
Jul 8, 2017, 10:31:23 AM7/8/17
to v8-users
Hi everyone!

I'm looking for a way to create a sub-context, that is a context that inherit from another context.

The goal is to simulate the import feature.

1/ Create a global context
2/ Load and excute main script
3/ import creates a sub-context
4/ Load and execute the imported script in the sub-context
5/ copy some stuff from the sub-context back into the global context

I can't find a decent way to do so ...

Any clue ?

Regards, 
Florent

Ben Noordhuis

unread,
Jul 11, 2017, 8:49:33 AM7/11/17
to v8-users
What have you tried so far? What did or didn't work?

ibon tolosana

unread,
Jul 12, 2017, 5:59:57 PM7/12/17
to v8-users
There's no problem in creating as much Context objects as needed per Isolate.
When trying to detach an object from a context to reference it from another one, make sure both context objects share the same security token (SetSecurityToken) otherwise the operation will fail.

I don't really see why you'd like to create another context to load/compile/run javascript and then get a Context object reference to set on another Context. If it is for code privacy, wrapping the file contents on a different scope, pretty much like nodejs does would suffice.
Take into account that creating a Context is an expensive operation in every sense.

Hope that helps.
Reply all
Reply to author
Forward
0 new messages