Skip to content

Commit 8aef370

Browse files
committed
repl: give repl entries unique names.
This is a workaround for the REPL for a problem when multiple of the entries have the same source text Fixes: nodejs#1337 Refs: https://bugs.chromium.org/p/v8/issues/detail?id=10284
1 parent 66810a0 commit 8aef370

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

lib/repl.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ const {
128128
} = internalBinding('contextify');
129129

130130
const history = require('internal/repl/history');
131+
let nextREPLResourceNumber = 1;
132+
function getREPLResourceName() {
133+
return `REPL${nextREPLResourceNumber++}`;
134+
}
131135

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

769773
debug('eval %j', evalCmd);
770-
self.eval(evalCmd, self.context, 'repl', finish);
774+
self.eval(evalCmd, self.context, getREPLResourceName(), finish);
771775

772776
function finish(e, ret) {
773777
debug('finish', e, ret);
@@ -1248,7 +1252,7 @@ function complete(line, callback) {
12481252

12491253
const memberGroups = [];
12501254
const evalExpr = `try { ${expr} } catch {}`;
1251-
this.eval(evalExpr, this.context, 'repl', (e, obj) => {
1255+
this.eval(evalExpr, this.context, getREPLResourceName(), (e, obj) => {
12521256
try {
12531257
let p;
12541258
if ((typeof obj === 'object' && obj !== null) ||
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
require('../common');
3+
const assert = require('assert');
4+
const child_process = require('child_process');
5+
const child = child_process.spawn(process.execPath, [
6+
'--interactive',
7+
'--expose-gc'
8+
], {
9+
stdio: 'pipe'
10+
});
11+
child.stdin.write('\nimport("fs");\n_.then(gc);\n');
12+
// Wait for concurrent GC to finish
13+
setTimeout(() => {
14+
child.stdin.write('\nimport("fs");\n');
15+
child.stdin.write('\nprocess.exit(0);\n');
16+
}, 500);
17+
child.on('exit', (code, signal) => {
18+
assert.strictEqual(code, 0);
19+
assert.strictEqual(signal, null);
20+
});

0 commit comments

Comments
 (0)