self.close();
}
+ function ontermend() {
+ if (util.isString(self.line) && self.line.length > 0) {
+ self.emit('line', self.line);
+ }
+ self.close();
+ }
+
function onkeypress(s, key) {
self._ttyWrite(s, key);
}
// input usually refers to stdin
input.on('keypress', onkeypress);
- input.on('end', function inputEnd() {
- if (util.isString(self.line) && self.line.length > 0)
- self.emit('line', self.line);
- self.close();
- });
+ input.on('end', ontermend);
// Current line
this.line = '';
output.on('resize', onresize);
self.once('close', function() {
input.removeListener('keypress', onkeypress);
+ input.removeListener('end', ontermend);
output.removeListener('resize', onresize);
});
}
FakeInput.prototype.write = function() {};
FakeInput.prototype.end = function() {};
+function isWarned(emitter) {
+ for (var name in emitter) {
+ var listeners = emitter[name];
+ if (listeners.warned) return true;
+ }
+ return false;
+}
+
[ true, false ].forEach(function(terminal) {
var fi;
var rli;
assert.equal(readline.getStringWidth('> '), 2);
assert.deepEqual(fi.listeners(terminal ? 'keypress' : 'data'), []);
+
+ // check EventEmitter memory leak
+ for (var i=0; i<12; i++) {
+ var rl = readline.createInterface({
+ input: process.stdin,
+ output: process.stdout
+ });
+ rl.close();
+ assert.equal(isWarned(process.stdin._events), false);
+ assert.equal(isWarned(process.stdout._events), false);
+ }
+
});
+