repl: make invalid RegExp modifiers throw in the REPL

Fixes #4012.
This commit is contained in:
Nathan Rajlich 2012-09-30 22:43:35 -07:00
parent fa912c246c
commit f1722a280c
2 changed files with 5 additions and 0 deletions

View File

@ -273,6 +273,7 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
return e && e.match(/^SyntaxError/) &&
// RegExp syntax error
!e.match(/^SyntaxError: Invalid regular expression/) &&
!e.match(/^SyntaxError: Invalid flags supplied to RegExp constructor/) &&
// JSON.parse() error
!(e.match(/^SyntaxError: Unexpected token .*\n/) &&
e.match(/\n at Object.parse \(native\)\n/));

View File

@ -130,6 +130,10 @@ function error_test() {
// should throw
{ client: client_unix, send: '/(/;',
expect: /^SyntaxError: Invalid regular expression\:/ },
// invalid RegExp modifiers are a special case of syntax error,
// should throw (GH-4012)
{ client: client_unix, send: 'new RegExp("foo", "wrong modifier");',
expect: /^SyntaxError: Invalid flags supplied to RegExp constructor/ },
// Named functions can be used:
{ client: client_unix, send: 'function blah() { return 1; }',
expect: prompt_unix },