-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
repl: Mitigate vm #548 function redefinition issue
```js node 🙈 ₹ git:(upstream ⚡ repl-tmp-548) ./node > function name() { return "node"; }; undefined > name() 'node' > function name() { return "nodejs"; }; undefined > name() 'nodejs' > ``` PR-URL: #7794 Reviewed-By: Evan Lucas <evanlucas@me.com>
- Loading branch information
1 parent
d3f0a6a
commit 72fc4eb
Showing
3 changed files
with
64 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
test/known_issues/test-repl-function-redefinition-edge-case.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Reference: https://github.com/nodejs/node/pull/7624 | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const repl = require('repl'); | ||
const stream = require('stream'); | ||
|
||
common.globalCheck = false; | ||
|
||
const r = initRepl(); | ||
|
||
r.input.emit('data', 'function a() { return 42; } (1)\n'); | ||
r.input.emit('data', 'a\n'); | ||
r.input.emit('data', '.exit'); | ||
|
||
const expected = '1\n[Function a]\n'; | ||
const got = r.output.accumulator.join(''); | ||
assert.strictEqual(got, expected); | ||
|
||
function initRepl() { | ||
const input = new stream(); | ||
input.write = input.pause = input.resume = () => {}; | ||
input.readable = true; | ||
|
||
const output = new stream(); | ||
output.writable = true; | ||
output.accumulator = []; | ||
|
||
output.write = (data) => output.accumulator.push(data); | ||
|
||
return repl.start({ | ||
input, | ||
output, | ||
useColors: false, | ||
terminal: false, | ||
prompt: '' | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters