From 4a2670740c0e8cb4831c2c089cc7de7337a55e80 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Fri, 21 Sep 2012 18:46:16 -0700 Subject: [PATCH] repl: make invalid RegExps throw in the REPL Fixes #2746. --- lib/repl.js | 3 +++ test/simple/test-repl.js | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/lib/repl.js b/lib/repl.js index 98c14e7344..fcb9c1f32f 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 6cf2aaaac3..7360dfd998 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 },