在V8中,为什么Isolate::GetCurrent()返回NULL ?

In V8 why does Isolate::GetCurrent() return NULL?

本文关键字:返回 NULL GetCurrent 为什么 Isolate V8      更新时间:2023-10-16

我在Ubuntu上编译了V8,并且有一个非常简单的V8程序isolate_test.cc。它基于来自Google的Hello World示例:

#include <v8.h> 
using namespace v8;
int main(int argc, char* argv[]) {
    V8::initialize();
    Isolate* isolate = Isolate::GetCurrent(); //Always returns NULL
    return 0; 
}
我用来编译这个程序的命令是:
g++ -Iinclude -g isolate_test.cc -o isolate_test -Wl,--start-group out/x64.debug/obj.target/{tools/gyp/libv8_{base,snapshot},third_party/icu/libicu{uc,i18n,data}}.a -Wl,--end-group -lrt -lpthread

问题是Isolate::GetCurrent()总是返回NULL。为什么会发生这种情况,获得当前Isolate的正确方法是什么?

我可能会偏离轨道,但我的第一个想法是这与Isolate::GetCurrent()无法从libpthread获得当前线程有关。

Update:根据这个问题,我添加了V8::initialize()作为程序中的第一个调用,但是这并不能解决问题。

我有同样的问题。我真的不知道潜在的原因,但这里的NULL意味着没有创建和输入默认隔离。显而易见的解决方法是手动执行

Isolate* isolate = Isolate::GetCurrent(); // returns NULL
if (!isolate) {
    isolate = Isolate::New();
    isolate->Enter();
}

默认隔离已从v8中删除。因此,GetCurrent()不再默认初始化。

以下是更改的问题:https://code.google.com/p/chromium/issues/detail?id=359977