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

LibJS: Implement RegExp legacy static properties

RegExp legacy static properties Spec url is https://github.com/tc39/proposal-regexp-legacy-features
This commit is contained in:
leeight 2022-10-17 08:59:27 +08:00 committed by Linus Groh
parent 5e2fe7e2bf
commit 0d96468e9b
12 changed files with 726 additions and 9 deletions

View file

@ -3510,7 +3510,14 @@ Completion RegExpLiteral::execute(Interpreter& interpreter) const
// 3. Return ! RegExpCreate(pattern, flags).
Regex<ECMA262> regex(parsed_regex(), parsed_pattern(), parsed_flags());
return Value { RegExpObject::create(realm, move(regex), move(pattern), move(flags)) };
// NOTE: We bypass RegExpCreate and subsequently RegExpAlloc as an optimization to use the already parsed values.
auto* regexp_object = RegExpObject::create(realm, move(regex), move(pattern), move(flags));
// RegExpAlloc has these two steps from the 'Legacy RegExp features' proposal.
regexp_object->set_realm(*vm.current_realm());
// We don't need to check 'If SameValue(newTarget, thisRealm.[[Intrinsics]].[[%RegExp%]]) is true'
// here as we know RegExpCreate calls RegExpAlloc with %RegExp% for newTarget.
regexp_object->set_legacy_features_enabled(true);
return Value { regexp_object };
}
void ArrayExpression::dump(int indent) const