-
-
Save indutny/f0202f9fa89fa19b95aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/node.cc b/src/node.cc | |
index 32cff12..6cf1d43 100644 | |
--- a/src/node.cc | |
+++ b/src/node.cc | |
@@ -109,6 +109,9 @@ static Persistent<String> code_symbol; | |
static Persistent<String> rss_symbol; | |
static Persistent<String> heap_total_symbol; | |
static Persistent<String> heap_used_symbol; | |
+static Persistent<String> enter_symbol; | |
+static Persistent<String> exit_symbol; | |
+static Persistent<String> disposed_symbol; | |
static Persistent<String> fatal_exception_symbol; | |
@@ -932,31 +935,46 @@ MakeCallback(const Handle<Object> object, | |
TryCatch try_catch; | |
- if (process_makeCallback.IsEmpty()) { | |
- Local<Value> cb_v = process->Get(String::New("_makeCallback")); | |
- if (!cb_v->IsFunction()) { | |
- fprintf(stderr, "process._makeCallback assigned to non-function\n"); | |
- abort(); | |
+ if (enter_symbol.IsEmpty()) { | |
+ enter_symbol = NODE_PSYMBOL("enter"); | |
+ exit_symbol = NODE_PSYMBOL("exit"); | |
+ disposed_symbol = NODE_PSYMBOL("_disposed"); | |
+ } | |
+ | |
+ Local<Value> domain_v = object->Get(domain_symbol); | |
+ Local<Object> domain; | |
+ Local<Function> enter; | |
+ Local<Function> exit; | |
+ if (domain_v->IsObject()) { | |
+ domain = domain_v->ToObject(); | |
+ if (domain->Get(disposed_symbol)->BooleanValue()) { | |
+ // domain has been disposed of. | |
+ return Undefined(); | |
} | |
- Local<Function> cb = cb_v.As<Function>(); | |
- process_makeCallback = Persistent<Function>::New(cb); | |
+ enter = Local<Function>::Cast(domain->Get(enter_symbol)); | |
+ enter->Call(domain, 0, NULL); | |
} | |
- Local<Array> argArray = Array::New(argc); | |
- for (int i = 0; i < argc; i++) { | |
- argArray->Set(Integer::New(i, node_isolate), argv[i]); | |
+ if (try_catch.HasCaught()) { | |
+ FatalException(try_catch); | |
+ return Undefined(); | |
} | |
- Local<Value> object_l = Local<Value>::New(node_isolate, object); | |
- Local<Value> callback_l = Local<Value>::New(node_isolate, callback); | |
+ Local<Value> ret = callback->Call(object, argc, argv); | |
- Local<Value> args[3] = { object_l, callback_l, argArray }; | |
+ if (try_catch.HasCaught()) { | |
+ FatalException(try_catch); | |
+ return Undefined(); | |
+ } | |
- Local<Value> ret = process_makeCallback->Call(process, ARRAY_SIZE(args), args); | |
+ if (domain_v->IsObject()) { | |
+ exit = Local<Function>::Cast(domain->Get(exit_symbol)); | |
+ exit->Call(domain, 0, NULL); | |
+ } | |
if (try_catch.HasCaught()) { | |
FatalException(try_catch); | |
- return Undefined(node_isolate); | |
+ return Undefined(); | |
} | |
return scope.Close(ret); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment