summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian White <mscdex@mscdex.net>2010-12-03 07:45:00 -0500
committerRyan Dahl <ry@tinyclouds.org>2010-12-03 09:57:36 -0800
commite41e078159e3eb5907e53f54234ee3e1aed21bb1 (patch)
tree3e1c62e86a9a1d14d5a2e2370d88512fcd87a2af
parente4bca198431acb420a44ea3a5dc1eaa5517159d4 (diff)
downloadnode-new-e41e078159e3eb5907e53f54234ee3e1aed21bb1.tar.gz
Make sure REPL doesn't get borked when invalid REPL keywords are entered
-rw-r--r--lib/repl.js68
1 files changed, 38 insertions, 30 deletions
diff --git a/lib/repl.js b/lib/repl.js
index fb08593b29..d5b55f2027 100644
--- a/lib/repl.js
+++ b/lib/repl.js
@@ -84,6 +84,7 @@ function REPLServer(prompt, stream) {
});
rli.addListener('line', function(cmd) {
+ var skipCatchall = false;
cmd = trimWhitespace(cmd);
// Check to see if a REPL keyword was used. If it returns true,
@@ -92,43 +93,50 @@ function REPLServer(prompt, stream) {
var matches = cmd.match(/^(\.[^\s]+)\s*(.*)$/);
var keyword = matches && matches[1];
var rest = matches && matches[2];
- if (self.parseREPLKeyword(keyword, rest) === true) return;
+ if (self.parseREPLKeyword(keyword, rest) === true) {
+ return;
+ } else {
+ self.stream.write('Invalid REPL keyword\n');
+ skipCatchall = true;
+ }
}
- // The catchall for errors
- try {
- self.buffered_cmd += cmd;
- // This try is for determining if the command is complete, or should
- // continue onto the next line.
+ if (!skipCatchall) {
+ // The catchall for errors
try {
- // Use evalcx to supply the global context
- var ret = evalcx(self.buffered_cmd, context, 'repl');
- if (ret !== undefined) {
- context._ = ret;
- self.stream.write(exports.writer(ret) + '\n');
- }
+ self.buffered_cmd += cmd;
+ // This try is for determining if the command is complete, or should
+ // continue onto the next line.
+ try {
+ // Use evalcx to supply the global context
+ var ret = evalcx(self.buffered_cmd, context, 'repl');
+ if (ret !== undefined) {
+ context._ = ret;
+ self.stream.write(exports.writer(ret) + '\n');
+ }
- self.buffered_cmd = '';
+ self.buffered_cmd = '';
+ } catch (e) {
+ // instanceof doesn't work across context switches.
+ if (!(e && e.constructor && e.constructor.name === 'SyntaxError')) {
+ throw e;
+ // It could also be an error from JSON.parse
+ } else if (e &&
+ e.stack &&
+ e.stack.match('Unexpected token ILLEGAL') &&
+ e.stack.match(/Object.parse \(native\)/)) {
+ throw e;
+ }
+ }
} catch (e) {
- // instanceof doesn't work across context switches.
- if (!(e && e.constructor && e.constructor.name === 'SyntaxError')) {
- throw e;
- // It could also be an error from JSON.parse
- } else if (e &&
- e.stack &&
- e.stack.match('Unexpected token ILLEGAL') &&
- e.stack.match(/Object.parse \(native\)/)) {
- throw e;
+ // On error: Print the error and clear the buffer
+ if (e.stack) {
+ self.stream.write(e.stack + '\n');
+ } else {
+ self.stream.write(e.toString() + '\n');
}
+ self.buffered_cmd = '';
}
- } catch (e) {
- // On error: Print the error and clear the buffer
- if (e.stack) {
- self.stream.write(e.stack + '\n');
- } else {
- self.stream.write(e.toString() + '\n');
- }
- self.buffered_cmd = '';
}
self.displayPrompt();