Skip to content

Commit

Permalink
repl: give repl entries unique names.
Browse files Browse the repository at this point in the history
This is a workaround for the REPL for a problem when multiple of the
entries have the same source text

Fixes: #1337
Refs: https://bugs.chromium.org/p/v8/issues/detail?id=10284
  • Loading branch information
bmeck committed Jul 14, 2020
1 parent 66810a0 commit 8aef370
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/repl.js
Expand Up @@ -128,6 +128,10 @@ const {
} = internalBinding('contextify');

const history = require('internal/repl/history');
let nextREPLResourceNumber = 1;
function getREPLResourceName() {
return `REPL${nextREPLResourceNumber++}`;
}

// Lazy-loaded.
let processTopLevelAwait;
Expand Down Expand Up @@ -767,7 +771,7 @@ function REPLServer(prompt,
const evalCmd = self[kBufferedCommandSymbol] + cmd + '\n';

debug('eval %j', evalCmd);
self.eval(evalCmd, self.context, 'repl', finish);
self.eval(evalCmd, self.context, getREPLResourceName(), finish);

function finish(e, ret) {
debug('finish', e, ret);
Expand Down Expand Up @@ -1248,7 +1252,7 @@ function complete(line, callback) {

const memberGroups = [];
const evalExpr = `try { ${expr} } catch {}`;
this.eval(evalExpr, this.context, 'repl', (e, obj) => {
this.eval(evalExpr, this.context, getREPLResourceName(), (e, obj) => {
try {
let p;
if ((typeof obj === 'object' && obj !== null) ||
Expand Down
20 changes: 20 additions & 0 deletions test/parallel/test-repl-dynamic-import.js
@@ -0,0 +1,20 @@
'use strict';
require('../common');
const assert = require('assert');
const child_process = require('child_process');
const child = child_process.spawn(process.execPath, [
'--interactive',
'--expose-gc'
], {
stdio: 'pipe'
});
child.stdin.write('\nimport("fs");\n_.then(gc);\n');
// Wait for concurrent GC to finish
setTimeout(() => {
child.stdin.write('\nimport("fs");\n');
child.stdin.write('\nprocess.exit(0);\n');
}, 500);
child.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});

0 comments on commit 8aef370

Please sign in to comment.