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 — async_hooks: refactor to avoid unsafe array iteration · nodejs/node@602aaf2

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • async_hooks.js
    • internal
      • async_hooks.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/async_hooks.js‎

Copy file name to clipboardExpand all lines: lib/async_hooks.js
+7-8Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class AsyncHook {
8989
// enable()/disable() are run during their execution. The following
9090
// references are reassigned to the tmp arrays if a hook is currently being
9191
// processed.
92-
const [hooks_array, hook_fields] = getHookArrays();
92+
const { 0: hooks_array, 1: hook_fields } = getHookArrays();
9393

9494
// Each hook is only allowed to be added once.
9595
if (ArrayPrototypeIncludes(hooks_array, this))
@@ -118,7 +118,7 @@ class AsyncHook {
118118
}
119119

120120
disable() {
121-
const [hooks_array, hook_fields] = getHookArrays();
121+
const { 0: hooks_array, 1: hook_fields } = getHookArrays();
122122

123123
const index = ArrayPrototypeIndexOf(hooks_array, this);
124124
if (index === -1)
@@ -195,8 +195,7 @@ class AsyncResource {
195195
emitBefore(asyncId, this[trigger_async_id_symbol], this);
196196

197197
try {
198-
const ret = thisArg === undefined ?
199-
fn(...args) :
198+
const ret =
200199
ReflectApply(fn, thisArg, args);
201200

202201
return ret;
@@ -303,25 +302,25 @@ class AsyncLocalStorage {
303302
run(store, callback, ...args) {
304303
// Avoid creation of an AsyncResource if store is already active
305304
if (ObjectIs(store, this.getStore())) {
306-
return callback(...args);
305+
return ReflectApply(callback, null, args);
307306
}
308307
const resource = new AsyncResource('AsyncLocalStorage',
309308
defaultAlsResourceOpts);
310309
// Calling emitDestroy before runInAsyncScope avoids a try/finally
311310
// It is ok because emitDestroy only schedules calling the hook
312311
return resource.emitDestroy().runInAsyncScope(() => {
313312
this.enterWith(store);
314-
return callback(...args);
313+
return ReflectApply(callback, null, args);
315314
});
316315
}
317316

318317
exit(callback, ...args) {
319318
if (!this.enabled) {
320-
return callback(...args);
319+
return ReflectApply(callback, null, args);
321320
}
322321
this.disable();
323322
try {
324-
return callback(...args);
323+
return ReflectApply(callback, null, args);
325324
} finally {
326325
this._enable();
327326
}
Collapse file

‎lib/internal/async_hooks.js‎

Copy file name to clipboardExpand all lines: lib/internal/async_hooks.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,14 +421,14 @@ function clearDefaultTriggerAsyncId() {
421421

422422
function defaultTriggerAsyncIdScope(triggerAsyncId, block, ...args) {
423423
if (triggerAsyncId === undefined)
424-
return block(...args);
424+
return ReflectApply(block, null, args);
425425
// CHECK(NumberIsSafeInteger(triggerAsyncId))
426426
// CHECK(triggerAsyncId > 0)
427427
const oldDefaultTriggerAsyncId = async_id_fields[kDefaultTriggerAsyncId];
428428
async_id_fields[kDefaultTriggerAsyncId] = triggerAsyncId;
429429

430430
try {
431-
return block(...args);
431+
return ReflectApply(block, null, args);
432432
} finally {
433433
async_id_fields[kDefaultTriggerAsyncId] = oldDefaultTriggerAsyncId;
434434
}

0 commit comments

Comments
0 (0)
You are visitor 01402503 — 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.