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

后端 未结 2 2087
走了就别回头了
走了就别回头了 2020-12-23 19:34

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 access

2条回答
  •  猫巷女王i
    2020-12-23 20:19

    Isolates, as the name suggests, are completely closed to the outside world, so Isolates can run in parallel since they are different instances of V8 entirely. Think of an Isolate as a sandbox--a V8 runtime environment.

    Now within an Isolate, you are likely to have numerous unrelated JavaScript applications running simultaneously. JavaScript provides a lot of global-level language facilities, and having multiple unrelated applications mess with these "singletons" is not a good idea. So within an instance of V8 called an Isolate, you can define multiple Contexts so that unrelated applications can do what they need to do without interfering with each other.

    This is not a perfect analogy, but if you know Java web stuff, imagine multiple instances of Tomcat deployed on the same machine and then each instance of Tomcat running separate applications with their own web contexts and web.xml's. It's kind of like that.

    Hope that helps.

提交回复
热议问题