【问题标题】:In V8 why does Isolate::GetCurrent() return NULL?在 V8 中,为什么 Isolate::GetCurrent() 返回 NULL?
【发布时间】:2014-05-23 09:02:06
【问题描述】:

我已经在 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() 添加为程序中的第一个调用,但这并不能解决问题。

【问题讨论】:

  • stackoverflow.com/questions/16924087/… ,你可能错过了对 V8::initialize(); 的调用,这可能也是示例中的文档错误
  • 我找不到任何对 V8::initialize() 的引用 - 它是否已从 API 中删除?
  • 不完全确定,虽然它是在您指向Isolate::GetCurrent()的链接文件中定义的

标签: c++ ubuntu v8 libv8


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-26
      • 2016-12-28
      • 1970-01-01
      • 2014-06-26
      • 1970-01-01
      • 1970-01-01
      • 2015-11-25
      • 2015-07-04
      相关资源
      最近更新 更多