Browse Source

isolates: have node::Isolate manage the v8::Context

v0.7.4-release
Ben Noordhuis 13 years ago
parent
commit
ca19e792c6
  1. 12
      src/node_isolate.cc
  2. 6
      src/node_isolate.h

12
src/node_isolate.cc

@ -47,6 +47,9 @@ Isolate::Isolate(uv_loop_t* loop) {
assert(v8_isolate_->GetData() == NULL); assert(v8_isolate_->GetData() == NULL);
v8_isolate_->SetData(this); v8_isolate_->SetData(this);
v8_context_ = v8::Context::New();
v8_context_->Enter();
globals_init(&globals_); globals_init(&globals_);
} }
@ -77,6 +80,15 @@ void Isolate::Dispose() {
it->callback_(it->arg_); it->callback_(it->arg_);
delete it; delete it;
} }
assert(v8_context_->InContext());
v8_context_->Exit();
v8_context_.Clear();
v8_context_.Dispose();
v8_isolate_->Exit();
v8_isolate_->Dispose();
v8_isolate_ = NULL;
} }

6
src/node_isolate.h

@ -62,6 +62,11 @@ public:
return v8_isolate_; return v8_isolate_;
} }
v8::Handle<v8::Context> GetV8Context() {
NODE_ISOLATE_CHECK(this);
return v8_context_;
}
/* Register a handler that should run when the current isolate exits. /* Register a handler that should run when the current isolate exits.
* Handlers run in LIFO order. * Handlers run in LIFO order.
*/ */
@ -82,6 +87,7 @@ private:
}; };
SLIST_HEAD(AtExitCallbacks, AtExitCallbackInfo) at_exit_callbacks_; SLIST_HEAD(AtExitCallbacks, AtExitCallbackInfo) at_exit_callbacks_;
v8::Persistent<v8::Context> v8_context_;
v8::Isolate* v8_isolate_; v8::Isolate* v8_isolate_;
uv_loop_t* loop_; uv_loop_t* loop_;

Loading…
Cancel
Save