RegExpLegacyStaticProperties.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (c) 2022, LI YUBEI <leeight@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Optional.h>
  8. #include <LibJS/Forward.h>
  9. #include <LibJS/Runtime/Utf16String.h>
  10. namespace JS {
  11. // https://github.com/tc39/proposal-regexp-legacy-features#regexp
  12. // The %RegExp% intrinsic object, which is the builtin RegExp constructor, has the following additional internal slots:
  13. // [[RegExpInput]]
  14. // [[RegExpLastMatch]]
  15. // [[RegExpLastParen]]
  16. // [[RegExpLeftContext]]
  17. // [[RegExpRightContext]]
  18. // [[RegExpParen1]] ... [[RegExpParen9]]
  19. class RegExpLegacyStaticProperties {
  20. public:
  21. Optional<Utf16String> const& input() const { return m_input; }
  22. Optional<Utf16String> const& last_match() const { return m_last_match; }
  23. Optional<Utf16String> const& last_paren() const { return m_last_paren; }
  24. Optional<Utf16String> const& left_context() const { return m_left_context; }
  25. Optional<Utf16String> const& right_context() const { return m_right_context; }
  26. Optional<Utf16String> const& $1() const { return m_$1; }
  27. Optional<Utf16String> const& $2() const { return m_$2; }
  28. Optional<Utf16String> const& $3() const { return m_$3; }
  29. Optional<Utf16String> const& $4() const { return m_$4; }
  30. Optional<Utf16String> const& $5() const { return m_$5; }
  31. Optional<Utf16String> const& $6() const { return m_$6; }
  32. Optional<Utf16String> const& $7() const { return m_$7; }
  33. Optional<Utf16String> const& $8() const { return m_$8; }
  34. Optional<Utf16String> const& $9() const { return m_$9; }
  35. void set_input(Utf16String input) { m_input = move(input); }
  36. void set_last_match(Utf16String last_match) { m_last_match = move(last_match); }
  37. void set_last_paren(Utf16String last_paren) { m_last_paren = move(last_paren); }
  38. void set_left_context(Utf16String left_context) { m_left_context = move(left_context); }
  39. void set_right_context(Utf16String right_context) { m_right_context = move(right_context); }
  40. void set_$1(Utf16String value) { m_$1 = move(value); }
  41. void set_$2(Utf16String value) { m_$2 = move(value); }
  42. void set_$3(Utf16String value) { m_$3 = move(value); }
  43. void set_$4(Utf16String value) { m_$4 = move(value); }
  44. void set_$5(Utf16String value) { m_$5 = move(value); }
  45. void set_$6(Utf16String value) { m_$6 = move(value); }
  46. void set_$7(Utf16String value) { m_$7 = move(value); }
  47. void set_$8(Utf16String value) { m_$8 = move(value); }
  48. void set_$9(Utf16String value) { m_$9 = move(value); }
  49. void invalidate();
  50. private:
  51. Optional<Utf16String> m_input;
  52. Optional<Utf16String> m_last_match;
  53. Optional<Utf16String> m_last_paren;
  54. Optional<Utf16String> m_left_context;
  55. Optional<Utf16String> m_right_context;
  56. Optional<Utf16String> m_$1;
  57. Optional<Utf16String> m_$2;
  58. Optional<Utf16String> m_$3;
  59. Optional<Utf16String> m_$4;
  60. Optional<Utf16String> m_$5;
  61. Optional<Utf16String> m_$6;
  62. Optional<Utf16String> m_$7;
  63. Optional<Utf16String> m_$8;
  64. Optional<Utf16String> m_$9;
  65. };
  66. ThrowCompletionOr<void> set_legacy_regexp_static_property(VM& vm, RegExpConstructor& constructor, Value this_value, void (RegExpLegacyStaticProperties::*property_setter)(Utf16String), Value value);
  67. ThrowCompletionOr<Value> get_legacy_regexp_static_property(VM& vm, RegExpConstructor& constructor, Value this_value, Optional<Utf16String> const& (RegExpLegacyStaticProperties::*property_getter)() const);
  68. void update_legacy_regexp_static_properties(RegExpConstructor& constructor, Utf16String const& string, size_t start_index, size_t end_index, Vector<Utf16String> const& captured_values);
  69. void invalidate_legacy_regexp_static_properties(RegExpConstructor& constructor);
  70. }