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 59be5f8

Browse filesBrowse files
aduh95juanarbol
authored andcommitted
lib: use safe Promise alternatives when available
PR-URL: #43476 Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
1 parent bad8ecc commit 59be5f8
Copy full SHA for 59be5f8

File tree

Expand file treeCollapse file tree

6 files changed

+27
-37
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

6 files changed

+27
-37
lines changed
Open diff view settings
Collapse file

‎lib/internal/debugger/inspect_repl.js‎

Copy file name to clipboardExpand all lines: lib/internal/debugger/inspect_repl.js
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ const {
2323
ObjectKeys,
2424
ObjectValues,
2525
Promise,
26-
PromisePrototypeCatch,
2726
PromisePrototypeThen,
2827
PromiseResolve,
2928
ReflectGetOwnPropertyDescriptor,
@@ -653,8 +652,8 @@ function createRepl(inspector) {
653652
}
654653

655654
const inspectValue = (expr) =>
656-
PromisePrototypeCatch(evalInCurrentContext(expr),
657-
(error) => `<${error.message}>`);
655+
PromisePrototypeThen(evalInCurrentContext(expr), undefined,
656+
(error) => `<${error.message}>`);
658657
const lastIndex = watchedExpressions.length - 1;
659658

660659
const values = await SafePromiseAll(watchedExpressions, inspectValue);
Collapse file

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

Copy file name to clipboardExpand all lines: lib/internal/fs/cp/cp.js
+4-6Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ const {
66
ArrayPrototypeEvery,
77
ArrayPrototypeFilter,
88
Boolean,
9-
PromiseAll,
10-
PromisePrototypeCatch,
119
PromisePrototypeThen,
1210
PromiseReject,
13-
SafeArrayIterator,
11+
SafePromiseAll,
1412
StringPrototypeSplit,
1513
} = primordials;
1614
const {
@@ -128,13 +126,13 @@ function getStats(src, dest, opts) {
128126
const statFunc = opts.dereference ?
129127
(file) => stat(file, { bigint: true }) :
130128
(file) => lstat(file, { bigint: true });
131-
return PromiseAll(new SafeArrayIterator([
129+
return SafePromiseAll([
132130
statFunc(src),
133-
PromisePrototypeCatch(statFunc(dest), (err) => {
131+
PromisePrototypeThen(statFunc(dest), undefined, (err) => {
134132
if (err.code === 'ENOENT') return null;
135133
throw err;
136134
}),
137-
]));
135+
]);
138136
}
139137

140138
async function checkParentDir(destStat, src, dest, opts) {
Collapse file

‎lib/internal/modules/esm/loader.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/esm/loader.js
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ const {
1313
ObjectCreate,
1414
ObjectDefineProperty,
1515
ObjectSetPrototypeOf,
16-
PromiseAll,
1716
RegExpPrototypeExec,
18-
SafeArrayIterator,
17+
SafePromiseAll,
1918
SafeWeakMap,
2019
StringPrototypeSlice,
2120
StringPrototypeToUpperCase,
@@ -525,7 +524,7 @@ class ESMLoader {
525524
.then(({ module }) => module.getNamespace());
526525
}
527526

528-
const namespaces = await PromiseAll(new SafeArrayIterator(jobs));
527+
const namespaces = await SafePromiseAll(jobs);
529528

530529
if (!wasArr) { return namespaces[0]; } // We can skip the pairing below
531530

Collapse file

‎lib/internal/webstreams/adapters.js‎

Copy file name to clipboardExpand all lines: lib/internal/webstreams/adapters.js
+10-13Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
'use strict';
22

33
const {
4-
ArrayPrototypeMap,
5-
PromiseAll,
64
PromisePrototypeThen,
7-
PromisePrototypeFinally,
85
PromiseResolve,
6+
SafePromiseAll,
7+
SafePromisePrototypeFinally,
98
Uint8Array,
109
} = primordials;
1110

@@ -165,7 +164,7 @@ function newWritableStreamFromStreamWritable(streamWritable) {
165164
async write(chunk) {
166165
if (streamWritable.writableNeedDrain || !streamWritable.write(chunk)) {
167166
backpressurePromise = createDeferredPromise();
168-
return PromisePrototypeFinally(
167+
return SafePromisePrototypeFinally(
169168
backpressurePromise.promise, () => {
170169
backpressurePromise = undefined;
171170
});
@@ -246,10 +245,9 @@ function newStreamWritableFromWritableStream(writableStream, options = kEmptyObj
246245
writer.ready,
247246
() => {
248247
return PromisePrototypeThen(
249-
PromiseAll(
250-
ArrayPrototypeMap(
251-
chunks,
252-
(data) => writer.write(data.chunk))),
248+
SafePromiseAll(
249+
chunks,
250+
(data) => writer.write(data.chunk)),
253251
done,
254252
done);
255253
},
@@ -652,10 +650,9 @@ function newStreamDuplexFromReadableWritablePair(pair = kEmptyObject, options =
652650
writer.ready,
653651
() => {
654652
return PromisePrototypeThen(
655-
PromiseAll(
656-
ArrayPrototypeMap(
657-
chunks,
658-
(data) => writer.write(data.chunk))),
653+
SafePromiseAll(
654+
chunks,
655+
(data) => writer.write(data.chunk)),
659656
done,
660657
done);
661658
},
@@ -751,7 +748,7 @@ function newStreamDuplexFromReadableWritablePair(pair = kEmptyObject, options =
751748

752749
if (!writableClosed || !readableClosed) {
753750
PromisePrototypeThen(
754-
PromiseAll([
751+
SafePromiseAll([
755752
closeWriter(),
756753
closeReader(),
757754
]),
Collapse file

‎lib/internal/webstreams/readablestream.js‎

Copy file name to clipboardExpand all lines: lib/internal/webstreams/readablestream.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ const {
1919
PromisePrototypeThen,
2020
PromiseResolve,
2121
PromiseReject,
22-
PromiseAll,
2322
ReflectConstruct,
23+
SafePromiseAll,
2424
Symbol,
2525
SymbolAsyncIterator,
2626
SymbolToStringTag,
@@ -1319,7 +1319,7 @@ function readableStreamPipeTo(
13191319
}
13201320

13211321
shutdownWithAnAction(
1322-
async () => PromiseAll(actions.map((action) => action())),
1322+
() => SafePromiseAll(actions, (action) => action()),
13231323
true,
13241324
error);
13251325
}
Collapse file

‎lib/internal/webstreams/transformstream.js‎

Copy file name to clipboardExpand all lines: lib/internal/webstreams/transformstream.js
+7-10Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const {
44
FunctionPrototypeBind,
55
FunctionPrototypeCall,
66
ObjectDefineProperties,
7-
PromisePrototypeCatch,
87
PromisePrototypeThen,
98
PromiseResolve,
109
ReflectConstruct,
@@ -496,19 +495,17 @@ function transformStreamDefaultControllerError(controller, error) {
496495
transformStreamError(controller[kState].stream, error);
497496
}
498497

499-
function transformStreamDefaultControllerPerformTransform(controller, chunk) {
500-
const transformPromise =
501-
ensureIsPromise(
498+
async function transformStreamDefaultControllerPerformTransform(controller, chunk) {
499+
try {
500+
return await ensureIsPromise(
502501
controller[kState].transformAlgorithm,
503502
controller,
504503
chunk,
505504
controller);
506-
return PromisePrototypeCatch(
507-
transformPromise,
508-
(error) => {
509-
transformStreamError(controller[kState].stream, error);
510-
throw error;
511-
});
505+
} catch (error) {
506+
transformStreamError(controller[kState].stream, error);
507+
throw error;
508+
}
512509
}
513510

514511
function transformStreamDefaultControllerTerminate(controller) {

0 commit comments

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