diff options
author | Nathan Rajlich <nathan@tootallnate.net> | 2012-06-14 16:59:02 -0700 |
---|---|---|
committer | isaacs <i@izs.me> | 2012-06-14 17:26:50 -0700 |
commit | 032fc42e64fdb5ab0b5182ea39a0487b40638c82 (patch) | |
tree | 2443b1af197de085187af4020e0c1d705efcda11 | |
parent | c9a1b5d162d40235ac7ec5479059c66a33f5c1a1 (diff) | |
download | node-032fc42e64fdb5ab0b5182ea39a0487b40638c82.tar.gz |
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.
-rw-r--r-- | lib/readline.js | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/lib/readline.js b/lib/readline.js index df0d92bba..8adc2c145 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -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 @@ -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); |