/* * Copyright (c) 2020, Matthew Olsson * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include namespace JS { ThrowCompletionOr regexp_create(VM&, Value pattern, Value flags); Result, String> regex_flags_from_string(StringView flags); struct ParseRegexPatternError { String error; }; ErrorOr parse_regex_pattern(StringView pattern, bool unicode, bool unicode_sets); ThrowCompletionOr parse_regex_pattern(VM& vm, StringView pattern, bool unicode, bool unicode_sets); class RegExpObject : public Object { JS_OBJECT(RegExpObject, Object); public: // JS regexps are all 'global' by default as per our definition, but the "global" flag enables "stateful". // FIXME: Enable 'BrowserExtended' only if in a browser context. static constexpr regex::RegexOptions default_flags { (regex::ECMAScriptFlags)regex::AllFlags::SingleMatch | (regex::ECMAScriptFlags)regex::AllFlags::Global | (regex::ECMAScriptFlags)regex::AllFlags::SkipTrimEmptyMatches | regex::ECMAScriptFlags::BrowserExtended }; static RegExpObject* create(Realm&); static RegExpObject* create(Realm&, Regex regex, String pattern, String flags); ThrowCompletionOr regexp_initialize(VM&, Value pattern, Value flags); String escape_regexp_pattern() const; virtual void initialize(Realm&) override; virtual ~RegExpObject() override = default; String const& pattern() const { return m_pattern; } String const& flags() const { return m_flags; } Regex const& regex() { return *m_regex; } Regex const& regex() const { return *m_regex; } private: RegExpObject(Object& prototype); RegExpObject(Regex regex, String pattern, String flags, Object& prototype); String m_pattern; String m_flags; Optional> m_regex; }; }