@@ -109,6 +109,11 @@ static Persistent<String> listeners_symbol;
109109static Persistent<String> uncaught_exception_symbol;
110110static Persistent<String> emit_symbol;
111111
112+ static Persistent<String> domain_symbol;
113+ static Persistent<String> enter_symbol;
114+ static Persistent<String> exit_symbol;
115+ static Persistent<String> disposed_symbol;
116+
112117
113118static bool print_eval = false ;
114119static bool force_repl = false ;
@@ -1017,10 +1022,47 @@ MakeCallback(const Handle<Object> object,
10171022
10181023 TryCatch try_catch;
10191024
1025+ if (domain_symbol.IsEmpty ()) {
1026+ domain_symbol = NODE_PSYMBOL (" domain" );
1027+ enter_symbol = NODE_PSYMBOL (" enter" );
1028+ exit_symbol = NODE_PSYMBOL (" exit" );
1029+ disposed_symbol = NODE_PSYMBOL (" _disposed" );
1030+ }
1031+
1032+ Local<Value> domain_v = object->Get (domain_symbol);
1033+ Local<Object> domain;
1034+ Local<Function> enter;
1035+ Local<Function> exit;
1036+ if (!domain_v->IsUndefined ()) {
1037+ domain = domain_v->ToObject ();
1038+ if (domain->Get (disposed_symbol)->BooleanValue ()) {
1039+ // domain has been disposed of.
1040+ return Undefined ();
1041+ }
1042+ enter = Local<Function>::Cast (domain->Get (enter_symbol));
1043+ enter->Call (domain, 0 , NULL );
1044+ }
1045+
1046+ if (try_catch.HasCaught ()) {
1047+ FatalException (try_catch);
1048+ return Undefined ();
1049+ }
1050+
10201051 Local<Value> ret = callback->Call (object, argc, argv);
10211052
10221053 if (try_catch.HasCaught ()) {
10231054 FatalException (try_catch);
1055+ return Undefined ();
1056+ }
1057+
1058+ if (!domain_v->IsUndefined ()) {
1059+ exit = Local<Function>::Cast (domain->Get (exit_symbol));
1060+ exit->Call (domain, 0 , NULL );
1061+ }
1062+
1063+ if (try_catch.HasCaught ()) {
1064+ FatalException (try_catch);
1065+ return Undefined ();
10241066 }
10251067
10261068 return scope.Close (ret);
0 commit comments