Skip to content
Closed
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
repl: wrong repl 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.
  • Loading branch information
princejwesley committed Feb 25, 2016
commit 00ebc4e27932ab3bee10e0a04fe97030a555ffb1
6 changes: 5 additions & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ function REPLServer(prompt,
(self.replMode === exports.REPL_MODE_STRICT || retry)) {
// "void 0" keeps the repl from returning "use strict" as the
// result value for let/const statements.
code = `'use strict'; void 0; ${code}`;
code = `'use strict'; void 0;\n${code}`;
}
var script = vm.createScript(code, {
filename: file,
Expand Down Expand Up @@ -289,6 +289,10 @@ function REPLServer(prompt,
debug('domain error');
const top = replMap.get(self);
internalUtil.decorateErrorStack(e);
if (e.stack && self.replMode === exports.REPL_MODE_STRICT) {
e.stack = e.stack.replace(/(\s+at\s+repl:)(\d+)/,
(_, pre, line) => pre + (line - 1));
}
top.outputStream.write((e.stack || e) + '\n');
top.lineParser.reset();
top.bufferedCommand = '';
Expand Down
23 changes: 20 additions & 3 deletions test/parallel/test-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const prompt_npm = 'npm should be run outside of the ' +
'node repl, in your normal shell.\n' +
'(Press Control-D to exit.)\n';
const expect_npm = prompt_npm + prompt_unix;
var server_tcp, server_unix, client_tcp, client_unix, timer;
var server_tcp, server_unix, client_tcp, client_unix, timer, replServer;


// absolute path to test/fixtures/a.js
Expand Down Expand Up @@ -48,9 +48,17 @@ function clean_up() {
clearTimeout(timer);
}

function strict_mode_error_test() {
send_expect([
{ client: client_unix, send: 'ref = 1',
expect: /^ReferenceError:\sref\sis\snot\sdefined\n\s+at\srepl:1:5/ },
]);
}

function error_test() {
// The other stuff is done so reuse unix socket
var read_buffer = '';
var run_strict_test = true;
client_unix.removeAllListeners('data');

client_unix.on('data', function(data) {
Expand All @@ -72,6 +80,10 @@ function error_test() {
read_buffer = '';
if (client_unix.list && client_unix.list.length > 0) {
send_expect(client_unix.list);
} else if (run_strict_test) {
replServer.replMode = repl.REPL_MODE_STRICT;
run_strict_test = false;
strict_mode_error_test();
} else {
console.error('End of Error test, running TCP test.');
tcp_test();
Expand All @@ -83,6 +95,10 @@ function error_test() {
read_buffer = '';
if (client_unix.list && client_unix.list.length > 0) {
send_expect(client_unix.list);
} else if (run_strict_test) {
replServer.replMode = repl.REPL_MODE_STRICT;
run_strict_test = false;
strict_mode_error_test();
} else {
console.error('End of Error test, running TCP test.\n');
tcp_test();
Expand Down Expand Up @@ -381,12 +397,13 @@ function unix_test() {
socket.end();
});

repl.start({
replServer = repl.start({
prompt: prompt_unix,
input: socket,
output: socket,
useGlobal: true
}).context.message = message;
});
replServer.context.message = message;
});

server_unix.on('listening', function() {
Expand Down