Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
isolates: have node::Isolate manage the v8::Context
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Dec 9, 2011
1 parent 7597cad commit 2821c8b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/node_isolate.cc
Expand Up @@ -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_);
}

Expand Down Expand Up @@ -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;
}


Expand Down
6 changes: 6 additions & 0 deletions src/node_isolate.h
Expand Up @@ -62,6 +62,11 @@ class 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.
* Handlers run in LIFO order.
*/
Expand All @@ -82,6 +87,7 @@ class Isolate {
};

SLIST_HEAD(AtExitCallbacks, AtExitCallbackInfo) at_exit_callbacks_;
v8::Persistent<v8::Context> v8_context_;
v8::Isolate* v8_isolate_;
uv_loop_t* loop_;

Expand Down

0 comments on commit 2821c8b

Please sign in to comment.