Switching the global context

Feb 18 at 7:38 PM
Edited Feb 19 at 10:24 PM
Hello,

is there any way to create and manage global contexts (the global object as well as built-ins and intrinsics) with ClearScript?
We are using ClearScript to load and run extensions to our applications. What I would like to do is to isolate multiple such extensions from each other while still running on the same engine instance.
It seems to me that the V8 is capable of doing this because node.js has similar functionality (see https://nodejs.org/api/vm.html) and iframes in browsers also run in their own context.

Thanks for your help.
Coordinator
Feb 20 at 8:37 PM
Hi ZoneRunner,

Yes, this is possible.

Normally, when you invoke the V8ScriptEngine constructor, ClearScript creates a V8 context within a dedicated V8 runtime (a.k.a. isolate).

To create multiple V8 contexts within a single V8 runtime, use ClearScript's V8Runtime constructor and then call V8Runtime.CreateScriptEngine as necessary.

You can download ClearScript's API reference here.

Good luck!
Feb 21 at 6:28 PM
Ah great! A couple more questions:

Both, the V8Runtime constructor and the V8Runtime.CreateScriptEngine() method take debug mode and port parameters. Can I actually have a debug port per isolate or are these arguments ignored in that case? Which set of arguments has precedence if they contradict each other?
Coordinator
Feb 21 at 9:23 PM
V8 supports one debug port per isolate/runtime, although, to be honest, we've never tested multiple debug ports in a single process.

Once you've enabled debugging in a given isolate/runtime, you can't reconfigure or disable it via any API. Debug flags and ports specified subsequently for the same isolate/runtime are ignored.

By the way, be aware that V8 5.6 dropped support for the original V8 debug protocol, so debug behavior is likely to change in future ClearScript versions.
Feb 22 at 7:24 PM
Edited Feb 22 at 7:25 PM
Oh I did not notice that yet. But if I understand this correctly, it means I can directly use chrome to debug in the future. Good news then.

Thanks!