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

Commit

Permalink
Do not fire callbacks for disposed domains
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Apr 14, 2012
1 parent ab886be commit 054740e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/node.cc
Expand Up @@ -112,6 +112,7 @@ static Persistent<String> emit_symbol;
static Persistent<String> domain_symbol;
static Persistent<String> enter_symbol;
static Persistent<String> exit_symbol;
static Persistent<String> disposed_symbol;


static bool print_eval = false;
Expand Down Expand Up @@ -1017,6 +1018,7 @@ MakeCallback(const Handle<Object> object,
domain_symbol = NODE_PSYMBOL("domain");
enter_symbol = NODE_PSYMBOL("enter");
exit_symbol = NODE_PSYMBOL("exit");
disposed_symbol = NODE_PSYMBOL("_disposed");
}

Local<Value> domain_v = object->Get(domain_symbol);
Expand All @@ -1025,6 +1027,10 @@ MakeCallback(const Handle<Object> object,
Local<Function> exit;
if (!domain_v->IsUndefined()) {
domain = domain_v->ToObject();
if (domain->Get(disposed_symbol)->BooleanValue() == true) {
// domain has been disposed of.
return scope.Close(Undefined());
}
enter = Local<Function>::Cast(domain->Get(enter_symbol));
enter->Call(domain, 0, NULL);
}
Expand Down
5 changes: 4 additions & 1 deletion src/node.js
Expand Up @@ -238,7 +238,10 @@
for (var i = 0; i < l; i++) {
var tock = q[i];
var callback = tock.callback;
if (tock.domain) tock.domain.enter();
if (tock.domain) {
if (tock.domain._disposed) continue;
tock.domain.enter();
}
callback();
if (tock.domain) tock.domain.exit();
}
Expand Down

0 comments on commit 054740e

Please sign in to comment.