mirror of https://github.com/nodejs/node.git
readline: don't cache the "keypress" listeners
it's not safe to since `removeAllListeners()` will detach the returned Array from the stream instance if that's ever called by the user.pull/24503/head
parent
c9a1b5d162
commit
032fc42e64
|
@ -786,10 +786,8 @@ function emitKeypressEvents(stream) {
|
||||||
if (stream._emitKeypress) return;
|
if (stream._emitKeypress) return;
|
||||||
stream._emitKeypress = true;
|
stream._emitKeypress = true;
|
||||||
|
|
||||||
var keypressListeners = stream.listeners('keypress');
|
|
||||||
|
|
||||||
function onData(b) {
|
function onData(b) {
|
||||||
if (keypressListeners.length) {
|
if (stream.listeners('keypress').length > 0) {
|
||||||
emitKey(stream, b);
|
emitKey(stream, b);
|
||||||
} else {
|
} else {
|
||||||
// Nobody's watching anyway
|
// Nobody's watching anyway
|
||||||
|
@ -805,7 +803,7 @@ function emitKeypressEvents(stream) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keypressListeners.length) {
|
if (stream.listeners('keypress').length > 0) {
|
||||||
stream.on('data', onData);
|
stream.on('data', onData);
|
||||||
} else {
|
} else {
|
||||||
stream.on('newListener', onNewListener);
|
stream.on('newListener', onNewListener);
|
||||||
|
|
Loading…
Reference in New Issue