@@ -790,62 +790,6 @@ bool ShouldAbortOnUncaughtException(Isolate* isolate) {
790790}
791791
792792
793- Local<Value> GetDomainProperty (Environment* env, Local<Object> object) {
794- Local<Value> domain_v =
795- object->GetPrivate (env->context (), env->domain_private_symbol ())
796- .ToLocalChecked ();
797- if (domain_v->IsObject ()) {
798- return domain_v;
799- }
800- return object->Get (env->context (), env->domain_string ()).ToLocalChecked ();
801- }
802-
803-
804- void DomainEnter (Environment* env, Local<Object> object) {
805- Local<Value> domain_v = GetDomainProperty (env, object);
806- if (domain_v->IsObject ()) {
807- Local<Object> domain = domain_v.As <Object>();
808- Local<Value> enter_v = domain->Get (env->enter_string ());
809- if (enter_v->IsFunction ()) {
810- if (enter_v.As <Function>()->Call (domain, 0 , nullptr ).IsEmpty ()) {
811- FatalError (" node::AsyncWrap::MakeCallback" ,
812- " domain enter callback threw, please report this" );
813- }
814- }
815- }
816- }
817-
818-
819- void DomainExit (Environment* env, v8::Local<v8::Object> object) {
820- Local<Value> domain_v = GetDomainProperty (env, object);
821- if (domain_v->IsObject ()) {
822- Local<Object> domain = domain_v.As <Object>();
823- Local<Value> exit_v = domain->Get (env->exit_string ());
824- if (exit_v->IsFunction ()) {
825- if (exit_v.As <Function>()->Call (domain, 0 , nullptr ).IsEmpty ()) {
826- FatalError (" node::AsyncWrap::MakeCallback" ,
827- " domain exit callback threw, please report this" );
828- }
829- }
830- }
831- }
832-
833- void SetupDomainUse (const FunctionCallbackInfo<Value>& args) {
834- Environment* env = Environment::GetCurrent (args);
835-
836- if (env->using_domains ())
837- return ;
838- env->set_using_domains (true );
839-
840- HandleScope scope (env->isolate ());
841-
842- // Do a little housekeeping.
843- env->process_object ()->Delete (
844- env->context (),
845- FIXED_ONE_BYTE_STRING (args.GetIsolate (), " _setupDomainUse" )).FromJust ();
846- }
847-
848-
849793void RunMicrotasks (const FunctionCallbackInfo<Value>& args) {
850794 args.GetIsolate ()->RunMicrotasks ();
851795}
@@ -982,11 +926,6 @@ InternalCallbackScope::InternalCallbackScope(Environment* env,
982926 // If you hit this assertion, you forgot to enter the v8::Context first.
983927 CHECK_EQ (Environment::GetCurrent (env->isolate ()), env);
984928
985- if (asyncContext.async_id == 0 && env->using_domains () &&
986- !object_.IsEmpty ()) {
987- DomainEnter (env, object_);
988- }
989-
990929 if (asyncContext.async_id != 0 ) {
991930 // No need to check a return value because the application will exit if
992931 // an exception occurs.
@@ -1016,11 +955,6 @@ void InternalCallbackScope::Close() {
1016955 AsyncWrap::EmitAfter (env_, async_context_.async_id );
1017956 }
1018957
1019- if (async_context_.async_id == 0 && env_->using_domains () &&
1020- !object_.IsEmpty ()) {
1021- DomainExit (env_, object_);
1022- }
1023-
1024958 if (IsInnerMakeCallback ()) {
1025959 return ;
1026960 }
@@ -1061,7 +995,18 @@ MaybeLocal<Value> InternalMakeCallback(Environment* env,
1061995 return Undefined (env->isolate ());
1062996 }
1063997
1064- MaybeLocal<Value> ret = callback->Call (env->context (), recv, argc, argv);
998+ Local<Function> domain_cb = env->domain_callback ();
999+ MaybeLocal<Value> ret;
1000+ if (asyncContext.async_id != 0 || domain_cb.IsEmpty () || recv.IsEmpty ()) {
1001+ ret = callback->Call (env->context (), recv, argc, argv);
1002+ } else {
1003+ Local<Array> argv_array = Array::New (env->isolate (), argc);
1004+ for (int i = 0 ; i < argc; i++) {
1005+ argv_array->Set (env->context (), i, argv[i]).FromJust ();
1006+ }
1007+ Local<Value> domain_argv[] = { callback, argv_array };
1008+ ret = domain_cb->Call (env->context (), recv, 2 , domain_argv);
1009+ }
10651010
10661011 if (ret.IsEmpty ()) {
10671012 // NOTE: For backwards compatibility with public API we return Undefined()
@@ -3339,7 +3284,6 @@ void SetupProcessObject(Environment* env,
33393284 env->SetMethod (process, " _setupProcessObject" , SetupProcessObject);
33403285 env->SetMethod (process, " _setupNextTick" , SetupNextTick);
33413286 env->SetMethod (process, " _setupPromises" , SetupPromises);
3342- env->SetMethod (process, " _setupDomainUse" , SetupDomainUse);
33433287}
33443288
33453289
0 commit comments