1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:18:11 +00:00

LibJS: Implement RegExpCreate/RegExpInitialize closer to the spec

RegExpInitialize specifies how the pattern string should be created
before passing it to [[RegExpMatcher]]. Rather than passing it as-is,
the string should be converted to code points and back to a "List" (if
the Unicode flag is present), or as a "List" of UTF-16 code units.
Further. the spec requires that we keep both the original pattern string
and this parsed string in the RegExp object.

The caveat is that the LibRegex parser further requires any multi-byte
code units to be escaped (as "\unnnn"). Otherwise, the code unit is
recognized as individual UTF-8 bytes.
This commit is contained in:
Timothy Flynn 2021-07-22 08:04:31 -04:00 committed by Linus Groh
parent 345ef6abba
commit a0c19deb80
3 changed files with 55 additions and 20 deletions

View file

@ -175,7 +175,7 @@ void NewRegExp::execute_impl(Bytecode::Interpreter& interpreter) const
auto source = interpreter.current_executable().get_string(m_source_index);
auto flags = interpreter.current_executable().get_string(m_flags_index);
interpreter.accumulator() = RegExpObject::create(interpreter.global_object(), source, flags);
interpreter.accumulator() = regexp_create(interpreter.global_object(), js_string(interpreter.vm(), source), js_string(interpreter.vm(), flags));
}
void CopyObjectExcludingProperties::execute_impl(Bytecode::Interpreter& interpreter) const