mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
repl: use SafePromiseAll and SafePromiseRace
PR-URL: https://github.com/nodejs/node/pull/43758 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
@@ -23,7 +23,6 @@ const {
|
||||
ObjectKeys,
|
||||
ObjectValues,
|
||||
Promise,
|
||||
PromiseAll,
|
||||
PromisePrototypeCatch,
|
||||
PromisePrototypeThen,
|
||||
PromiseResolve,
|
||||
@@ -31,8 +30,8 @@ const {
|
||||
ReflectOwnKeys,
|
||||
RegExpPrototypeExec,
|
||||
RegExpPrototypeSymbolReplace,
|
||||
SafeArrayIterator,
|
||||
SafeMap,
|
||||
SafePromiseAll,
|
||||
String,
|
||||
StringFromCharCode,
|
||||
StringPrototypeEndsWith,
|
||||
@@ -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) {
|
||||
@@ -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]);
|
||||
@@ -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.`);
|
||||
});
|
||||
@@ -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)}` :
|
||||
|
||||
@@ -74,12 +74,12 @@ const {
|
||||
ObjectKeys,
|
||||
ObjectSetPrototypeOf,
|
||||
Promise,
|
||||
PromiseRace,
|
||||
ReflectApply,
|
||||
RegExp,
|
||||
RegExpPrototypeExec,
|
||||
RegExpPrototypeSymbolReplace,
|
||||
RegExpPrototypeSymbolSplit,
|
||||
SafePromiseRace,
|
||||
SafeSet,
|
||||
SafeWeakSet,
|
||||
StringPrototypeCharAt,
|
||||
@@ -611,7 +611,7 @@ function REPLServer(prompt,
|
||||
};
|
||||
prioritizedSigintQueue.add(sigintListener);
|
||||
});
|
||||
promise = PromiseRace([promise, interrupt]);
|
||||
promise = SafePromiseRace([promise, interrupt]);
|
||||
}
|
||||
|
||||
(async () => {
|
||||
|
||||
Reference in New Issue
Block a user