Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

isolates: add _newIsolate() and _joinIsolate() to process object

  • Loading branch information...
bnoordhuis committed Nov 23, 2011
1 parent 60c0f91 commit b573532e67a115ec46e55327f65e99287e87491b
Showing with 56 additions and 1 deletion.
  1. +49 −0 src/node.cc
  2. +7 −1 src/node_isolate.cc
@@ -1760,6 +1760,52 @@ static Handle<Value> Binding(const Arguments& args) {
}


static void RunIsolate(void* arg) {
uv_loop_t* loop = uv_loop_new();
Isolate* isolate = Isolate::New(loop);
}


static char magic_isolate_cookie_[] = "magic isolate cookie";


static Handle<Value> NewIsolate(const Arguments& args) {
HandleScope scope;

uv_thread_t* tid = new uv_thread_t;

if (uv_thread_create(tid, RunIsolate, NULL))
return Null();

Local<ObjectTemplate> tpl = ObjectTemplate::New();
tpl->SetInternalFieldCount(2);

Local<Object> obj = tpl->NewInstance();
obj->SetPointerInInternalField(0, magic_isolate_cookie_);
obj->SetPointerInInternalField(1, tid);

return scope.Close(obj);
}


static Handle<Value> JoinIsolate(const Arguments& args) {
HandleScope scope;

assert(args[0]->IsObject());

Local<Object> obj = args[0]->ToObject();
assert(obj->InternalFieldCount() == 2);
assert(obj->GetPointerFromInternalField(0) == magic_isolate_cookie_);

uv_thread_t* tid = (uv_thread_t*) obj->GetPointerFromInternalField(1);

if (uv_thread_join(tid))
return False(); // error
else
return True(); // ok
}


static Handle<Value> ProcessTitleGetter(Local<String> property,
const AccessorInfo& info) {
HandleScope scope;
@@ -2027,6 +2073,9 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {

NODE_SET_METHOD(process, "binding", Binding);

NODE_SET_METHOD(process, "_newIsolate", NewIsolate);
NODE_SET_METHOD(process, "_joinIsolate", JoinIsolate);

return process;
}

@@ -35,9 +35,15 @@ Isolate* Isolate::New(uv_loop_t* loop) {


Isolate::Isolate(uv_loop_t* loop) {
SLIST_INIT(&at_exit_callbacks_);
loop_ = loop;

isolate_ = v8::Isolate::GetCurrent();
SLIST_INIT(&at_exit_callbacks_);
if (isolate_ == NULL) {
isolate_ = v8::Isolate::New();
isolate_->Enter();
}

assert(isolate_->GetData() == NULL);
isolate_->SetData(this);
}

0 comments on commit b573532

Please sign in to comment.
You can’t perform that action at this time.