1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:37:45 +00:00

LibJS: Hook up Regex<ECMA262> to RegExpObject and implement `test()'

This makes RegExpObject compile and store a Regex<ECMA262>, adds
all flag-related properties, and implements `RegExpPrototype.test()`
(complete with 'lastIndex' support) :^)
It should be noted that this only implements `test()' using the builtin
`exec()'.
This commit is contained in:
AnotherTest 2020-11-19 01:50:00 +03:30 committed by Andreas Kling
parent 75081b2bdd
commit 8ba273a2f3
13 changed files with 396 additions and 12 deletions

View file

@ -28,6 +28,12 @@
#include <LibJS/AST.h>
#include <LibJS/Runtime/Object.h>
#include <LibRegex/Regex.h>
struct Flags {
regex::RegexOptions<ECMAScriptFlags> effective_flags;
regex::RegexOptions<ECMAScriptFlags> declared_flags;
};
namespace JS {
@ -38,16 +44,25 @@ public:
static RegExpObject* create(GlobalObject&, String pattern, String flags);
RegExpObject(String pattern, String flags, Object& prototype);
virtual void initialize(GlobalObject&) override;
virtual ~RegExpObject() override;
const String& pattern() const { return m_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:
virtual bool is_regexp_object() const override { return true; }
JS_DECLARE_NATIVE_GETTER(last_index);
JS_DECLARE_NATIVE_SETTER(set_last_index);
String m_pattern;
String m_flags;
Flags m_active_flags;
Regex<ECMA262> m_regex;
};
}