summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/RegExpObject.h
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2021-07-22 08:04:31 -0400
committerLinus Groh <mail@linusgroh.de>2021-07-23 23:06:57 +0100
commita0c19deb80e6a1bf9503acbc643f49671e3a65b4 (patch)
treee9f1bbdbb7fed2bf47dd7998da66b18492bffaf2 /Userland/Libraries/LibJS/Runtime/RegExpObject.h
parent345ef6abba68c1a96e5f5e365f1a2e8dc1762955 (diff)
downloadserenity-a0c19deb80e6a1bf9503acbc643f49671e3a65b4.zip
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.
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/RegExpObject.h')
-rw-r--r--Userland/Libraries/LibJS/Runtime/RegExpObject.h9
1 files changed, 5 insertions, 4 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/RegExpObject.h b/Userland/Libraries/LibJS/Runtime/RegExpObject.h
index 4ee57d3764..528a9f1129 100644
--- a/Userland/Libraries/LibJS/Runtime/RegExpObject.h
+++ b/Userland/Libraries/LibJS/Runtime/RegExpObject.h
@@ -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;