Skip to content

Commit eeea6e4

Browse files
LiviaMedeirosaduh95
authored andcommitted
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: #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>
1 parent 689049e commit eeea6e4

9 files changed

Lines changed: 7 additions & 30 deletions

File tree

‎lib/internal/fs/cp/cp.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const {
1010
Promise,
1111
PromisePrototypeThen,
1212
PromiseReject,
13-
SafePromiseAll,
13+
SafePromiseAllReturnArrayLike,
1414
StringPrototypeSplit,
1515
} = primordials;
1616
const {
@@ -131,7 +131,7 @@ function getStats(src, dest, opts) {
131131
const statFunc = opts.dereference ?
132132
(file) => stat(file, { bigint: true }) :
133133
(file) => lstat(file, { bigint: true });
134-
return SafePromiseAll([
134+
return SafePromiseAllReturnArrayLike([
135135
statFunc(src),
136136
PromisePrototypeThen(statFunc(dest), undefined, (err) => {
137137
if (err.code === 'ENOENT') return null;

‎lib/internal/test_runner/runner.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const {
1919
PromiseWithResolvers,
2020
RegExpPrototypeSymbolReplace,
2121
SafeMap,
22-
SafePromiseAll,
22+
SafePromiseAllReturnArrayLike,
2323
SafePromiseAllReturnVoid,
2424
SafePromiseAllSettledReturnVoid,
2525
SafeSet,
@@ -624,7 +624,7 @@ function runTestFile(path, filesWatcher, opts) {
624624
});
625625
});
626626

627-
const { 0: { 0: code, 1: signal } } = await SafePromiseAll([
627+
const { 0: { 0: code, 1: signal } } = await SafePromiseAllReturnArrayLike([
628628
once(child, 'exit', { __proto__: null, signal: t.signal }),
629629
finished(child.stdout, { __proto__: null, signal: t.signal }),
630630
]);

‎lib/internal/test_runner/test.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ const {
2929
ReflectApply,
3030
RegExpPrototypeExec,
3131
SafeMap,
32-
SafePromiseAll,
3332
SafePromiseAllReturnVoid,
3433
SafePromiseRace,
3534
SafeSet,
@@ -1956,7 +1955,7 @@ class Suite extends Test {
19561955

19571956
stopPromise = stopTest(this.timeout, this.signal);
19581957
const subtests = this.skipped || this.error ? [] : this.subtests;
1959-
const promise = SafePromiseAll(subtests, (subtests) => subtests.start());
1958+
const promise = SafePromiseAllReturnVoid(subtests, (subtests) => subtests.start());
19601959

19611960
await SafePromiseRace([promise, stopPromise]);
19621961
await after();

‎lib/internal/webstreams/readablestream.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const {
2020
PromiseReject,
2121
PromiseResolve,
2222
PromiseWithResolvers,
23-
SafePromiseAll,
23+
SafePromiseAllReturnVoid,
2424
Symbol,
2525
SymbolAsyncIterator,
2626
SymbolDispose,
@@ -1786,7 +1786,7 @@ function readableStreamPipeTo(
17861786
}
17871787

17881788
shutdownWithAnAction(
1789-
() => SafePromiseAll(actions, (action) => action()),
1789+
() => SafePromiseAllReturnVoid(actions, (action) => action()),
17901790
true,
17911791
error);
17921792
}

‎test/fixtures/test-runner/output/describe_it.snapshot‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ ok 27 - immediate resolve pass
230230
<node-internal-frames>
231231
new Promise (<anonymous>)
232232
<node-internal-frames>
233-
Array.map (<anonymous>)
234233
...
235234
# Subtest: mixing describe/it and test should work
236235
ok 2 - mixing describe/it and test should work
@@ -516,7 +515,6 @@ not ok 56 - custom inspect symbol that throws fail
516515
<node-internal-frames>
517516
new Promise (<anonymous>)
518517
<node-internal-frames>
519-
Array.map (<anonymous>)
520518
...
521519
# Subtest: sync throw fails at second
522520
not ok 2 - sync throw fails at second
@@ -530,8 +528,6 @@ not ok 56 - custom inspect symbol that throws fail
530528
stack: |-
531529
TestContext.<anonymous> (<project-root>/test/fixtures/test-runner/output/describe_it.js:311:11)
532530
<node-internal-frames>
533-
async Promise.all (index 0)
534-
<node-internal-frames>
535531
...
536532
1..2
537533
not ok 57 - subtest sync throw fails
@@ -605,8 +601,6 @@ not ok 59 - describe async throw fails
605601
failureType: 'testTimeoutFailure'
606602
error: 'test timed out after 5ms'
607603
code: 'ERR_TEST_FAILURE'
608-
stack: |-
609-
async Promise.all (index 0)
610604
...
611605
# Subtest: timed out callback test
612606
not ok 2 - timed out callback test

‎test/fixtures/test-runner/output/hooks.snapshot‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ not ok 6 - after throws - no subtests
157157
stack: |-
158158
TestContext.<anonymous> (<project-root>/test/fixtures/test-runner/output/hooks.js:94:28)
159159
<node-internal-frames>
160-
async Promise.all (index 0)
161160
...
162161
1..2
163162
not ok 7 - beforeEach throws
@@ -182,8 +181,6 @@ not ok 7 - beforeEach throws
182181
stack: |-
183182
TestContext.<anonymous> (<project-root>/test/fixtures/test-runner/output/hooks.js:100:27)
184183
<node-internal-frames>
185-
async Promise.all (index 0)
186-
<node-internal-frames>
187184
...
188185
# Subtest: 2
189186
not ok 2 - 2
@@ -223,7 +220,6 @@ not ok 8 - afterEach throws
223220
<node-internal-frames>
224221
new Promise (<anonymous>)
225222
<node-internal-frames>
226-
Array.map (<anonymous>)
227223
...
228224
# Subtest: 2
229225
ok 2 - 2
@@ -256,7 +252,6 @@ not ok 9 - afterEach when test fails
256252
<node-internal-frames>
257253
new Promise (<anonymous>)
258254
<node-internal-frames>
259-
Array.map (<anonymous>)
260255
...
261256
# Subtest: 2
262257
not ok 2 - 2

‎test/fixtures/test-runner/output/hooks_spec_reporter.snapshot‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,12 @@ test at test/fixtures/test-runner/output/hooks.js:96:3
143143
Error: beforeEach
144144
at TestContext.<anonymous> (<project-root>/test/fixtures/test-runner/output/hooks.js:94:28)
145145
at <node-internal-frames>
146-
at async Promise.all (index 0)
147146

148147
test at test/fixtures/test-runner/output/hooks.js:101:3
149148
✖ 1 (*ms)
150149
Error: afterEach
151150
at TestContext.<anonymous> (<project-root>/test/fixtures/test-runner/output/hooks.js:100:27)
152151
at <node-internal-frames>
153-
at async Promise.all (index 0)
154-
at <node-internal-frames>
155152

156153
test at test/fixtures/test-runner/output/hooks.js:102:3
157154
✖ 2 (*ms)
@@ -166,7 +163,6 @@ test at test/fixtures/test-runner/output/hooks.js:107:3
166163
at <node-internal-frames>
167164
at new Promise (<anonymous>)
168165
at <node-internal-frames>
169-
at Array.map (<anonymous>)
170166

171167
test at test/fixtures/test-runner/output/hooks.js:113:3
172168
✖ 1 (*ms)
@@ -175,7 +171,6 @@ test at test/fixtures/test-runner/output/hooks.js:113:3
175171
at <node-internal-frames>
176172
at new Promise (<anonymous>)
177173
at <node-internal-frames>
178-
at Array.map (<anonymous>)
179174

180175
test at test/fixtures/test-runner/output/hooks.js:114:3
181176
✖ 2 (*ms)

‎test/fixtures/test-runner/output/test-timeout-flag.snapshot‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ TAP version 13
99
failureType: 'testTimeoutFailure'
1010
error: 'test timed out after 100ms'
1111
code: 'ERR_TEST_FAILURE'
12-
stack: |-
13-
async Promise.all (index 0)
1412
...
1513
# Subtest: should timeout after 5ms
1614
not ok 2 - should timeout after 5ms

‎test/fixtures/test-runner/output/timeout_in_before_each_should_not_affect_further_tests.snapshot‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ gonna timeout
1414
failureType: 'hookFailed'
1515
error: 'failed running beforeEach hook'
1616
code: 'ERR_TEST_FAILURE'
17-
stack: |-
18-
async Promise.all (index 0)
1917
...
2018
# Subtest: first describe second test
2119
ok 2 - first describe second test
@@ -45,8 +43,6 @@ not gonna timeout
4543
failureType: 'hookFailed'
4644
error: 'failed running afterEach hook'
4745
code: 'ERR_TEST_FAILURE'
48-
stack: |-
49-
async Promise.all (index 0)
5046
...
5147
# Subtest: second describe second test
5248
ok 2 - second describe second test

0 commit comments

Comments
 (0)