RegExpObject.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibJS/AST.h>
  8. #include <LibJS/Runtime/Object.h>
  9. #include <LibRegex/Regex.h>
  10. struct Flags {
  11. regex::RegexOptions<ECMAScriptFlags> effective_flags;
  12. regex::RegexOptions<ECMAScriptFlags> declared_flags;
  13. };
  14. namespace JS {
  15. RegExpObject* regexp_create(GlobalObject&, Value pattern, Value flags);
  16. class RegExpObject : public Object {
  17. JS_OBJECT(RegExpObject, Object);
  18. public:
  19. static RegExpObject* create(GlobalObject&, String original_pattern, String parsed_pattern, String flags);
  20. RegExpObject(String original_pattern, String parsed_pattern, String flags, Object& prototype);
  21. virtual void initialize(GlobalObject&) override;
  22. virtual ~RegExpObject() override;
  23. const String& pattern() const { return m_original_pattern; }
  24. const String& flags() const { return m_flags; }
  25. const regex::RegexOptions<ECMAScriptFlags>& declared_options() { return m_active_flags.declared_flags; }
  26. const Regex<ECMA262>& regex() { return m_regex; }
  27. const Regex<ECMA262>& regex() const { return m_regex; }
  28. private:
  29. String m_original_pattern;
  30. String m_parsed_pattern;
  31. String m_flags;
  32. Flags m_active_flags;
  33. Regex<ECMA262> m_regex;
  34. };
  35. }