Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 70768ce

Browse filesBrowse files
bmeckMylesBorins
authored andcommitted
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: #1337 Refs: https://bugs.chromium.org/p/v8/issues/detail?id=10284 PR-URL: #34372 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
1 parent c8a7789 commit 70768ce
Copy full SHA for 70768ce

File tree

Expand file treeCollapse file tree

4 files changed

+43
-17
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+43
-17
lines changed
Open diff view settings
Collapse file

‎lib/repl.js‎

Copy file name to clipboardExpand all lines: lib/repl.js
+10-4Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ const {
124124
} = internalBinding('contextify');
125125

126126
const history = require('internal/repl/history');
127+
let nextREPLResourceNumber = 1;
128+
// This prevents v8 code cache from getting confused and using a different
129+
// cache from a resource of the same name
130+
function getREPLResourceName() {
131+
return `REPL${nextREPLResourceNumber++}`;
132+
}
127133

128134
// Lazy-loaded.
129135
let processTopLevelAwait;
@@ -541,10 +547,10 @@ function REPLServer(prompt,
541547
if (e.name === 'SyntaxError') {
542548
// Remove stack trace.
543549
e.stack = e.stack
544-
.replace(/^repl:\d+\r?\n/, '')
550+
.replace(/^REPL\d+:\d+\r?\n/, '')
545551
.replace(/^\s+at\s.*\n?/gm, '');
546552
} else if (self.replMode === exports.REPL_MODE_STRICT) {
547-
e.stack = e.stack.replace(/(\s+at\s+repl:)(\d+)/,
553+
e.stack = e.stack.replace(/(\s+at\s+REPL\d+:)(\d+)/,
548554
(_, pre, line) => pre + (line - 1));
549555
}
550556
}
@@ -759,7 +765,7 @@ function REPLServer(prompt,
759765
const evalCmd = self[kBufferedCommandSymbol] + cmd + '\n';
760766

761767
debug('eval %j', evalCmd);
762-
self.eval(evalCmd, self.context, 'repl', finish);
768+
self.eval(evalCmd, self.context, getREPLResourceName(), finish);
763769

764770
function finish(e, ret) {
765771
debug('finish', e, ret);
@@ -1275,7 +1281,7 @@ function complete(line, callback) {
12751281
}
12761282

12771283
const evalExpr = `try { ${expr} } catch {}`;
1278-
this.eval(evalExpr, this.context, 'repl', (e, obj) => {
1284+
this.eval(evalExpr, this.context, getREPLResourceName(), (e, obj) => {
12791285
if (obj != null) {
12801286
if (typeof obj === 'object' || typeof obj === 'function') {
12811287
try {
Collapse file
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
const common = 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+
}, common.platformTimeout(50));
17+
child.on('exit', (code, signal) => {
18+
assert.strictEqual(code, 0);
19+
assert.strictEqual(signal, null);
20+
});
Collapse file

‎test/parallel/test-repl-pretty-custom-stack.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl-pretty-custom-stack.js
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const fixtures = require('../common/fixtures');
55
const assert = require('assert');
66
const repl = require('repl');
77

8-
const stackRegExp = /repl:[0-9]+:[0-9]+/g;
8+
const stackRegExp = /(REPL\d+):[0-9]+:[0-9]+/g;
99

1010
function run({ command, expected }) {
1111
let accum = '';
@@ -25,8 +25,8 @@ function run({ command, expected }) {
2525

2626
r.write(`${command}\n`);
2727
assert.strictEqual(
28-
accum.replace(stackRegExp, 'repl:*:*'),
29-
expected.replace(stackRegExp, 'repl:*:*')
28+
accum.replace(stackRegExp, '$1:*:*'),
29+
expected.replace(stackRegExp, '$1:*:*')
3030
);
3131
r.close();
3232
}
@@ -48,8 +48,8 @@ const tests = [
4848
{
4949
// test .load for a file that throws
5050
command: `.load ${fixtures.path('repl-pretty-stack.js')}`,
51-
expected: 'Uncaught Error: Whoops!--->\nrepl:*:*--->\nd (repl:*:*)' +
52-
'--->\nc (repl:*:*)--->\nb (repl:*:*)--->\na (repl:*:*)\n'
51+
expected: 'Uncaught Error: Whoops!--->\nREPL1:*:*--->\nd (REPL1:*:*)' +
52+
'--->\nc (REPL1:*:*)--->\nb (REPL1:*:*)--->\na (REPL1:*:*)\n'
5353
},
5454
{
5555
command: 'let x y;',
@@ -67,7 +67,7 @@ const tests = [
6767
// test anonymous IIFE
6868
{
6969
command: '(function() { throw new Error(\'Whoops!\'); })()',
70-
expected: 'Uncaught Error: Whoops!--->\nrepl:*:*\n'
70+
expected: 'Uncaught Error: Whoops!--->\nREPL5:*:*\n'
7171
}
7272
];
7373

Collapse file

‎test/parallel/test-repl-pretty-stack.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl-pretty-stack.js
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const fixtures = require('../common/fixtures');
55
const assert = require('assert');
66
const repl = require('repl');
77

8-
const stackRegExp = /(at .*repl:)[0-9]+:[0-9]+/g;
8+
const stackRegExp = /(at .*REPL\d+:)[0-9]+:[0-9]+/g;
99

1010
function run({ command, expected, ...extraREPLOptions }, i) {
1111
let accum = '';
@@ -37,9 +37,9 @@ const tests = [
3737
{
3838
// Test .load for a file that throws.
3939
command: `.load ${fixtures.path('repl-pretty-stack.js')}`,
40-
expected: 'Uncaught Error: Whoops!\n at repl:*:*\n' +
41-
' at d (repl:*:*)\n at c (repl:*:*)\n' +
42-
' at b (repl:*:*)\n at a (repl:*:*)\n'
40+
expected: 'Uncaught Error: Whoops!\n at REPL1:*:*\n' +
41+
' at d (REPL1:*:*)\n at c (REPL1:*:*)\n' +
42+
' at b (REPL1:*:*)\n at a (REPL1:*:*)\n'
4343
},
4444
{
4545
command: 'let x y;',
@@ -53,12 +53,12 @@ const tests = [
5353
{
5454
command: '(() => { const err = Error(\'Whoops!\'); ' +
5555
'err.foo = \'bar\'; throw err; })()',
56-
expected: "Uncaught Error: Whoops!\n at repl:*:* {\n foo: 'bar'\n}\n",
56+
expected: "Uncaught Error: Whoops!\n at REPL4:*:* {\n foo: 'bar'\n}\n",
5757
},
5858
{
5959
command: '(() => { const err = Error(\'Whoops!\'); ' +
6060
'err.foo = \'bar\'; throw err; })()',
61-
expected: 'Uncaught Error: Whoops!\n at repl:*:* {\n foo: ' +
61+
expected: 'Uncaught Error: Whoops!\n at REPL5:*:* {\n foo: ' +
6262
"\u001b[32m'bar'\u001b[39m\n}\n",
6363
useColors: true
6464
},
@@ -69,7 +69,7 @@ const tests = [
6969
// Test anonymous IIFE.
7070
{
7171
command: '(function() { throw new Error(\'Whoops!\'); })()',
72-
expected: 'Uncaught Error: Whoops!\n at repl:*:*\n'
72+
expected: 'Uncaught Error: Whoops!\n at REPL7:*:*\n'
7373
}
7474
];
7575

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.