Skip to content

Commit 515747e

Browse files
committed
Revert "repl: Mitigate vm nodejs#548 function redefinition issue"
This reverts commit bb9eabe. The issue is fixed upstream in V8. Thus we do not need this workaround in REPL. Keeping the edgecase test.
1 parent 94b3d34 commit 515747e

File tree

2 files changed

+14
-22
lines changed

2 files changed

+14
-22
lines changed

lib/repl.js

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,19 @@ function REPLServer(prompt,
498498
}
499499

500500
var evalCmd = self.bufferedCommand + cmd;
501-
evalCmd = preprocess(evalCmd);
501+
if (/^\s*\{/.test(evalCmd) && /\}\s*$/.test(evalCmd)) {
502+
// It's confusing for `{ a : 1 }` to be interpreted as a block
503+
// statement rather than an object literal. So, we first try
504+
// to wrap it in parentheses, so that it will be interpreted as
505+
// an expression.
506+
evalCmd = '(' + evalCmd + ')\n';
507+
self.wrappedCmd = true;
508+
} else {
509+
// otherwise we just append a \n so that it will be either
510+
// terminated, or continued onto the next expression if it's an
511+
// unexpected end of input.
512+
evalCmd = evalCmd + '\n';
513+
}
502514

503515
debug('eval %j', evalCmd);
504516
self.eval(evalCmd, self.context, 'repl', finish);
@@ -555,26 +567,6 @@ function REPLServer(prompt,
555567
// Display prompt again
556568
self.displayPrompt();
557569
}
558-
559-
function preprocess(code) {
560-
let cmd = code;
561-
if (/^\s*\{/.test(cmd) && /\}\s*$/.test(cmd)) {
562-
// It's confusing for `{ a : 1 }` to be interpreted as a block
563-
// statement rather than an object literal. So, we first try
564-
// to wrap it in parentheses, so that it will be interpreted as
565-
// an expression.
566-
cmd = `(${cmd})`;
567-
self.wrappedCmd = true;
568-
} else {
569-
// Mitigate https://github.com/nodejs/node/issues/548
570-
cmd = cmd.replace(/^\s*function\s+([^(]+)/,
571-
(_, name) => `var ${name} = function ${name}`);
572-
}
573-
// Append a \n so that it will be either
574-
// terminated, or continued onto the next expression if it's an
575-
// unexpected end of input.
576-
return `${cmd}\n`;
577-
}
578570
});
579571

580572
self.on('SIGCONT', function() {

test/known_issues/test-repl-function-redefinition-edge-case.js renamed to test/parallel/test-repl-function-redefinition-edge-case.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ r.input.emit('data', 'function a() { return 42; } (1)\n');
1313
r.input.emit('data', 'a\n');
1414
r.input.emit('data', '.exit');
1515

16-
const expected = '1\n[Function a]\n';
16+
const expected = '1\n[Function: a]\n';
1717
const got = r.output.accumulator.join('');
1818
assert.strictEqual(got, expected);
1919

0 commit comments

Comments
 (0)