Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
repl: make invalid RegExps throw in the REPL
Browse files Browse the repository at this point in the history
Fixes #2746.
  • Loading branch information
TooTallNate committed Sep 22, 2012
1 parent 0400571 commit 4f38a86
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/repl.js
Expand Up @@ -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/));
}
Expand Down
4 changes: 4 additions & 0 deletions test/simple/test-repl.js
Expand Up @@ -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 },
Expand Down

1 comment on commit 4f38a86

@bnoordhuis
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Please sign in to comment.