I trying to setup a multithreaded environment there multiple v8::Isolate objects may be entered/exited constantly to compile and run some JavaScript code. I have a method that should compile and run som javascript code in a specific Isolate/Context:
void myclass::run(const std::string & code, v8::Persistsent<v8::Context> & con)
{
boost::asio::io_service::strand & strand = this->_strand;
// strand guarantee at most one handler will be executed concurrently
strand.post([&]() {
v8::Isolate::Scope isolate_scope(this->get_isolate());
v8::HandleScope handle_scope(this->get_isolate());
// This code below will compile but undefined is allways returned.
// Because v8::Persistent<v8::Context> does not have any
// "Enter/Exit" methods so is my attempt to create a Local handle instead.
// However, as I said earlier, it does not work. Any idea how to fix it?
v8::Local<v8::Context> context = v8::Local<v8::Context>::New(this->get_isolate(), con);
v8::Context::Scope context_scope(context); // auto enter/leave.
// Compile the source code.
v8::Local<v8::String> source = v8::String::NewFromUtf8(_isolate, code.c_str());
v8::Local<v8::Script> script = v8::Script::Compile(source);
v8::Local<v8::Value> result = script->Run();
// result is allways undefined, what am I doing wrong?
});
}
As you can see in the comments in the code however, it does not work. I simply want to just enter a specfic Isolate together with a Persistent. How do I do that?
Thanks in advance!