Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
readline: don't cache the "keypress" listeners
Browse files Browse the repository at this point in the history
it's not safe to since `removeAllListeners()` will detach the returned
Array from the stream instance if that's ever called by the user.
  • Loading branch information
TooTallNate authored and isaacs committed Jun 15, 2012
1 parent c9a1b5d commit 032fc42
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/readline.js
Expand Up @@ -786,10 +786,8 @@ function emitKeypressEvents(stream) {
if (stream._emitKeypress) return;
stream._emitKeypress = true;

var keypressListeners = stream.listeners('keypress');

function onData(b) {
if (keypressListeners.length) {
if (stream.listeners('keypress').length > 0) {
emitKey(stream, b);
} else {
// Nobody's watching anyway
Expand All @@ -805,7 +803,7 @@ function emitKeypressEvents(stream) {
}
}

if (keypressListeners.length) {
if (stream.listeners('keypress').length > 0) {
stream.on('data', onData);
} else {
stream.on('newListener', onNewListener);
Expand Down

0 comments on commit 032fc42

Please sign in to comment.