From 032fc42e64fdb5ab0b5182ea39a0487b40638c82 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Thu, 14 Jun 2012 16:59:02 -0700 Subject: [PATCH] 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. --- lib/readline.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/readline.js b/lib/readline.js index df0d92bbac6..8adc2c14587 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);