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 40d57b7

Browse filesBrowse files
princejwesleysilverwind
authored andcommitted
repl: fix stack trace column number in strict mode
On strict mode, "'use strict'; void 0; " is added as prefix in order to prevent "use strict" as the result value for let/const statements. It causes wrong column number in stack trace. PR-URL: #5416 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
1 parent f0c0614 commit 40d57b7
Copy full SHA for 40d57b7

File tree

Expand file treeCollapse file tree

2 files changed

+25
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+25
-4
lines changed
Open diff view settings
Collapse file

‎lib/repl.js‎

Copy file name to clipboardExpand all lines: lib/repl.js
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ function REPLServer(prompt,
228228
(self.replMode === exports.REPL_MODE_STRICT || retry)) {
229229
// "void 0" keeps the repl from returning "use strict" as the
230230
// result value for let/const statements.
231-
code = `'use strict'; void 0; ${code}`;
231+
code = `'use strict'; void 0;\n${code}`;
232232
}
233233
var script = vm.createScript(code, {
234234
filename: file,
@@ -287,6 +287,10 @@ function REPLServer(prompt,
287287
debug('domain error');
288288
const top = replMap.get(self);
289289
internalUtil.decorateErrorStack(e);
290+
if (e.stack && self.replMode === exports.REPL_MODE_STRICT) {
291+
e.stack = e.stack.replace(/(\s+at\s+repl:)(\d+)/,
292+
(_, pre, line) => pre + (line - 1));
293+
}
290294
top.outputStream.write((e.stack || e) + '\n');
291295
top.lineParser.reset();
292296
top.bufferedCommand = '';
Collapse file

‎test/parallel/test-repl.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl.js
+20-3Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const prompt_npm = 'npm should be run outside of the ' +
1515
'node repl, in your normal shell.\n' +
1616
'(Press Control-D to exit.)\n';
1717
const expect_npm = prompt_npm + prompt_unix;
18-
var server_tcp, server_unix, client_tcp, client_unix, timer;
18+
var server_tcp, server_unix, client_tcp, client_unix, timer, replServer;
1919

2020

2121
// absolute path to test/fixtures/a.js
@@ -48,9 +48,17 @@ function clean_up() {
4848
clearTimeout(timer);
4949
}
5050

51+
function strict_mode_error_test() {
52+
send_expect([
53+
{ client: client_unix, send: 'ref = 1',
54+
expect: /^ReferenceError:\sref\sis\snot\sdefined\n\s+at\srepl:1:5/ },
55+
]);
56+
}
57+
5158
function error_test() {
5259
// The other stuff is done so reuse unix socket
5360
var read_buffer = '';
61+
var run_strict_test = true;
5462
client_unix.removeAllListeners('data');
5563

5664
client_unix.on('data', function(data) {
@@ -72,6 +80,10 @@ function error_test() {
7280
read_buffer = '';
7381
if (client_unix.list && client_unix.list.length > 0) {
7482
send_expect(client_unix.list);
83+
} else if (run_strict_test) {
84+
replServer.replMode = repl.REPL_MODE_STRICT;
85+
run_strict_test = false;
86+
strict_mode_error_test();
7587
} else {
7688
console.error('End of Error test, running TCP test.');
7789
tcp_test();
@@ -83,6 +95,10 @@ function error_test() {
8395
read_buffer = '';
8496
if (client_unix.list && client_unix.list.length > 0) {
8597
send_expect(client_unix.list);
98+
} else if (run_strict_test) {
99+
replServer.replMode = repl.REPL_MODE_STRICT;
100+
run_strict_test = false;
101+
strict_mode_error_test();
86102
} else {
87103
console.error('End of Error test, running TCP test.\n');
88104
tcp_test();
@@ -381,12 +397,13 @@ function unix_test() {
381397
socket.end();
382398
});
383399

384-
repl.start({
400+
replServer = repl.start({
385401
prompt: prompt_unix,
386402
input: socket,
387403
output: socket,
388404
useGlobal: true
389-
}).context.message = message;
405+
});
406+
replServer.context.message = message;
390407
});
391408

392409
server_unix.on('listening', function() {

0 commit comments

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