mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:57:44 +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:
parent
345ef6abba
commit
a0c19deb80
3 changed files with 55 additions and 20 deletions
|
@ -23,20 +23,21 @@ class RegExpObject : public Object {
|
|||
JS_OBJECT(RegExpObject, Object);
|
||||
|
||||
public:
|
||||
static RegExpObject* create(GlobalObject&, String pattern, String flags);
|
||||
static RegExpObject* create(GlobalObject&, String original_pattern, String parsed_pattern, String flags);
|
||||
|
||||
RegExpObject(String pattern, String flags, Object& prototype);
|
||||
RegExpObject(String original_pattern, String parsed_pattern, String flags, Object& prototype);
|
||||
virtual void initialize(GlobalObject&) override;
|
||||
virtual ~RegExpObject() override;
|
||||
|
||||
const String& pattern() const { return m_pattern; }
|
||||
const String& pattern() const { return m_original_pattern; }
|
||||
const String& flags() const { return m_flags; }
|
||||
const regex::RegexOptions<ECMAScriptFlags>& declared_options() { return m_active_flags.declared_flags; }
|
||||
const Regex<ECMA262>& regex() { return m_regex; }
|
||||
const Regex<ECMA262>& regex() const { return m_regex; }
|
||||
|
||||
private:
|
||||
String m_pattern;
|
||||
String m_original_pattern;
|
||||
String m_parsed_pattern;
|
||||
String m_flags;
|
||||
Flags m_active_flags;
|
||||
Regex<ECMA262> m_regex;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue