summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/readline.js5
-rw-r--r--test/parallel/test-readline-interface.js12
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/readline.js b/lib/readline.js
index 63a7aa816..a6845010d 100644
--- a/lib/readline.js
+++ b/lib/readline.js
@@ -26,7 +26,10 @@ exports.createInterface = function(input, output, completer, terminal) {
function Interface(input, output, completer, terminal) {
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;
diff --git a/test/parallel/test-readline-interface.js b/test/parallel/test-readline-interface.js
index ae8a4188a..69eb4bf51 100644
--- a/test/parallel/test-readline-interface.js
+++ b/test/parallel/test-readline-interface.js
@@ -216,6 +216,18 @@ function isWarned(emitter) {
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) {
// question
fi = new FakeInput();