javascript v8 是怎么编译的?

How is javascript compiled by v8?

hello-world为例。 我有几个问题:

  1. v8::Isolate 是做什么的?是否创建新线程
  2. v8::Isolate::Scope 是做什么的?
  3. v8::HandleScope 是做什么的?
  4. v8::Local<v8::Context> 是做什么的?
  5. v8::Script::Compile 是做什么的?是不是直接把js代码编译成机器码?

感谢您的帮助!

参见official wiki

  • An isolate is a VM instance with its own heap.
  • A local handle is a pointer to an object. All V8 objects are accessed using handles, they are necessary because of the way the V8 garbage collector works.
  • A handle scope can be thought of as a container for any number of handles. When you've finished with your handles, instead of deleting each one individually you can simply delete their scope.
  • A context is an execution environment that allows separate, unrelated, JavaScript code to run in a single instance of V8. You must explicitly specify the context in which you want any JavaScript code to be run.

These concepts are discussed in greater detail in the Embedder's Guide.

阅读现有文档后,如果仍有任何不清楚的地方,请提出更具体的问题。

关于 (5):在当前版本的 V8 中,v8::Script::Compile 为 V8 的解释器编译字节码。在早期版本中,它编译未优化的机器代码。不同之处在于您无需担心的内部实现细节:-)