GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — src: refactor emit before/after/promiseResolve · nodejs/node@e208282

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • async_wrap.cc
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/async_wrap.cc‎

Copy file name to clipboardExpand all lines: src/async_wrap.cc
+13-21Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,25 @@ static void DestroyAsyncIdsCallback(void* arg) {
166166
}
167167

168168

169-
void AsyncWrap::EmitPromiseResolve(Environment* env, double async_id) {
169+
void Emit(Environment* env, double async_id, AsyncHooks::Fields type,
170+
Local<Function> fn) {
170171
AsyncHooks* async_hooks = env->async_hooks();
171172

172-
if (async_hooks->fields()[AsyncHooks::kPromiseResolve] == 0)
173+
if (async_hooks->fields()[type] == 0)
173174
return;
174175

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

181181

182+
void AsyncWrap::EmitPromiseResolve(Environment* env, double async_id) {
183+
Emit(env, async_id, AsyncHooks::kPromiseResolve,
184+
env->async_hooks_promise_resolve_function());
185+
}
186+
187+
182188
void AsyncWrap::EmitTraceEventBefore() {
183189
switch (provider_type()) {
184190
#define V(PROVIDER) \
@@ -195,15 +201,8 @@ void AsyncWrap::EmitTraceEventBefore() {
195201

196202

197203
void AsyncWrap::EmitBefore(Environment* env, double async_id) {
198-
AsyncHooks* async_hooks = env->async_hooks();
199-
200-
if (async_hooks->fields()[AsyncHooks::kBefore] == 0)
201-
return;
202-
203-
Local<Value> async_id_value = Number::New(env->isolate(), async_id);
204-
Local<Function> fn = env->async_hooks_before_function();
205-
FatalTryCatch try_catch(env);
206-
USE(fn->Call(env->context(), Undefined(env->isolate()), 1, &async_id_value));
204+
Emit(env, async_id, AsyncHooks::kBefore,
205+
env->async_hooks_before_function());
207206
}
208207

209208

@@ -223,17 +222,10 @@ void AsyncWrap::EmitTraceEventAfter() {
223222

224223

225224
void AsyncWrap::EmitAfter(Environment* env, double async_id) {
226-
AsyncHooks* async_hooks = env->async_hooks();
227-
228-
if (async_hooks->fields()[AsyncHooks::kAfter] == 0)
229-
return;
230-
231225
// If the user's callback failed then the after() hooks will be called at the
232226
// end of _fatalException().
233-
Local<Value> async_id_value = Number::New(env->isolate(), async_id);
234-
Local<Function> fn = env->async_hooks_after_function();
235-
FatalTryCatch try_catch(env);
236-
USE(fn->Call(env->context(), Undefined(env->isolate()), 1, &async_id_value));
227+
Emit(env, async_id, AsyncHooks::kAfter,
228+
env->async_hooks_after_function());
237229
}
238230

239231
class PromiseWrap : public AsyncWrap {

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.