0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/known_issues/test-repl-function-redefinition-edge-case.js
Prince J Wesley bb9eabec40 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'
>
```

Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Lance Ball <lball@redhat.com>
2016-07-15 13:44:34 -04:00

39 lines
882 B
JavaScript

// 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: ''
});
}