Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4a971f6

Browse filesBrowse files
Stephen Belangertargos
authored andcommitted
async_hooks: eliminate require side effects
PR-URL: #40782 Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
1 parent 82b4226 commit 4a971f6
Copy full SHA for 4a971f6

File tree

Expand file treeCollapse file tree

2 files changed

+10
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+10
-5
lines changed
Open diff view settings
Collapse file

‎lib/internal/async_hooks.js‎

Copy file name to clipboardExpand all lines: lib/internal/async_hooks.js
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ function callbackTrampoline(asyncId, resource, cb, ...args) {
137137
return result;
138138
}
139139

140-
setCallbackTrampoline(callbackTrampoline);
141-
142140
const topLevelResource = {};
143141

144142
function executionAsyncResource() {
@@ -372,6 +370,8 @@ function promiseResolveHook(promise) {
372370
let wantPromiseHook = false;
373371
function enableHooks() {
374372
async_hook_fields[kCheck] += 1;
373+
374+
setCallbackTrampoline(callbackTrampoline);
375375
}
376376

377377
let stopPromiseHook;
@@ -398,6 +398,8 @@ function disableHooks() {
398398

399399
wantPromiseHook = false;
400400

401+
setCallbackTrampoline();
402+
401403
// Delay the call to `disablePromiseHook()` because we might currently be
402404
// between the `before` and `after` calls of a Promise.
403405
enqueueMicrotask(disablePromiseHookIfNecessary);
Collapse file

‎src/async_wrap.cc‎

Copy file name to clipboardExpand all lines: src/async_wrap.cc
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,11 @@ void AsyncWrap::QueueDestroyAsyncId(const FunctionCallbackInfo<Value>& args) {
327327
void AsyncWrap::SetCallbackTrampoline(const FunctionCallbackInfo<Value>& args) {
328328
Environment* env = Environment::GetCurrent(args);
329329

330-
CHECK(args[0]->IsFunction());
331-
332-
env->set_async_hooks_callback_trampoline(args[0].As<Function>());
330+
if (args[0]->IsFunction()) {
331+
env->set_async_hooks_callback_trampoline(args[0].As<Function>());
332+
} else {
333+
env->set_async_hooks_callback_trampoline(Local<Function>());
334+
}
333335
}
334336

335337
Local<FunctionTemplate> AsyncWrap::GetConstructorTemplate(Environment* env) {
@@ -439,6 +441,7 @@ void AsyncWrap::Initialize(Local<Object> target,
439441
env->set_async_hooks_after_function(Local<Function>());
440442
env->set_async_hooks_destroy_function(Local<Function>());
441443
env->set_async_hooks_promise_resolve_function(Local<Function>());
444+
env->set_async_hooks_callback_trampoline(Local<Function>());
442445
env->set_async_hooks_binding(target);
443446
}
444447

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.