diff --git a/src/async_wrap-inl.h b/src/async_wrap-inl.h index 219dfa71b6cdf0..f24bdc1516fa61 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 fe4dcbdffccd9b..d8e534b5744a05 100644 --- a/src/async_wrap.cc +++ b/src/async_wrap.cc @@ -331,8 +331,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 cb501d1dae5dc7..62dd2532f87f92 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -167,6 +167,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 076dbf66b7c59f..217f52ee5c90fd 100644 --- a/src/env.h +++ b/src/env.h @@ -432,6 +432,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 b4f01f08a647a8..0f2259b789e464 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -52,8 +52,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/tcp_wrap.cc b/src/tcp_wrap.cc index bdae0ee994360c..3ad0eb4e0ce4fe 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -56,8 +56,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); @@ -294,8 +293,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(), @@ -331,8 +329,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 5b3b7f9abc9bad..da2d4445b58b73 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -356,8 +356,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; @@ -508,8 +507,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);