I have compiled nodejs using the "--shared" configure option. In my C++ code I have started a script in node (in its own thread) :
node::Start(argc, argv);
I have executed the following javascript to put an object into the global space :
global.someObject = new SomeObject;
I am now in C++ (on another thread) and I want to access the global "someObject". I have been thinking of using code along these lines, however the isolate vairable is NULL :
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);
auto context = isolate->GetCurrentContext(); // no longer crashes
auto global_obj = context->Global();
v8::Local<v8::Value> objinfo = global_obj->GetHiddenValue(v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), "someObject"));
Any pointers or ideas ? How do you get a valid isolate variable from node in C++ ?
You need to run isolate->Exit()
from the main thread and call isolate->Enter()
from the other thread. You should also use v8::Locker and v8::Unlocker APIs. There are some examples here.