From 3db3f957846701fb05fc23970ee5aeb0b8851d2b Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Thu, 19 Nov 2026 15:46:58 +0800 Subject: [PATCH] lib: replace `SafePromiseAll` with `SafePromiseAllReturn*` `SafePromiseAllReturnArrayLike` and `SafePromiseReturnVoid` are safer, faster alternatives to `SafePromiseAll`. The latter should be used only when we expose returned value directly to userspace. Signed-off-by: LiviaMedeiros --- lib/internal/fs/cp/cp.js | 4 ++-- lib/internal/test_runner/runner.js | 4 ++-- lib/internal/test_runner/test.js | 3 +-- lib/internal/webstreams/readablestream.js | 4 ++-- test/fixtures/test-runner/output/describe_it.snapshot | 6 ------ test/fixtures/test-runner/output/hooks.snapshot | 5 ----- .../test-runner/output/hooks_spec_reporter.snapshot | 5 ----- test/fixtures/test-runner/output/test-timeout-flag.snapshot | 2 -- ..._in_before_each_should_not_affect_further_tests.snapshot | 4 ---- 9 files changed, 7 insertions(+), 30 deletions(-) diff --git a/lib/internal/fs/cp/cp.js b/lib/internal/fs/cp/cp.js index 1ec5a2d89cac..410ee26e001c 100644 --- a/lib/internal/fs/cp/cp.js +++ b/lib/internal/fs/cp/cp.js @@ -10,7 +10,7 @@ const { Promise, PromisePrototypeThen, PromiseReject, - SafePromiseAll, + SafePromiseAllReturnArrayLike, StringPrototypeSplit, } = primordials; const { @@ -131,7 +131,7 @@ function getStats(src, dest, opts) { const statFunc = opts.dereference ? (file) => stat(file, { bigint: true }) : (file) => lstat(file, { bigint: true }); - return SafePromiseAll([ + return SafePromiseAllReturnArrayLike([ statFunc(src), PromisePrototypeThen(statFunc(dest), undefined, (err) => { if (err.code === 'ENOENT') return null; diff --git a/lib/internal/test_runner/runner.js b/lib/internal/test_runner/runner.js index 6edb25fcc7ad..09c820eb9116 100644 --- a/lib/internal/test_runner/runner.js +++ b/lib/internal/test_runner/runner.js @@ -19,7 +19,7 @@ const { PromiseWithResolvers, RegExpPrototypeSymbolReplace, SafeMap, - SafePromiseAll, + SafePromiseAllReturnArrayLike, SafePromiseAllReturnVoid, SafePromiseAllSettledReturnVoid, SafeSet, @@ -624,7 +624,7 @@ function runTestFile(path, filesWatcher, opts) { }); }); - const { 0: { 0: code, 1: signal } } = await SafePromiseAll([ + const { 0: { 0: code, 1: signal } } = await SafePromiseAllReturnArrayLike([ once(child, 'exit', { __proto__: null, signal: t.signal }), finished(child.stdout, { __proto__: null, signal: t.signal }), ]); diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index f4557d23091e..f46b29ef8eda 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -29,7 +29,6 @@ const { ReflectApply, RegExpPrototypeExec, SafeMap, - SafePromiseAll, SafePromiseAllReturnVoid, SafePromiseRace, SafeSet, @@ -1954,7 +1953,7 @@ class Suite extends Test { stopPromise = stopTest(this.timeout, this.signal); const subtests = this.skipped || this.error ? [] : this.subtests; - const promise = SafePromiseAll(subtests, (subtests) => subtests.start()); + const promise = SafePromiseAllReturnVoid(subtests, (subtests) => subtests.start()); await SafePromiseRace([promise, stopPromise]); await after(); diff --git a/lib/internal/webstreams/readablestream.js b/lib/internal/webstreams/readablestream.js index a8abedcbc9e4..898ff3bce55e 100644 --- a/lib/internal/webstreams/readablestream.js +++ b/lib/internal/webstreams/readablestream.js @@ -20,7 +20,7 @@ const { PromiseReject, PromiseResolve, PromiseWithResolvers, - SafePromiseAll, + SafePromiseAllReturnVoid, Symbol, SymbolAsyncIterator, SymbolDispose, @@ -1786,7 +1786,7 @@ function readableStreamPipeTo( } shutdownWithAnAction( - () => SafePromiseAll(actions, (action) => action()), + () => SafePromiseAllReturnVoid(actions, (action) => action()), true, error); } diff --git a/test/fixtures/test-runner/output/describe_it.snapshot b/test/fixtures/test-runner/output/describe_it.snapshot index 772a90d98918..2e5fe0d1ee28 100644 --- a/test/fixtures/test-runner/output/describe_it.snapshot +++ b/test/fixtures/test-runner/output/describe_it.snapshot @@ -230,7 +230,6 @@ ok 27 - immediate resolve pass new Promise () - Array.map () ... # Subtest: mixing describe/it and test should work ok 2 - mixing describe/it and test should work @@ -516,7 +515,6 @@ not ok 56 - custom inspect symbol that throws fail new Promise () - Array.map () ... # Subtest: sync throw fails at second not ok 2 - sync throw fails at second @@ -530,8 +528,6 @@ not ok 56 - custom inspect symbol that throws fail stack: |- TestContext. (/test/fixtures/test-runner/output/describe_it.js:311:11) - async Promise.all (index 0) - ... 1..2 not ok 57 - subtest sync throw fails @@ -605,8 +601,6 @@ not ok 59 - describe async throw fails failureType: 'testTimeoutFailure' error: 'test timed out after 5ms' code: 'ERR_TEST_FAILURE' - stack: |- - async Promise.all (index 0) ... # Subtest: timed out callback test not ok 2 - timed out callback test diff --git a/test/fixtures/test-runner/output/hooks.snapshot b/test/fixtures/test-runner/output/hooks.snapshot index 4a576028d9b9..d0cc80b1f29c 100644 --- a/test/fixtures/test-runner/output/hooks.snapshot +++ b/test/fixtures/test-runner/output/hooks.snapshot @@ -157,7 +157,6 @@ not ok 6 - after throws - no subtests stack: |- TestContext. (/test/fixtures/test-runner/output/hooks.js:94:28) - async Promise.all (index 0) ... 1..2 not ok 7 - beforeEach throws @@ -182,8 +181,6 @@ not ok 7 - beforeEach throws stack: |- TestContext. (/test/fixtures/test-runner/output/hooks.js:100:27) - async Promise.all (index 0) - ... # Subtest: 2 not ok 2 - 2 @@ -223,7 +220,6 @@ not ok 8 - afterEach throws new Promise () - Array.map () ... # Subtest: 2 ok 2 - 2 @@ -256,7 +252,6 @@ not ok 9 - afterEach when test fails new Promise () - Array.map () ... # Subtest: 2 not ok 2 - 2 diff --git a/test/fixtures/test-runner/output/hooks_spec_reporter.snapshot b/test/fixtures/test-runner/output/hooks_spec_reporter.snapshot index e2ad150bb5f7..f229f1c17600 100644 --- a/test/fixtures/test-runner/output/hooks_spec_reporter.snapshot +++ b/test/fixtures/test-runner/output/hooks_spec_reporter.snapshot @@ -143,15 +143,12 @@ test at test/fixtures/test-runner/output/hooks.js:96:3 Error: beforeEach at TestContext. (/test/fixtures/test-runner/output/hooks.js:94:28) at - at async Promise.all (index 0) test at test/fixtures/test-runner/output/hooks.js:101:3 ✖ 1 (*ms) Error: afterEach at TestContext. (/test/fixtures/test-runner/output/hooks.js:100:27) at - at async Promise.all (index 0) - at test at test/fixtures/test-runner/output/hooks.js:102:3 ✖ 2 (*ms) @@ -166,7 +163,6 @@ test at test/fixtures/test-runner/output/hooks.js:107:3 at at new Promise () at - at Array.map () test at test/fixtures/test-runner/output/hooks.js:113:3 ✖ 1 (*ms) @@ -175,7 +171,6 @@ test at test/fixtures/test-runner/output/hooks.js:113:3 at at new Promise () at - at Array.map () test at test/fixtures/test-runner/output/hooks.js:114:3 ✖ 2 (*ms) diff --git a/test/fixtures/test-runner/output/test-timeout-flag.snapshot b/test/fixtures/test-runner/output/test-timeout-flag.snapshot index 2b5ba9d76a20..eb31f34dcd1f 100644 --- a/test/fixtures/test-runner/output/test-timeout-flag.snapshot +++ b/test/fixtures/test-runner/output/test-timeout-flag.snapshot @@ -9,8 +9,6 @@ TAP version 13 failureType: 'testTimeoutFailure' error: 'test timed out after 100ms' code: 'ERR_TEST_FAILURE' - stack: |- - async Promise.all (index 0) ... # Subtest: should timeout after 5ms not ok 2 - should timeout after 5ms diff --git a/test/fixtures/test-runner/output/timeout_in_before_each_should_not_affect_further_tests.snapshot b/test/fixtures/test-runner/output/timeout_in_before_each_should_not_affect_further_tests.snapshot index 00d349065823..1348ec5aa6bc 100644 --- a/test/fixtures/test-runner/output/timeout_in_before_each_should_not_affect_further_tests.snapshot +++ b/test/fixtures/test-runner/output/timeout_in_before_each_should_not_affect_further_tests.snapshot @@ -14,8 +14,6 @@ gonna timeout failureType: 'hookFailed' error: 'failed running beforeEach hook' code: 'ERR_TEST_FAILURE' - stack: |- - async Promise.all (index 0) ... # Subtest: first describe second test ok 2 - first describe second test @@ -45,8 +43,6 @@ not gonna timeout failureType: 'hookFailed' error: 'failed running afterEach hook' code: 'ERR_TEST_FAILURE' - stack: |- - async Promise.all (index 0) ... # Subtest: second describe second test ok 2 - second describe second test