New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.
Starred by 28 users

Issue metadata

Status: Assigned
Owner:
Cc:
Components:
HW: All
NextAction: ----
OS: All
Priority: 2
Type: ----
ES5

Blocked on:
issue 2728

Blocking:
issue 4743



Sign in to add a comment

Invalid reg exp not reported as an early error.

Reported by utatane....@gmail.com, Oct 13 2010

Issue description

according to ES5 section 7.8.5, "the error must be treated as an early error"

example:

  function test() {
    /(/.test("(");
  }
  test();  // UNREACHABLE

If /(/ is invalid RegExp Literal and this throws SyntaxError, this SyntaxError is an early error and should be reported prior to the evaluation of that Program.
 
Labels: ES5
Status: Accepted
Parsing or pre-parsing regexps must detect and throw the syntax error.
Cc: mmaly%ch...@gtempaccount.com

Comment 3 by lrn@chromium.org, Oct 4 2011

Cc: -mmaly@chromium.org
Owner: lrn@chromium.org
Owner: yangguo@chromium.org
Owner: marja@chromium.org

Comment 6 by marja@chromium.org, Jul 2 2014

This bug report is still valid; /(/ is not detected during parsing (or preparsing).

So for example this parses fine:

function test() { /(/.test("("); } 

Comment 7 by marja@chromium.org, Apr 24 2015

Cc: marja@chromium.org
Owner: rossberg@chromium.org
Reassigning generic parsing bugs to rossberg@.
 Issue 3384  has been merged into this issue.
Summary: Invalid reg exp not reported as an early error. (was: Invalid RegExp reports SyntaxError as an early error.)
Labels: Priority-Medium

Comment 11 by habl...@google.com, Apr 29 2015

Status: Assigned
Labels: Hotlist-test262

Comment 13 by adamk@chromium.org, May 23 2016

Cc: rossberg@chromium.org
Owner: ----
Status: Available (was: Assigned)

Comment 14 by adamk@chromium.org, May 23 2016

Components: Language

Comment 15 by adamk@chromium.org, Jun 14 2016

Cc: nikolaos@chromium.org
Labels: SpecViolation-Backlog

Comment 17 by adamk@chromium.org, Dec 21 2016

Blockedon: 2728
Labels: Priority-2

Comment 19 by math...@qiwi.be, May 1 2017

Blocking: 4743
Cc: jgruber@chromium.org yangguo@chromium.org
Cc: littledan@chromium.org
Labels: HW-All OS-All
Owner: mathias@chromium.org
Status: Assigned (was: Available)
Reassigning to mathias@, do you perhaps have any insight here? V8 seems to be in clear spec violation regarding regexp early errors, but as far as I'm aware there are no plans to change this.
 Issue chromium:746942  has been merged into this issue.
I had heard this was all a question of performance. From an eshost test, it seems like other JS implementations may be checking these things in the preparser, unlike V8 (though maybe I'm being overly optimistic about what's lazily parsed). If an efficient RegExp validator can be implemented in parser-base.cc, that would be nice.

Comment 24 by adamk@chromium.org, Jul 25 2017

Cc: -rossberg@chromium.org
Components: Parser
My understanding is that detecting these errors early in V8 would have too much of a negative performance impact for relatively little gain. Unless someone comes up with an efficient way of validating RegExps during parsing, this is unlikely to change.

Some questions I still have: is swapping early errors for runtime errors an acceptable spec deviation? What about new proposals such as Unicode property escapes? Those early errors are runtime errors in V8. Should that block shipping? Should the spec proposal be updated accordingly, knowing that it would be inconsistent with the rest of the language?

Comment 26 by marja@chromium.org, Jul 31 2017

Looks like Scanner::ScanRegExpPattern is pretty simple; it just collects ( and ) among other chars and doesn't do anything specific for them.

Depending on what errors we want to recognize, it might not be that costly. E.g., making it track ( and ) and see if they match sounds pretty simple - probably collecting the chars into the buffer dominates.

However, it's still extra work... Dunno.
There's a whole section of failing test262 tests that covers this; it's definitely a lot more than just matching parens. Some examples:

/?/
/{2}/
/{2,3}/
/\u{110000}/u
/\8/u

Though interestingly, even engines that throw early errors for regexps don't get all these right.
FWIW V8 already implements the #984 PR--at the moment that RegExps are parsed and compiled, those sorts of errors are thrown. V8 doesn't implement the old specification, which would throw a SyntaxError when the part of the RegExp is actually dynamically reached by executing on a string.
Components: Regexp

Sign in to add a comment