Skip to content

Commit

Permalink
repl: use SafePromiseAll and SafePromiseRace
Browse files Browse the repository at this point in the history
PR-URL: #43758
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
aduh95 authored and danielleadams committed Jul 26, 2022
1 parent 50b3750 commit 1deb6b7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
40 changes: 17 additions & 23 deletions lib/internal/debugger/inspect_repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ const {
ObjectKeys,
ObjectValues,
Promise,
PromiseAll,
PromisePrototypeCatch,
PromisePrototypeThen,
PromiseResolve,
ReflectGetOwnPropertyDescriptor,
ReflectOwnKeys,
RegExpPrototypeExec,
RegExpPrototypeSymbolReplace,
SafeArrayIterator,
SafeMap,
SafePromiseAll,
String,
StringFromCharCode,
StringPrototypeEndsWith,
Expand Down Expand Up @@ -519,22 +518,19 @@ function createRepl(inspector) {
}

loadScopes() {
return PromiseAll(
new SafeArrayIterator(ArrayPrototypeMap(
ArrayPrototypeFilter(
this.scopeChain,
(scope) => scope.type !== 'global'
),
async (scope) => {
const { objectId } = scope.object;
const { result } = await Runtime.getProperties({
objectId,
generatePreview: true,
});
return new ScopeSnapshot(scope, result);
})
)
);
return SafePromiseAll(
ArrayPrototypeFilter(
this.scopeChain,
(scope) => scope.type !== 'global'
),
async (scope) => {
const { objectId } = scope.object;
const { result } = await Runtime.getProperties({
objectId,
generatePreview: true,
});
return new ScopeSnapshot(scope, result);
});
}

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

const values = await PromiseAll(new SafeArrayIterator(
ArrayPrototypeMap(watchedExpressions, inspectValue)));
const values = await SafePromiseAll(watchedExpressions, inspectValue);
const lines = ArrayPrototypeMap(watchedExpressions, (expr, idx) => {
const prefix = `${leftPad(idx, ' ', lastIndex)}: ${expr} =`;
const value = inspect(values[idx]);
Expand Down Expand Up @@ -866,7 +861,7 @@ function createRepl(inspector) {
location.lineNumber + 1));
if (!newBreakpoints.length) return PromiseResolve();
return PromisePrototypeThen(
PromiseAll(new SafeArrayIterator(newBreakpoints)),
SafePromiseAll(newBreakpoints),
(results) => {
print(`${results.length} breakpoints restored.`);
});
Expand Down Expand Up @@ -902,8 +897,7 @@ function createRepl(inspector) {

inspector.suspendReplWhile(() =>
PromisePrototypeThen(
PromiseAll(new SafeArrayIterator(
[formatWatchers(true), selectedFrame.list(2)])),
SafePromiseAll([formatWatchers(true), selectedFrame.list(2)]),
({ 0: watcherList, 1: context }) => {
const breakContext = watcherList ?
`${watcherList}\n${inspect(context)}` :
Expand Down
4 changes: 2 additions & 2 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ const {
ObjectKeys,
ObjectSetPrototypeOf,
Promise,
PromiseRace,
ReflectApply,
RegExp,
RegExpPrototypeExec,
RegExpPrototypeSymbolReplace,
RegExpPrototypeSymbolSplit,
SafePromiseRace,
SafeSet,
SafeWeakSet,
StringPrototypeCharAt,
Expand Down Expand Up @@ -611,7 +611,7 @@ function REPLServer(prompt,
};
prioritizedSigintQueue.add(sigintListener);
});
promise = PromiseRace([promise, interrupt]);
promise = SafePromiseRace([promise, interrupt]);
}

(async () => {
Expand Down

0 comments on commit 1deb6b7

Please sign in to comment.