You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Regular expression flags should be checked at runtime, not at lexing time #503
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:
functiona(){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?
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.
Activity
LuoZijun commentedon Jun 17, 2020
The runtime defined flags: g, i, m, s, u, y
[MDN] Advanced searching with flags: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Advanced_searching_with_flags_2
Razican commentedon Jun 22, 2020
Hi @LuoZijun could you explain a bit the issue you found? We are generating the regular expression flags as per the spec, right?
LuoZijun commentedon Jun 22, 2020
@Razican I mean the
invalid regular expression flagerror should be decided by Runtime. Not Lexer.[-][Lexer] Regular Expression[/-][+]Regular expression flags should be checked at runtime, not at lexing time[/+]Razican commentedon Jul 2, 2020
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:
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?
Razican commentedon Dec 25, 2021
There are some early errors that must be taken into account: https://262.ecma-international.org/10.0/#sec-primary-expression-regular-expression-literals-static-semantics-early-errors
Razican commentedon Dec 25, 2021
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.