readline: fix calling constructor without new
Previously, we detected options object based on amount of arguments supplied. But if we're calling readline without new operator, constructor gets re-called and will always have 4 arguments. PR-URL: https://github.com/iojs/io.js/pull/1385 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
parent
8bc8bd4bc2
commit
f0bf6bb024
@ -26,7 +26,10 @@ exports.createInterface = function(input, output, completer, terminal) {
|
|||||||
|
|
||||||
function Interface(input, output, completer, terminal) {
|
function Interface(input, output, completer, terminal) {
|
||||||
if (!(this instanceof Interface)) {
|
if (!(this instanceof Interface)) {
|
||||||
return new Interface(input, output, completer, terminal);
|
// call the constructor preserving original number of arguments
|
||||||
|
const self = Object.create(Interface.prototype);
|
||||||
|
Interface.apply(self, arguments);
|
||||||
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._sawReturn = false;
|
this._sawReturn = false;
|
||||||
|
@ -216,6 +216,18 @@ function isWarned(emitter) {
|
|||||||
fi.emit('data', ''); // removes listener
|
fi.emit('data', ''); // removes listener
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// calling readline without `new`
|
||||||
|
fi = new FakeInput();
|
||||||
|
rli = readline.Interface({ input: fi, output: fi, terminal: terminal });
|
||||||
|
called = false;
|
||||||
|
rli.on('line', function(line) {
|
||||||
|
called = true;
|
||||||
|
assert.equal(line, 'asdf');
|
||||||
|
});
|
||||||
|
fi.emit('data', 'asdf\n');
|
||||||
|
assert.ok(called);
|
||||||
|
rli.close();
|
||||||
|
|
||||||
if (terminal) {
|
if (terminal) {
|
||||||
// question
|
// question
|
||||||
fi = new FakeInput();
|
fi = new FakeInput();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user