Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: add convenience ctor for async trigger id scope #19204

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/async_wrap-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ inline v8::MaybeLocal<v8::Value> AsyncWrap::MakeCallback(
return MakeCallback(cb_v.As<v8::Function>(), 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
Expand Down
3 changes: 1 addition & 2 deletions src/async_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,7 @@ static void PromiseHook(PromiseHookType type, Local<Promise> 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);
Expand Down
3 changes: 3 additions & 0 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ class Environment {
DefaultTriggerAsyncIdScope() = delete;
explicit DefaultTriggerAsyncIdScope(Environment* env,
double init_trigger_async_id);
explicit DefaultTriggerAsyncIdScope(AsyncWrap* async_wrap);
~DefaultTriggerAsyncIdScope();

private:
Expand Down
3 changes: 1 addition & 2 deletions src/pipe_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ Local<Object> 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<Function> constructor = env->pipe_constructor_template()->GetFunction();
CHECK_EQ(false, constructor.IsEmpty());
Expand Down
9 changes: 3 additions & 6 deletions src/stream_base-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ inline int StreamBase::Shutdown(v8::Local<v8::Object> 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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -383,8 +381,7 @@ void StreamBase::JSMethod(const FunctionCallbackInfo<Value>& 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));
}

Expand Down
9 changes: 3 additions & 6 deletions src/tcp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ Local<Object> 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<Function> constructor = env->tcp_constructor_template()->GetFunction();
CHECK_EQ(constructor.IsEmpty(), false);
Expand Down Expand Up @@ -289,8 +288,7 @@ void TCPWrap::Connect(const FunctionCallbackInfo<Value>& 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(),
Expand Down Expand Up @@ -326,8 +324,7 @@ void TCPWrap::Connect6(const FunctionCallbackInfo<Value>& 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(),
Expand Down
6 changes: 2 additions & 4 deletions src/udp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,7 @@ void UDPWrap::DoSend(const FunctionCallbackInfo<Value>& 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;
Expand Down Expand Up @@ -511,8 +510,7 @@ Local<Object> 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);
Expand Down