Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is the difference between v8::Isolate and v8::Context?

Tags:

v8

embedded-v8

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!

like image 345
DeX3 Avatar asked Oct 15 '13 14:10

DeX3


People also ask

What is a V8 isolate?

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.

What is a V8 context?

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.


1 Answers

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.

like image 99
BitCortex Avatar answered Oct 02 '22 00:10

BitCortex