且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

v8 :: Isolate和v8 :: Context之间到底有什么区别?

更新时间:2023-11-13 13:00:40

我确定以下内容是一种简化,但对我有用.

I'm sure the following is a simplification, but it works for me.

隔离是V8运行时的独立副本,包括堆管理器,垃圾收集器等.一次只能有一个线程访问给定的隔离,但是不同的线程可以访问不同的线程同时隔离.

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.

但是,隔离不足以运行脚本.您还需要一个全局(根)对象. context 通过将隔离堆中的一个对象指定为全局对象来定义完整的脚本执行环境.

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.