Browse Source

repl: make invalid RegExps throw in the REPL

Fixes #2746.
v0.8.11-release
Nathan Rajlich 12 years ago
parent
commit
4a2670740c
  1. 3
      lib/repl.js
  2. 4
      test/simple/test-repl.js

3
lib/repl.js

@ -271,6 +271,9 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
// Convert error to string // Convert error to string
e = e && (e.stack || e.toString()); e = e && (e.stack || e.toString());
return e && e.match(/^SyntaxError/) && 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(/^SyntaxError: Unexpected token .*\n/) &&
e.match(/\n at Object.parse \(native\)\n/)); e.match(/\n at Object.parse \(native\)\n/));
} }

4
test/simple/test-repl.js

@ -126,6 +126,10 @@ function error_test() {
// should throw // should throw
{ client: client_unix, send: 'JSON.parse(\'{invalid: \\\'json\\\'}\');', { client: client_unix, send: 'JSON.parse(\'{invalid: \\\'json\\\'}\');',
expect: /^SyntaxError: Unexpected token i/ }, 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: // Named functions can be used:
{ client: client_unix, send: 'function blah() { return 1; }', { client: client_unix, send: 'function blah() { return 1; }',
expect: prompt_unix }, expect: prompt_unix },

Loading…
Cancel
Save