Skip to content

Regular expression flags should be checked at runtime, not at lexing time #503

Closed

Description

@LuoZijun

CodeLine:

let new_flag = match c {
b'g' => Self::GLOBAL,
b'i' => Self::IGNORE_CASE,
b'm' => Self::MULTILINE,
b's' => Self::DOT_ALL,
b'u' => Self::UNICODE,
b'y' => Self::STICKY,
_ => {

11.8.5 Regular Expression Literals: https://www.ecma-international.org/ecma-262/10.0/#sec-literals-regular-expression-literals

The ECMAScript spec said, RegularExpressionFlags is empty or IdentifierPart.

Activity

  1. LuoZijun commented on Jun 17, 2020

    @LuoZijun
    Author
  2. Razican commented on Jun 22, 2020

    @Razican
    Member

    Hi @LuoZijun could you explain a bit the issue you found? We are generating the regular expression flags as per the spec, right?

  3. LuoZijun commented on Jun 22, 2020

    @LuoZijun
    Author

    @Razican I mean the invalid regular expression flag error should be decided by Runtime. Not Lexer.

  4. changed the title [-][Lexer] Regular Expression[/-] [+]Regular expression flags should be checked at runtime, not at lexing time[/+] on Jul 2, 2020
  5. added
    A-Bug
    C-Builtins
    on Jul 2, 2020
  6. Razican commented on Jul 2, 2020

    @Razican
    Member

    After reviewing the specification, I can see that the only static error that this should throw should be in case we find a unicode scape sequence in the flags:
    https://www.ecma-international.org/ecma-262/10.0/#sec-literals-regular-expression-literals-static-semantics-early-errors

    But then, on runtime, we get the Syntax Error:
    https://www.ecma-international.org/ecma-262/10.0/#sec-regexpinitialize

    The thing is that this would prevent some optimizations, and I can see that both V8 and Spidermonkey throw a syntax error statically, before running the code.

    I tried this code to test it:

    function a() {
    	return /abc/abc;
    }

    Note that this throws a Syntax Error even if it's not being executed.

    In any case, is there a particular situation where this is causing pain? Do you have an example situation where this is behaving diferently to common browsers? Or any particular situation where this could be an issue?

  7. Razican commented on Dec 25, 2021

    @Razican
    Member

    After checking this thoroughly and following the Test262 suite, it turns out that these flags must be checked at parsing time (early error) and not at runtime, so I'm closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-BugC-Builtins

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions