What is the difference/connection between these objects in V8? Does a context "belong" to an Isolate or vice versa?
I know that a single Isolate may only be accessed by one thread at a time (and that's what v8::Locker is for I guess?).
I've looked through the docs but I can't seem to get a grasp on these concepts - any help is appreciated!
An isolate is an independent copy of the V8 runtime, including a heap manager, a garbage collector, etc. Only one thread may access a given isolate at a time, but different threads may access different isolates simultaneously. An isolate is not sufficient for running scripts, however.
Contexts. In V8, a context is an execution environment that allows separate, unrelated, JavaScript applications to run in a single instance of V8. You must explicitly specify the context in which you want any JavaScript code to be run.
I'm sure the following is a simplification, but it works for me.
An isolate is an independent copy of the V8 runtime, including a heap manager, a garbage collector, etc. Only one thread may access a given isolate at a time, but different threads may access different isolates simultaneously.
An isolate is not sufficient for running scripts, however. You also need a global (root) object. A context defines a complete script execution environment by designating an object in an isolate's heap as a global object.
Therefore, not only can many contexts "exist" in a given isolate, but they can also share any or all of their objects easily and safely. That's because their objects actually belong to the isolate and are protected by the isolate's exclusive lock.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With