Commit 626d61a82c5 for nodejs
commit 626d61a82c5b8f2c84da1af1d1e619c612be4609
Author: Livia Medeiros <livia@cirno.name>
Date: Mon Nov 23 01:03:56 2026 +0800
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 <livia@cirno.name>
PR-URL: https://github.com/nodejs/node/pull/67602
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Jordan Harband <ljharb@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
diff --git a/lib/internal/fs/cp/cp.js b/lib/internal/fs/cp/cp.js
index 1ec5a2d89ca..410ee26e001 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 6edb25fcc7a..09c820eb911 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 9989772ee21..ee13ac907e4 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,
@@ -1956,7 +1955,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 a8abedcbc9e..898ff3bce55 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 772a90d9891..2e5fe0d1ee2 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
<node-internal-frames>
new Promise (<anonymous>)
<node-internal-frames>
- Array.map (<anonymous>)
...
# 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
<node-internal-frames>
new Promise (<anonymous>)
<node-internal-frames>
- Array.map (<anonymous>)
...
# 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.<anonymous> (<project-root>/test/fixtures/test-runner/output/describe_it.js:311:11)
<node-internal-frames>
- async Promise.all (index 0)
- <node-internal-frames>
...
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 4a576028d9b..d0cc80b1f29 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.<anonymous> (<project-root>/test/fixtures/test-runner/output/hooks.js:94:28)
<node-internal-frames>
- async Promise.all (index 0)
...
1..2
not ok 7 - beforeEach throws
@@ -182,8 +181,6 @@ not ok 7 - beforeEach throws
stack: |-
TestContext.<anonymous> (<project-root>/test/fixtures/test-runner/output/hooks.js:100:27)
<node-internal-frames>
- async Promise.all (index 0)
- <node-internal-frames>
...
# Subtest: 2
not ok 2 - 2
@@ -223,7 +220,6 @@ not ok 8 - afterEach throws
<node-internal-frames>
new Promise (<anonymous>)
<node-internal-frames>
- Array.map (<anonymous>)
...
# Subtest: 2
ok 2 - 2
@@ -256,7 +252,6 @@ not ok 9 - afterEach when test fails
<node-internal-frames>
new Promise (<anonymous>)
<node-internal-frames>
- Array.map (<anonymous>)
...
# 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 e2ad150bb5f..f229f1c1760 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.<anonymous> (<project-root>/test/fixtures/test-runner/output/hooks.js:94:28)
at <node-internal-frames>
- at async Promise.all (index 0)
test at test/fixtures/test-runner/output/hooks.js:101:3
✖ 1 (*ms)
Error: afterEach
at TestContext.<anonymous> (<project-root>/test/fixtures/test-runner/output/hooks.js:100:27)
at <node-internal-frames>
- at async Promise.all (index 0)
- at <node-internal-frames>
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 <node-internal-frames>
at new Promise (<anonymous>)
at <node-internal-frames>
- at Array.map (<anonymous>)
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 <node-internal-frames>
at new Promise (<anonymous>)
at <node-internal-frames>
- at Array.map (<anonymous>)
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 2b5ba9d76a2..eb31f34dcd1 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 00d34906582..1348ec5aa6b 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