This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

repl: make invalid RegExps throw in the REPL

Fixes #2746.
  • Loading branch information...
1 parent f536eb1 commit 4a2670740c0e8cb4831c2c089cc7de7337a55e80 @TooTallNate TooTallNate committed Sep 22, 2012
Showing with 7 additions and 0 deletions.
  1. +3 −0 lib/repl.js
  2. +4 −0 test/simple/test-repl.js
View
@@ -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/));
}
View
@@ -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 },

0 comments on commit 4a26707

Please sign in to comment.