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

Commit

Permalink
isolates: add _newIsolate() and _joinIsolate() to process object
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis authored and ry committed Dec 9, 2011
1 parent 5c81677 commit 91697a2
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
49 changes: 49 additions & 0 deletions src/node.cc
Expand Up @@ -1820,6 +1820,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;
Expand Down Expand Up @@ -2088,6 +2134,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;
}

Expand Down
8 changes: 7 additions & 1 deletion src/node_isolate.cc
Expand Up @@ -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);
}
Expand Down

0 comments on commit 91697a2

Please sign in to comment.