1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:07:34 +00:00

LibJS: Parse RegExp literals at AST creation time, not execution time

The spec requires that invalid RegExp literals must cause a Syntax Error
before the JavaScript is executed. See:
https://tc39.es/ecma262/#sec-patterns-static-semantics-early-errors

This is explicitly tested in the RegExp/property-escapes test262 tests.
For example, see unsupported-property-Line_Break.js:

    $DONOTEVALUATE();
    /\p{Line_Break}/u;

That RegExp literal is invalid because Line_Break is not a supported
Unicode property. $DONOTEVALUATE() just throws an exception when it is
executed. The test expects that this file will fail to be parsed.

Note that RegExp patterns can still be parsed at execution time by way
of "new RegExp(...)".
This commit is contained in:
Timothy Flynn 2021-07-29 10:34:37 -04:00 committed by Linus Groh
parent 1400e3cf58
commit f1dd770a8a
6 changed files with 124 additions and 94 deletions

View file

@ -2020,7 +2020,9 @@ void RegExpLiteral::dump(int indent) const
Value RegExpLiteral::execute(Interpreter& interpreter, GlobalObject& global_object) const
{
InterpreterNodeScope node_scope { interpreter, *this };
return regexp_create(global_object, js_string(interpreter.heap(), pattern()), js_string(interpreter.heap(), flags()));
Regex<ECMA262> regex(parsed_regex(), parsed_pattern(), parsed_flags());
return RegExpObject::create(global_object, move(regex), pattern(), flags());
}
void ArrayExpression::dump(int indent) const