3

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

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

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.

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

Community
  • 1
  • 1
donturner
  • 17,867
  • 8
  • 59
  • 81
  • See http://stackoverflow.com/questions/16924087/segfault-in-v8-on-windows-in-handlescope-constructor , you're probably missing a call to V8::initialize(); , which is probably also a documentation bug in the examples – nos May 23 '14 at 09:15
  • I can't find any reference to `V8::initialize()` - has it been removed from the API? – donturner May 23 '14 at 09:20
  • Not entirely sure, though it's defined in the file of your link to [Isolate::GetCurrent()](https://code.google.com/p/v8/codesearch#v8/trunk/src/api.cc&q=Isolate%3a%3aGetCurrent%28%29&sq=package%3av8&l=6523) – nos May 23 '14 at 09:30

2 Answers2

3

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();
}
Peter K
  • 1,787
  • 13
  • 15
3

The default isolate has been removed from v8. As a result, GetCurrent() is no longer initialized by default.

Here's the issue for the change: https://code.google.com/p/chromium/issues/detail?id=359977

eh9
  • 7,340
  • 20
  • 43