Skip to content

Commit 0bd4a04

Browse files
aduh95targos
authored andcommitted
repl: use SafePromiseAll and SafePromiseRace
PR-URL: #43758 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent f7b8340 commit 0bd4a04

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

lib/internal/debugger/inspect_repl.js

+17-23
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,15 @@ const {
2323
ObjectKeys,
2424
ObjectValues,
2525
Promise,
26-
PromiseAll,
2726
PromisePrototypeCatch,
2827
PromisePrototypeThen,
2928
PromiseResolve,
3029
ReflectGetOwnPropertyDescriptor,
3130
ReflectOwnKeys,
3231
RegExpPrototypeSymbolMatch,
3332
RegExpPrototypeSymbolReplace,
34-
SafeArrayIterator,
3533
SafeMap,
34+
SafePromiseAll,
3635
String,
3736
StringFromCharCode,
3837
StringPrototypeEndsWith,
@@ -519,22 +518,19 @@ function createRepl(inspector) {
519518
}
520519

521520
loadScopes() {
522-
return PromiseAll(
523-
new SafeArrayIterator(ArrayPrototypeMap(
524-
ArrayPrototypeFilter(
525-
this.scopeChain,
526-
(scope) => scope.type !== 'global'
527-
),
528-
async (scope) => {
529-
const { objectId } = scope.object;
530-
const { result } = await Runtime.getProperties({
531-
objectId,
532-
generatePreview: true,
533-
});
534-
return new ScopeSnapshot(scope, result);
535-
})
536-
)
537-
);
521+
return SafePromiseAll(
522+
ArrayPrototypeFilter(
523+
this.scopeChain,
524+
(scope) => scope.type !== 'global'
525+
),
526+
async (scope) => {
527+
const { objectId } = scope.object;
528+
const { result } = await Runtime.getProperties({
529+
objectId,
530+
generatePreview: true,
531+
});
532+
return new ScopeSnapshot(scope, result);
533+
});
538534
}
539535

540536
list(delta = 5) {
@@ -661,8 +657,7 @@ function createRepl(inspector) {
661657
(error) => `<${error.message}>`);
662658
const lastIndex = watchedExpressions.length - 1;
663659

664-
const values = await PromiseAll(new SafeArrayIterator(
665-
ArrayPrototypeMap(watchedExpressions, inspectValue)));
660+
const values = await SafePromiseAll(watchedExpressions, inspectValue);
666661
const lines = ArrayPrototypeMap(watchedExpressions, (expr, idx) => {
667662
const prefix = `${leftPad(idx, ' ', lastIndex)}: ${expr} =`;
668663
const value = inspect(values[idx]);
@@ -866,7 +861,7 @@ function createRepl(inspector) {
866861
location.lineNumber + 1));
867862
if (!newBreakpoints.length) return PromiseResolve();
868863
return PromisePrototypeThen(
869-
PromiseAll(new SafeArrayIterator(newBreakpoints)),
864+
SafePromiseAll(newBreakpoints),
870865
(results) => {
871866
print(`${results.length} breakpoints restored.`);
872867
});
@@ -902,8 +897,7 @@ function createRepl(inspector) {
902897

903898
inspector.suspendReplWhile(() =>
904899
PromisePrototypeThen(
905-
PromiseAll(new SafeArrayIterator(
906-
[formatWatchers(true), selectedFrame.list(2)])),
900+
SafePromiseAll([formatWatchers(true), selectedFrame.list(2)]),
907901
({ 0: watcherList, 1: context }) => {
908902
const breakContext = watcherList ?
909903
`${watcherList}\n${inspect(context)}` :

lib/repl.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ const {
7474
ObjectKeys,
7575
ObjectSetPrototypeOf,
7676
Promise,
77-
PromiseRace,
7877
ReflectApply,
7978
RegExp,
8079
RegExpPrototypeExec,
8180
RegExpPrototypeSymbolReplace,
8281
RegExpPrototypeTest,
82+
SafePromiseRace,
8383
SafeSet,
8484
SafeWeakSet,
8585
StringPrototypeCharAt,
@@ -613,7 +613,7 @@ function REPLServer(prompt,
613613
};
614614
prioritizedSigintQueue.add(sigintListener);
615615
});
616-
promise = PromiseRace([promise, interrupt]);
616+
promise = SafePromiseRace([promise, interrupt]);
617617
}
618618

619619
(async () => {

0 commit comments

Comments
 (0)