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: refactor emit before/after/promiseResolve #19295

Closed
wants to merge 1 commit into from
Closed
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
34 changes: 13 additions & 21 deletions src/async_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,25 @@ static void DestroyAsyncIdsCallback(void* arg) {
}


void AsyncWrap::EmitPromiseResolve(Environment* env, double async_id) {
void Emit(Environment* env, double async_id, AsyncHooks::Fields type,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps inline void Emit(...?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasnell Imo we shouldn’t be adding inline to functions that aren’t defined in the corresponding -inl.h header

Also, @bnoordhuis pointed out somewhere else that we should put the inline specifier on the declarations in the .h header file

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I'm good with that.

Local<Function> fn) {
AsyncHooks* async_hooks = env->async_hooks();

if (async_hooks->fields()[AsyncHooks::kPromiseResolve] == 0)
if (async_hooks->fields()[type] == 0)
return;

Local<Value> async_id_value = Number::New(env->isolate(), async_id);
Local<Function> fn = env->async_hooks_promise_resolve_function();
FatalTryCatch try_catch(env);
USE(fn->Call(env->context(), Undefined(env->isolate()), 1, &async_id_value));
}


void AsyncWrap::EmitPromiseResolve(Environment* env, double async_id) {
Emit(env, async_id, AsyncHooks::kPromiseResolve,
env->async_hooks_promise_resolve_function());
}


void AsyncWrap::EmitTraceEventBefore() {
switch (provider_type()) {
#define V(PROVIDER) \
Expand All @@ -192,15 +198,8 @@ void AsyncWrap::EmitTraceEventBefore() {


void AsyncWrap::EmitBefore(Environment* env, double async_id) {
AsyncHooks* async_hooks = env->async_hooks();

if (async_hooks->fields()[AsyncHooks::kBefore] == 0)
return;

Local<Value> async_id_value = Number::New(env->isolate(), async_id);
Local<Function> fn = env->async_hooks_before_function();
FatalTryCatch try_catch(env);
USE(fn->Call(env->context(), Undefined(env->isolate()), 1, &async_id_value));
Emit(env, async_id, AsyncHooks::kBefore,
env->async_hooks_before_function());
}


Expand All @@ -221,17 +220,10 @@ void AsyncWrap::EmitTraceEventAfter() {


void AsyncWrap::EmitAfter(Environment* env, double async_id) {
AsyncHooks* async_hooks = env->async_hooks();

if (async_hooks->fields()[AsyncHooks::kAfter] == 0)
return;

// If the user's callback failed then the after() hooks will be called at the
// end of _fatalException().
Local<Value> async_id_value = Number::New(env->isolate(), async_id);
Local<Function> fn = env->async_hooks_after_function();
FatalTryCatch try_catch(env);
USE(fn->Call(env->context(), Undefined(env->isolate()), 1, &async_id_value));
Emit(env, async_id, AsyncHooks::kAfter,
env->async_hooks_after_function());
}

class PromiseWrap : public AsyncWrap {
Expand Down