diff --git a/src/async_wrap-inl.h b/src/async_wrap-inl.h index cc6377d82a0fee..21b1f9cee9f0e8 100644 --- a/src/async_wrap-inl.h +++ b/src/async_wrap-inl.h @@ -64,6 +64,13 @@ inline v8::MaybeLocal AsyncWrap::MakeCallback( return MakeCallback(cb_v.As(), argc, argv); } + +// Defined here to avoid a circular dependency with env-inl.h. +inline Environment::AsyncHooks::DefaultTriggerAsyncIdScope + ::DefaultTriggerAsyncIdScope(AsyncWrap* async_wrap) + : DefaultTriggerAsyncIdScope(async_wrap->env(), + async_wrap->get_async_id()) {} + } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS diff --git a/src/async_wrap.cc b/src/async_wrap.cc index 239e607b05ab77..b6776364a5301f 100644 --- a/src/async_wrap.cc +++ b/src/async_wrap.cc @@ -312,8 +312,7 @@ static void PromiseHook(PromiseHookType type, Local promise, parent_wrap = PromiseWrap::New(env, parent_promise, nullptr, true); } - AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope( - env, parent_wrap->get_async_id()); + AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(parent_wrap); wrap = PromiseWrap::New(env, promise, parent_wrap, silent); } else { wrap = PromiseWrap::New(env, promise, nullptr, silent); diff --git a/src/env-inl.h b/src/env-inl.h index 8883903cb1810c..31f2af402417dc 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -179,6 +179,9 @@ inline void Environment::AsyncHooks::clear_async_id_stack() { fields_[kStackLength] = 0; } +// The DefaultTriggerAsyncIdScope(AsyncWrap*) constructor is defined in +// async_wrap-inl.h to avoid a circular dependency. + inline Environment::AsyncHooks::DefaultTriggerAsyncIdScope ::DefaultTriggerAsyncIdScope(Environment* env, double default_trigger_async_id) diff --git a/src/env.h b/src/env.h index 2fd3254ed72efb..e6060b9e6faab9 100644 --- a/src/env.h +++ b/src/env.h @@ -431,6 +431,7 @@ class Environment { DefaultTriggerAsyncIdScope() = delete; explicit DefaultTriggerAsyncIdScope(Environment* env, double init_trigger_async_id); + explicit DefaultTriggerAsyncIdScope(AsyncWrap* async_wrap); ~DefaultTriggerAsyncIdScope(); private: diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index 016ce480b6a809..14ac671b92b5bb 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -54,8 +54,7 @@ Local PipeWrap::Instantiate(Environment* env, AsyncWrap* parent, PipeWrap::SocketType type) { EscapableHandleScope handle_scope(env->isolate()); - AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(env, - parent->get_async_id()); + AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(parent); CHECK_EQ(false, env->pipe_constructor_template().IsEmpty()); Local constructor = env->pipe_constructor_template()->GetFunction(); CHECK_EQ(false, constructor.IsEmpty()); diff --git a/src/stream_base-inl.h b/src/stream_base-inl.h index 81adf7a866b927..1534dcd1d53359 100644 --- a/src/stream_base-inl.h +++ b/src/stream_base-inl.h @@ -164,8 +164,7 @@ inline int StreamBase::Shutdown(v8::Local req_wrap_obj) { ->NewInstance(env->context()).ToLocalChecked(); } - AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope( - env, GetAsyncWrap()->get_async_id()); + AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(GetAsyncWrap()); ShutdownWrap* req_wrap = CreateShutdownWrap(req_wrap_obj); int err = DoShutdown(req_wrap); @@ -202,8 +201,7 @@ inline StreamWriteResult StreamBase::Write( ->NewInstance(env->context()).ToLocalChecked(); } - AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope( - env, GetAsyncWrap()->get_async_id()); + AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(GetAsyncWrap()); WriteWrap* req_wrap = CreateWriteWrap(req_wrap_obj); err = DoWrite(req_wrap, bufs, count, send_handle); @@ -383,8 +381,7 @@ void StreamBase::JSMethod(const FunctionCallbackInfo& args) { if (!wrap->IsAlive()) return args.GetReturnValue().Set(UV_EINVAL); - AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope( - handle->env(), handle->get_async_id()); + AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(handle); args.GetReturnValue().Set((wrap->*Method)(args)); } diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index 61b08217b8f129..cd6ed3cef0a5bf 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -57,8 +57,7 @@ Local TCPWrap::Instantiate(Environment* env, AsyncWrap* parent, TCPWrap::SocketType type) { EscapableHandleScope handle_scope(env->isolate()); - AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope( - env, parent->get_async_id()); + AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(parent); CHECK_EQ(env->tcp_constructor_template().IsEmpty(), false); Local constructor = env->tcp_constructor_template()->GetFunction(); CHECK_EQ(constructor.IsEmpty(), false); @@ -289,8 +288,7 @@ void TCPWrap::Connect(const FunctionCallbackInfo& args) { int err = uv_ip4_addr(*ip_address, port, &addr); if (err == 0) { - AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope( - env, wrap->get_async_id()); + AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(wrap); ConnectWrap* req_wrap = new ConnectWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_TCPCONNECTWRAP); err = uv_tcp_connect(req_wrap->req(), @@ -326,8 +324,7 @@ void TCPWrap::Connect6(const FunctionCallbackInfo& args) { int err = uv_ip6_addr(*ip_address, port, &addr); if (err == 0) { - AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope( - env, wrap->get_async_id()); + AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(wrap); ConnectWrap* req_wrap = new ConnectWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_TCPCONNECTWRAP); err = uv_tcp_connect(req_wrap->req(), diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index 27be93abd0e5d8..e7d97dc484250c 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -359,8 +359,7 @@ void UDPWrap::DoSend(const FunctionCallbackInfo& args, int family) { SendWrap* req_wrap; { - AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope( - env, wrap->get_async_id()); + AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(wrap); req_wrap = new SendWrap(env, req_wrap_obj, have_callback); } size_t msg_size = 0; @@ -511,8 +510,7 @@ Local UDPWrap::Instantiate(Environment* env, AsyncWrap* parent, UDPWrap::SocketType type) { EscapableHandleScope scope(env->isolate()); - AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope( - env, parent->get_async_id()); + AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(parent); // If this assert fires then Initialize hasn't been called yet. CHECK_EQ(env->udp_constructor_function().IsEmpty(), false);