title: How to enter a v8::Persistent<v8::Context> in a multithreaded environment?
body: <p>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:</p>
  
  <pre><code>void myclass::run(const std::string &amp; code, v8::Persistsent&lt;v8::Context&gt; &amp; con)
  {
    boost::asio::io_service::strand &amp; strand = this-&gt;_strand;
    // strand guarantee at most one handler will be executed concurrently
    strand.post([&amp;]() {
      v8::Isolate::Scope isolate_scope(this-&gt;get_isolate());
      v8::HandleScope handle_scope(this-&gt;get_isolate());
  
      // This code below will compile but undefined is allways returned.
      // Because v8::Persistent&lt;v8::Context&gt; 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&lt;v8::Context&gt; context = v8::Local&lt;v8::Context&gt;::New(this-&gt;get_isolate(), con);
      v8::Context::Scope context_scope(context); // auto enter/leave. 
  
  
      // Compile the source code.
      v8::Local&lt;v8::String&gt; source = v8::String::NewFromUtf8(_isolate, code.c_str());
  
      v8::Local&lt;v8::Script&gt; script = v8::Script::Compile(source);
  
      v8::Local&lt;v8::Value&gt; result = script-&gt;Run();
      // result is allways undefined, what am I doing wrong?
    });
  }
  </code></pre>
  
  <p>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?</p>
  
  <p>Thanks in advance!</p>