Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions lib/internal/repl/eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ function createReplEval(repl) {
silent: false,
returnByValue: false,
generatePreview: false,
// Await in a second inspector command after retaining the promise's
// objectId. See ReplInspectorChannel.evaluate().
awaitPromise: false,
replMode: true,
throwOnSideEffect: false,
Expand Down
17 changes: 2 additions & 15 deletions lib/internal/repl/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,21 +172,8 @@ class ReplInspectorChannel {
}

// Performs a `Runtime.evaluate`.
async evaluate(params, breakOnSigint) {
const response = await this.postInterruptible(
'Runtime.evaluate', params, breakOnSigint);
if (response.exceptionDetails || response.result?.subtype !== 'promise') {
return response;
}

// Hold the promise open until it resolves or rejects,
// so we can return the final value.
return this.postInterruptible('Runtime.awaitPromise', {
__proto__: null,
promiseObjectId: response.result.objectId,
returnByValue: params.returnByValue,
generatePreview: params.generatePreview,
}, breakOnSigint);
evaluate(params, breakOnSigint) {
return this.postInterruptible('Runtime.evaluate', params, breakOnSigint);
}

// Turns a remote object returned by the inspector into the real, live value
Expand Down
7 changes: 6 additions & 1 deletion lib/internal/repl/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@ function isRecoverableError(e, code) {
// Try to parse the code with acorn. If the parse fails, ignore the acorn
// error and return the recoverable status.
try {
RecoverableParser.parse(code, { ecmaVersion: 'latest' });
RecoverableParser.parse(code, {
ecmaVersion: 'latest',
// Top-level await is supported, so `await` must be parsed as a keyword
// for incomplete input such as `await new Promise((resolve) => {`.
allowAwaitOutsideFunction: true,
});

// Odd case: the underlying JS engine (V8, Chakra) rejected this input
// but Acorn detected no issue. Presume that additional text won't
Expand Down
35 changes: 35 additions & 0 deletions test/parallel/test-repl-promise-completion-value.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const { startNewREPLServer } = require('../common/repl');

const testCases = [
['await 2', '2'],
['Promise.resolve(2)', 'Promise { 2 }'],
['await 1; Promise.resolve(2);', 'Promise { 2 }'],
['new Promise(() => {})', 'Promise { <pending> }'],
['await Promise.resolve(123), Promise.resolve(456)', 'Promise { 456 }'],
['await Promise.resolve(123), await Promise.resolve(456)', '456'],
['await (Promise.resolve(123), Promise.resolve(456))', '456'],
['(async () => 7)()', 'Promise { 7 }'],
['await (async () => 7)()', '7'],
['const p = Promise.resolve(8)', 'undefined'],
['p', 'Promise { 8 }'],
['await p', '8'],
];

(async () => {
const { output, replServer, run } = startNewREPLServer({
terminal: false,
useColors: false,
});

for (const [input, expected] of testCases) {
output.accumulator = '';
await run(`${input}\n`);
assert.strictEqual(output.accumulator, `${expected}\n`, input);
}

replServer.close();
})().then(common.mustCall());
2 changes: 1 addition & 1 deletion test/parallel/test-repl-promise-gc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const { output, replServer, run } = startNewREPLServer({

// The promise is not retained by user code. Force a collection while the REPL
// is awaiting it to verify that the inspector keeps it alive until settlement.
await run(`new Promise((resolve) => setImmediate(() => {
await run(`await new Promise((resolve) => setImmediate(() => {
globalThis.gc();
resolve(42);
}))\n`);
Expand Down
Loading