diff options
author | Timothy Flynn <trflynn89@pm.me> | 2021-07-29 10:34:37 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-07-30 21:26:31 +0100 |
commit | f1dd770a8a710c086e357e6fb89a28e27795f998 (patch) | |
tree | e76e0882cb68ec6fe53c77cf5a250488eca52de7 /Userland/Libraries/LibJS/AST.cpp | |
parent | 1400e3cf58c14594f06d98db25e10f908480ce67 (diff) | |
download | serenity-f1dd770a8a710c086e357e6fb89a28e27795f998.zip |
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(...)".
Diffstat (limited to 'Userland/Libraries/LibJS/AST.cpp')
-rw-r--r-- | Userland/Libraries/LibJS/AST.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index 5867f5b56d..32f7f21f5f 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -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 |