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

时间:2014-05-23 09:02:06

标签: c++ ubuntu v8 libv8

我在Ubuntu上编译了V8并且有一个非常简单的V8程序,叫做isolate_test.cc。它基于Hello World example from Google

#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获取当前线程有关。

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

2 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:1)

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

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