summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Rajlich <nathan@tootallnate.net>2012-09-21 18:46:16 -0700
committerNathan Rajlich <nathan@tootallnate.net>2012-09-21 19:49:29 -0700
commit4a2670740c0e8cb4831c2c089cc7de7337a55e80 (patch)
treec8ec6296528f63d1e95987db6663b3f6c4ec0ad7
parentf536eb176b0b4d167d2d34357a12a83a30c71c97 (diff)
downloadnode-4a2670740c0e8cb4831c2c089cc7de7337a55e80.tar.gz
repl: make invalid RegExps throw in the REPL
Fixes #2746.
-rw-r--r--lib/repl.js3
-rw-r--r--test/simple/test-repl.js4
2 files changed, 7 insertions, 0 deletions
diff --git a/lib/repl.js b/lib/repl.js
index 98c14e734..fcb9c1f32 100644
--- a/lib/repl.js
+++ b/lib/repl.js
@@ -271,6 +271,9 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
// Convert error to string
e = e && (e.stack || e.toString());
return e && e.match(/^SyntaxError/) &&
+ // RegExp syntax error
+ !e.match(/^SyntaxError: Invalid regular expression/) &&
+ // JSON.parse() error
!(e.match(/^SyntaxError: Unexpected token .*\n/) &&
e.match(/\n at Object.parse \(native\)\n/));
}
diff --git a/test/simple/test-repl.js b/test/simple/test-repl.js
index 6cf2aaaac..7360dfd99 100644
--- a/test/simple/test-repl.js
+++ b/test/simple/test-repl.js
@@ -126,6 +126,10 @@ function error_test() {
// should throw
{ client: client_unix, send: 'JSON.parse(\'{invalid: \\\'json\\\'}\');',
expect: /^SyntaxError: Unexpected token i/ },
+ // invalid RegExps are a special case of syntax error,
+ // should throw
+ { client: client_unix, send: '/(/;',
+ expect: /^SyntaxError: Invalid regular expression\:/ },
// Named functions can be used:
{ client: client_unix, send: 'function blah() { return 1; }',
expect: prompt_unix },