summaryrefslogtreecommitdiff
path: root/lib/readline.js
diff options
context:
space:
mode:
authorAlex Kocharin <alex@kocharin.ru>2015-07-05 19:16:47 +0300
committerAlex Kocharin <alex@kocharin.ru>2015-07-11 21:12:25 +0300
commitbd0160320199451c93a9f318a9bd7c363f97bf0c (patch)
treec19b9271f98a05e510662ab0553d1f0cc5ef27ec /lib/readline.js
parentcf14a2427c9e56a915c64e658bbdfb5e8ba07d94 (diff)
downloadandroid-node-v8-bd0160320199451c93a9f318a9bd7c363f97bf0c.tar.gz
android-node-v8-bd0160320199451c93a9f318a9bd7c363f97bf0c.tar.bz2
android-node-v8-bd0160320199451c93a9f318a9bd7c363f97bf0c.zip
readline: fix freeze if `keypress` event throws
`emitKeys` is a generator which emits `keypress` events in an infinite loop. But if `keypress` event handler throws, the error stops the loop, leaving generator in a broken state. So this patch restarts the generator when an error occures. PR-URL: https://github.com/nodejs/io.js/pull/2107 Reviewed-By: Christopher Monsanto <chris@monsan.to> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'lib/readline.js')
-rw-r--r--lib/readline.js10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/readline.js b/lib/readline.js
index d186eef94a..741f58b934 100644
--- a/lib/readline.js
+++ b/lib/readline.js
@@ -910,7 +910,15 @@ function emitKeypressEvents(stream) {
var r = stream[KEYPRESS_DECODER].write(b);
if (r) {
for (var i = 0; i < r.length; i++) {
- stream[ESCAPE_DECODER].next(r[i]);
+ try {
+ stream[ESCAPE_DECODER].next(r[i]);
+ } catch (err) {
+ // if the generator throws (it could happen in the `keypress`
+ // event), we need to restart it.
+ stream[ESCAPE_DECODER] = emitKeys(stream);
+ stream[ESCAPE_DECODER].next();
+ throw err;
+ }
}
}
} else {