@@ -100,6 +100,7 @@ Persistent<String> process_symbol;
100
100
Persistent<String> domain_symbol;
101
101
102
102
static Persistent<Object> process;
103
+ static Persistent<Function> process_tickCallback;
103
104
104
105
static Persistent<String> exports_symbol;
105
106
@@ -114,7 +115,9 @@ static Persistent<String> heap_used_symbol;
114
115
115
116
static Persistent<String> fatal_exception_symbol;
116
117
117
- static Persistent<Function> process_makeCallback;
118
+ static Persistent<String> enter_symbol;
119
+ static Persistent<String> exit_symbol;
120
+ static Persistent<String> disposed_symbol;
118
121
119
122
120
123
static bool print_eval = false ;
@@ -926,11 +929,6 @@ MakeCallback(const Handle<Object> object,
926
929
Handle <Value> argv[]) {
927
930
HandleScope scope;
928
931
929
- if (argc > 6 ) {
930
- fprintf (stderr, " node::MakeCallback - Too many args (%d)\n " , argc);
931
- abort ();
932
- }
933
-
934
932
Local<Value> callback_v = object->Get (symbol);
935
933
if (!callback_v->IsFunction ()) {
936
934
String::Utf8Value method (symbol);
@@ -945,27 +943,60 @@ MakeCallback(const Handle<Object> object,
945
943
946
944
TryCatch try_catch;
947
945
948
- if (process_makeCallback.IsEmpty ()) {
949
- Local<Value> cb_v = process->Get (String::New (" _makeCallback" ));
950
- if (!cb_v->IsFunction ()) {
951
- fprintf (stderr, " process._makeCallback assigned to non-function\n " );
952
- abort ();
946
+ if (enter_symbol.IsEmpty ()) {
947
+ enter_symbol = NODE_PSYMBOL (" enter" );
948
+ exit_symbol = NODE_PSYMBOL (" exit" );
949
+ disposed_symbol = NODE_PSYMBOL (" _disposed" );
950
+ }
951
+
952
+ Local<Value> domain_v = object->Get (domain_symbol);
953
+ Local<Object> domain;
954
+ Local<Function> enter;
955
+ Local<Function> exit ;
956
+ if (!domain_v->IsUndefined ()) {
957
+ domain = domain_v->ToObject ();
958
+ if (domain->Get (disposed_symbol)->BooleanValue ()) {
959
+ // domain has been disposed of.
960
+ return Undefined (node_isolate);
953
961
}
954
- Local<Function> cb = cb_v. As <Function>( );
955
- process_makeCallback = Persistent<Function>:: New (cb );
962
+ enter = Local <Function>:: Cast (domain-> Get (enter_symbol) );
963
+ enter-> Call (domain, 0 , NULL );
956
964
}
957
965
958
- Local<Array> argArray = Array::New (argc);
959
- for ( int i = 0 ; i < argc; i++) {
960
- argArray-> Set ( Integer::New (i, node_isolate), argv[i] );
966
+ if (try_catch. HasCaught ()) {
967
+ FatalException (try_catch);
968
+ return Undefined ( node_isolate);
961
969
}
962
970
963
- Local<Value> object_l = Local<Value >::New (node_isolate, object );
964
- Local<Value> symbol_l = Local<Value>:: New (node_isolate, symbol );
971
+ Local<Function> callback = Local<Function >::Cast (callback_v );
972
+ Local<Value> ret = callback-> Call (object, argc, argv );
965
973
966
- Local<Value> args[3 ] = { object_l, symbol_l, argArray };
974
+ if (try_catch.HasCaught ()) {
975
+ FatalException (try_catch);
976
+ return Undefined (node_isolate);
977
+ }
967
978
968
- Local<Value> ret = process_makeCallback->Call (process, ARRAY_SIZE (args), args);
979
+ if (!domain_v->IsUndefined ()) {
980
+ exit = Local<Function>::Cast (domain->Get (exit_symbol));
981
+ exit ->Call (domain, 0 , NULL );
982
+ }
983
+
984
+ if (try_catch.HasCaught ()) {
985
+ FatalException (try_catch);
986
+ return Undefined (node_isolate);
987
+ }
988
+
989
+ // process nextTicks after every time we get called.
990
+ if (process_tickCallback.IsEmpty ()) {
991
+ Local<Value> cb_v = process->Get (String::New (" _tickCallback" ));
992
+ if (!cb_v->IsFunction ()) {
993
+ fprintf (stderr, " process._tickCallback assigned to non-function\n " );
994
+ abort ();
995
+ }
996
+ Local<Function> cb = cb_v.As <Function>();
997
+ process_tickCallback = Persistent<Function>::New (cb);
998
+ }
999
+ process_tickCallback->Call (process, NULL , 0 );
969
1000
970
1001
if (try_catch.HasCaught ()) {
971
1002
FatalException (try_catch);
0 commit comments