在V8中为什么Isolate :: GetCurrent()返回NULL? [英] In V8 why does Isolate::GetCurrent() return NULL?

查看:282
本文介绍了在V8中为什么Isolate :: GetCurrent()返回NULL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have compiled V8 on Ubuntu and have a very simple V8 program called isolate_test.cc. It is based on the 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; 
}

我用来编译此程序的命令是:

The command I use to compile this program is:

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 的正确方法是什么?

Problem is Isolate::GetCurrent() always returns NULL. Why does this happen and what is the correct way of getting the current Isolate?

我可以离开轨道,但我的第一个想法是这涉及到 Isolate :: GetCurrent()无法从 libpthread 获取当前线程。

I could be way off track but my first thought is that this relates to Isolate::GetCurrent() being unable to get the current thread from libpthread.

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

Update: As per this question I have added V8::initialize() as the first call in the program, however this does not solve the problem.

推荐答案

我有同样的问题。我真的不知道底层的原因,但这里的NULL表示未创建并输入默认隔离。显而易见的解决方法是手动执行

I have the same issue. I don't really know the underlying reason, but NULL here means default isolate was not created and entered. The obvious workaround is to do it manually

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

这篇关于在V8中为什么Isolate :: GetCurrent()返回NULL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆