diff --git a/src/node_isolate.cc b/src/node_isolate.cc index b6156fdfcd..fcf5db7fd5 100644 --- a/src/node_isolate.cc +++ b/src/node_isolate.cc @@ -47,6 +47,9 @@ Isolate::Isolate(uv_loop_t* loop) { assert(v8_isolate_->GetData() == NULL); v8_isolate_->SetData(this); + v8_context_ = v8::Context::New(); + v8_context_->Enter(); + globals_init(&globals_); } @@ -77,6 +80,15 @@ void Isolate::Dispose() { it->callback_(it->arg_); delete it; } + + assert(v8_context_->InContext()); + v8_context_->Exit(); + v8_context_.Clear(); + v8_context_.Dispose(); + + v8_isolate_->Exit(); + v8_isolate_->Dispose(); + v8_isolate_ = NULL; } diff --git a/src/node_isolate.h b/src/node_isolate.h index e24bde1f85..74fe7866ba 100644 --- a/src/node_isolate.h +++ b/src/node_isolate.h @@ -62,6 +62,11 @@ public: return v8_isolate_; } + v8::Handle GetV8Context() { + NODE_ISOLATE_CHECK(this); + return v8_context_; + } + /* Register a handler that should run when the current isolate exits. * Handlers run in LIFO order. */ @@ -82,6 +87,7 @@ private: }; SLIST_HEAD(AtExitCallbacks, AtExitCallbackInfo) at_exit_callbacks_; + v8::Persistent v8_context_; v8::Isolate* v8_isolate_; uv_loop_t* loop_;