11cb0ef41Sopenharmony_ci// Copyright 2017 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#ifndef V8_OBJECTS_JS_REGEXP_H_
61cb0ef41Sopenharmony_ci#define V8_OBJECTS_JS_REGEXP_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include "include/v8-regexp.h"
91cb0ef41Sopenharmony_ci#include "src/objects/contexts.h"
101cb0ef41Sopenharmony_ci#include "src/objects/js-array.h"
111cb0ef41Sopenharmony_ci#include "src/regexp/regexp-flags.h"
121cb0ef41Sopenharmony_ci#include "torque-generated/bit-fields.h"
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci// Has to be the last include (doesn't have include guards):
151cb0ef41Sopenharmony_ci#include "src/objects/object-macros.h"
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_cinamespace v8 {
181cb0ef41Sopenharmony_cinamespace internal {
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ci#include "torque-generated/src/objects/js-regexp-tq.inc"
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci// Regular expressions
231cb0ef41Sopenharmony_ci// The regular expression holds a single reference to a FixedArray in
241cb0ef41Sopenharmony_ci// the kDataOffset field.
251cb0ef41Sopenharmony_ci// The FixedArray contains the following data:
261cb0ef41Sopenharmony_ci// - tag : type of regexp implementation (not compiled yet, atom or irregexp)
271cb0ef41Sopenharmony_ci// - reference to the original source string
281cb0ef41Sopenharmony_ci// - reference to the original flag string
291cb0ef41Sopenharmony_ci// If it is an atom regexp
301cb0ef41Sopenharmony_ci// - a reference to a literal string to search for
311cb0ef41Sopenharmony_ci// If it is an irregexp regexp:
321cb0ef41Sopenharmony_ci// - a reference to code for Latin1 inputs (bytecode or compiled), or a smi
331cb0ef41Sopenharmony_ci// used for tracking the last usage (used for regexp code flushing).
341cb0ef41Sopenharmony_ci// - a reference to code for UC16 inputs (bytecode or compiled), or a smi
351cb0ef41Sopenharmony_ci// used for tracking the last usage (used for regexp code flushing).
361cb0ef41Sopenharmony_ci// - max number of registers used by irregexp implementations.
371cb0ef41Sopenharmony_ci// - number of capture registers (output values) of the regexp.
381cb0ef41Sopenharmony_ciclass JSRegExp : public TorqueGeneratedJSRegExp<JSRegExp, JSObject> {
391cb0ef41Sopenharmony_ci public:
401cb0ef41Sopenharmony_ci  enum Type {
411cb0ef41Sopenharmony_ci    NOT_COMPILED,  // Initial value. No data array has been set yet.
421cb0ef41Sopenharmony_ci    ATOM,          // A simple string match.
431cb0ef41Sopenharmony_ci    IRREGEXP,      // Compiled with Irregexp (code or bytecode).
441cb0ef41Sopenharmony_ci    EXPERIMENTAL,  // Compiled to use the experimental linear time engine.
451cb0ef41Sopenharmony_ci  };
461cb0ef41Sopenharmony_ci  DEFINE_TORQUE_GENERATED_JS_REG_EXP_FLAGS()
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE static MaybeHandle<JSRegExp> New(
491cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<String> source, Flags flags,
501cb0ef41Sopenharmony_ci      uint32_t backtrack_limit = kNoBacktrackLimit);
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_ci  static MaybeHandle<JSRegExp> Initialize(
531cb0ef41Sopenharmony_ci      Handle<JSRegExp> regexp, Handle<String> source, Flags flags,
541cb0ef41Sopenharmony_ci      uint32_t backtrack_limit = kNoBacktrackLimit);
551cb0ef41Sopenharmony_ci  static MaybeHandle<JSRegExp> Initialize(Handle<JSRegExp> regexp,
561cb0ef41Sopenharmony_ci                                          Handle<String> source,
571cb0ef41Sopenharmony_ci                                          Handle<String> flags_string);
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ci  DECL_ACCESSORS(last_index, Object)
601cb0ef41Sopenharmony_ci
611cb0ef41Sopenharmony_ci  // Instance fields accessors.
621cb0ef41Sopenharmony_ci  inline String source() const;
631cb0ef41Sopenharmony_ci  inline Flags flags() const;
641cb0ef41Sopenharmony_ci
651cb0ef41Sopenharmony_ci  // Data array field accessors.
661cb0ef41Sopenharmony_ci
671cb0ef41Sopenharmony_ci  inline Type type_tag() const;
681cb0ef41Sopenharmony_ci  inline String atom_pattern() const;
691cb0ef41Sopenharmony_ci  // This could be a Smi kUninitializedValue or Code.
701cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE Object code(bool is_latin1) const;
711cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE void set_code(bool is_unicode, Handle<Code> code);
721cb0ef41Sopenharmony_ci  // This could be a Smi kUninitializedValue or ByteArray.
731cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE Object bytecode(bool is_latin1) const;
741cb0ef41Sopenharmony_ci  // Sets the bytecode as well as initializing trampoline slots to the
751cb0ef41Sopenharmony_ci  // RegExpInterpreterTrampoline.
761cb0ef41Sopenharmony_ci  void set_bytecode_and_trampoline(Isolate* isolate,
771cb0ef41Sopenharmony_ci                                   Handle<ByteArray> bytecode);
781cb0ef41Sopenharmony_ci  inline int max_register_count() const;
791cb0ef41Sopenharmony_ci  // Number of captures (without the match itself).
801cb0ef41Sopenharmony_ci  inline int capture_count() const;
811cb0ef41Sopenharmony_ci  inline Object capture_name_map();
821cb0ef41Sopenharmony_ci  inline void set_capture_name_map(Handle<FixedArray> capture_name_map);
831cb0ef41Sopenharmony_ci  uint32_t backtrack_limit() const;
841cb0ef41Sopenharmony_ci
851cb0ef41Sopenharmony_ci  static constexpr Flag AsJSRegExpFlag(RegExpFlag f) {
861cb0ef41Sopenharmony_ci    return static_cast<Flag>(f);
871cb0ef41Sopenharmony_ci  }
881cb0ef41Sopenharmony_ci  static constexpr Flags AsJSRegExpFlags(RegExpFlags f) {
891cb0ef41Sopenharmony_ci    return Flags{static_cast<int>(f)};
901cb0ef41Sopenharmony_ci  }
911cb0ef41Sopenharmony_ci  static constexpr RegExpFlags AsRegExpFlags(Flags f) {
921cb0ef41Sopenharmony_ci    return RegExpFlags{static_cast<int>(f)};
931cb0ef41Sopenharmony_ci  }
941cb0ef41Sopenharmony_ci
951cb0ef41Sopenharmony_ci  static base::Optional<RegExpFlag> FlagFromChar(char c) {
961cb0ef41Sopenharmony_ci    base::Optional<RegExpFlag> f = TryRegExpFlagFromChar(c);
971cb0ef41Sopenharmony_ci    if (!f.has_value()) return f;
981cb0ef41Sopenharmony_ci    if (f.value() == RegExpFlag::kLinear &&
991cb0ef41Sopenharmony_ci        !FLAG_enable_experimental_regexp_engine) {
1001cb0ef41Sopenharmony_ci      return {};
1011cb0ef41Sopenharmony_ci    }
1021cb0ef41Sopenharmony_ci    return f;
1031cb0ef41Sopenharmony_ci  }
1041cb0ef41Sopenharmony_ci
1051cb0ef41Sopenharmony_ci  STATIC_ASSERT(static_cast<int>(kNone) == v8::RegExp::kNone);
1061cb0ef41Sopenharmony_ci#define V(_, Camel, ...)                                             \
1071cb0ef41Sopenharmony_ci  STATIC_ASSERT(static_cast<int>(k##Camel) == v8::RegExp::k##Camel); \
1081cb0ef41Sopenharmony_ci  STATIC_ASSERT(static_cast<int>(k##Camel) ==                        \
1091cb0ef41Sopenharmony_ci                static_cast<int>(RegExpFlag::k##Camel));
1101cb0ef41Sopenharmony_ci  REGEXP_FLAG_LIST(V)
1111cb0ef41Sopenharmony_ci#undef V
1121cb0ef41Sopenharmony_ci  STATIC_ASSERT(kFlagCount == v8::RegExp::kFlagCount);
1131cb0ef41Sopenharmony_ci  STATIC_ASSERT(kFlagCount == kRegExpFlagCount);
1141cb0ef41Sopenharmony_ci
1151cb0ef41Sopenharmony_ci  static base::Optional<Flags> FlagsFromString(Isolate* isolate,
1161cb0ef41Sopenharmony_ci                                               Handle<String> flags);
1171cb0ef41Sopenharmony_ci
1181cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE static Handle<String> StringFromFlags(Isolate* isolate,
1191cb0ef41Sopenharmony_ci                                                          Flags flags);
1201cb0ef41Sopenharmony_ci
1211cb0ef41Sopenharmony_ci  inline String EscapedPattern();
1221cb0ef41Sopenharmony_ci
1231cb0ef41Sopenharmony_ci  bool CanTierUp();
1241cb0ef41Sopenharmony_ci  bool MarkedForTierUp();
1251cb0ef41Sopenharmony_ci  void ResetLastTierUpTick();
1261cb0ef41Sopenharmony_ci  void TierUpTick();
1271cb0ef41Sopenharmony_ci  void MarkTierUpForNextExec();
1281cb0ef41Sopenharmony_ci
1291cb0ef41Sopenharmony_ci  bool ShouldProduceBytecode();
1301cb0ef41Sopenharmony_ci  inline bool HasCompiledCode() const;
1311cb0ef41Sopenharmony_ci  inline void DiscardCompiledCodeForSerialization();
1321cb0ef41Sopenharmony_ci
1331cb0ef41Sopenharmony_ci  static constexpr bool TypeSupportsCaptures(Type t) {
1341cb0ef41Sopenharmony_ci    return t == IRREGEXP || t == EXPERIMENTAL;
1351cb0ef41Sopenharmony_ci  }
1361cb0ef41Sopenharmony_ci
1371cb0ef41Sopenharmony_ci  // Each capture (including the match itself) needs two registers.
1381cb0ef41Sopenharmony_ci  static constexpr int RegistersForCaptureCount(int count) {
1391cb0ef41Sopenharmony_ci    return (count + 1) * 2;
1401cb0ef41Sopenharmony_ci  }
1411cb0ef41Sopenharmony_ci
1421cb0ef41Sopenharmony_ci  static constexpr int code_index(bool is_latin1) {
1431cb0ef41Sopenharmony_ci    return is_latin1 ? kIrregexpLatin1CodeIndex : kIrregexpUC16CodeIndex;
1441cb0ef41Sopenharmony_ci  }
1451cb0ef41Sopenharmony_ci
1461cb0ef41Sopenharmony_ci  static constexpr int bytecode_index(bool is_latin1) {
1471cb0ef41Sopenharmony_ci    return is_latin1 ? kIrregexpLatin1BytecodeIndex
1481cb0ef41Sopenharmony_ci                     : kIrregexpUC16BytecodeIndex;
1491cb0ef41Sopenharmony_ci  }
1501cb0ef41Sopenharmony_ci
1511cb0ef41Sopenharmony_ci  // Dispatched behavior.
1521cb0ef41Sopenharmony_ci  DECL_PRINTER(JSRegExp)
1531cb0ef41Sopenharmony_ci  DECL_VERIFIER(JSRegExp)
1541cb0ef41Sopenharmony_ci
1551cb0ef41Sopenharmony_ci  /* This is already an in-object field. */
1561cb0ef41Sopenharmony_ci  // TODO(v8:8944): improve handling of in-object fields
1571cb0ef41Sopenharmony_ci  static constexpr int kLastIndexOffset = kHeaderSize;
1581cb0ef41Sopenharmony_ci
1591cb0ef41Sopenharmony_ci  // The initial value of the last_index field on a new JSRegExp instance.
1601cb0ef41Sopenharmony_ci  static constexpr int kInitialLastIndexValue = 0;
1611cb0ef41Sopenharmony_ci
1621cb0ef41Sopenharmony_ci  // Indices in the data array.
1631cb0ef41Sopenharmony_ci  static constexpr int kTagIndex = 0;
1641cb0ef41Sopenharmony_ci  static constexpr int kSourceIndex = kTagIndex + 1;
1651cb0ef41Sopenharmony_ci  static constexpr int kFlagsIndex = kSourceIndex + 1;
1661cb0ef41Sopenharmony_ci  static constexpr int kFirstTypeSpecificIndex = kFlagsIndex + 1;
1671cb0ef41Sopenharmony_ci  static constexpr int kMinDataArrayLength = kFirstTypeSpecificIndex;
1681cb0ef41Sopenharmony_ci
1691cb0ef41Sopenharmony_ci  // The data fields are used in different ways depending on the
1701cb0ef41Sopenharmony_ci  // value of the tag.
1711cb0ef41Sopenharmony_ci  // Atom regexps (literal strings).
1721cb0ef41Sopenharmony_ci  static constexpr int kAtomPatternIndex = kFirstTypeSpecificIndex;
1731cb0ef41Sopenharmony_ci  static constexpr int kAtomDataSize = kAtomPatternIndex + 1;
1741cb0ef41Sopenharmony_ci
1751cb0ef41Sopenharmony_ci  // A Code object or a Smi marker value equal to kUninitializedValue.
1761cb0ef41Sopenharmony_ci  static constexpr int kIrregexpLatin1CodeIndex = kFirstTypeSpecificIndex;
1771cb0ef41Sopenharmony_ci  static constexpr int kIrregexpUC16CodeIndex = kIrregexpLatin1CodeIndex + 1;
1781cb0ef41Sopenharmony_ci  // A ByteArray object or a Smi marker value equal to kUninitializedValue.
1791cb0ef41Sopenharmony_ci  static constexpr int kIrregexpLatin1BytecodeIndex =
1801cb0ef41Sopenharmony_ci      kIrregexpUC16CodeIndex + 1;
1811cb0ef41Sopenharmony_ci  static constexpr int kIrregexpUC16BytecodeIndex =
1821cb0ef41Sopenharmony_ci      kIrregexpLatin1BytecodeIndex + 1;
1831cb0ef41Sopenharmony_ci  // Maximal number of registers used by either Latin1 or UC16.
1841cb0ef41Sopenharmony_ci  // Only used to check that there is enough stack space
1851cb0ef41Sopenharmony_ci  static constexpr int kIrregexpMaxRegisterCountIndex =
1861cb0ef41Sopenharmony_ci      kIrregexpUC16BytecodeIndex + 1;
1871cb0ef41Sopenharmony_ci  // Number of captures in the compiled regexp.
1881cb0ef41Sopenharmony_ci  static constexpr int kIrregexpCaptureCountIndex =
1891cb0ef41Sopenharmony_ci      kIrregexpMaxRegisterCountIndex + 1;
1901cb0ef41Sopenharmony_ci  // Maps names of named capture groups (at indices 2i) to their corresponding
1911cb0ef41Sopenharmony_ci  // (1-based) capture group indices (at indices 2i + 1).
1921cb0ef41Sopenharmony_ci  static constexpr int kIrregexpCaptureNameMapIndex =
1931cb0ef41Sopenharmony_ci      kIrregexpCaptureCountIndex + 1;
1941cb0ef41Sopenharmony_ci  // Tier-up ticks are set to the value of the tier-up ticks flag. The value is
1951cb0ef41Sopenharmony_ci  // decremented on each execution of the bytecode, so that the tier-up
1961cb0ef41Sopenharmony_ci  // happens once the ticks reach zero.
1971cb0ef41Sopenharmony_ci  // This value is ignored if the regexp-tier-up flag isn't turned on.
1981cb0ef41Sopenharmony_ci  static constexpr int kIrregexpTicksUntilTierUpIndex =
1991cb0ef41Sopenharmony_ci      kIrregexpCaptureNameMapIndex + 1;
2001cb0ef41Sopenharmony_ci  // A smi containing either the backtracking limit or kNoBacktrackLimit.
2011cb0ef41Sopenharmony_ci  // TODO(jgruber): If needed, this limit could be packed into other fields
2021cb0ef41Sopenharmony_ci  // above to save space.
2031cb0ef41Sopenharmony_ci  static constexpr int kIrregexpBacktrackLimit =
2041cb0ef41Sopenharmony_ci      kIrregexpTicksUntilTierUpIndex + 1;
2051cb0ef41Sopenharmony_ci  static constexpr int kIrregexpDataSize = kIrregexpBacktrackLimit + 1;
2061cb0ef41Sopenharmony_ci
2071cb0ef41Sopenharmony_ci  // TODO(mbid,v8:10765): At the moment the EXPERIMENTAL data array conforms
2081cb0ef41Sopenharmony_ci  // to the format of an IRREGEXP data array, with most fields set to some
2091cb0ef41Sopenharmony_ci  // default/uninitialized value. This is because EXPERIMENTAL and IRREGEXP
2101cb0ef41Sopenharmony_ci  // regexps take the same code path in `RegExpExecInternal`, which reads off
2111cb0ef41Sopenharmony_ci  // various fields from the data array. `RegExpExecInternal` should probably
2121cb0ef41Sopenharmony_ci  // distinguish between EXPERIMENTAL and IRREGEXP, and then we can get rid of
2131cb0ef41Sopenharmony_ci  // all the IRREGEXP only fields.
2141cb0ef41Sopenharmony_ci  static constexpr int kExperimentalDataSize = kIrregexpDataSize;
2151cb0ef41Sopenharmony_ci
2161cb0ef41Sopenharmony_ci  // In-object fields.
2171cb0ef41Sopenharmony_ci  static constexpr int kLastIndexFieldIndex = 0;
2181cb0ef41Sopenharmony_ci  static constexpr int kInObjectFieldCount = 1;
2191cb0ef41Sopenharmony_ci
2201cb0ef41Sopenharmony_ci  // The actual object size including in-object fields.
2211cb0ef41Sopenharmony_ci  static constexpr int Size() {
2221cb0ef41Sopenharmony_ci    return kHeaderSize + kInObjectFieldCount * kTaggedSize;
2231cb0ef41Sopenharmony_ci  }
2241cb0ef41Sopenharmony_ci
2251cb0ef41Sopenharmony_ci  // Descriptor array index to important methods in the prototype.
2261cb0ef41Sopenharmony_ci  static constexpr int kExecFunctionDescriptorIndex = 1;
2271cb0ef41Sopenharmony_ci  static constexpr int kSymbolMatchFunctionDescriptorIndex = 14;
2281cb0ef41Sopenharmony_ci  static constexpr int kSymbolMatchAllFunctionDescriptorIndex = 15;
2291cb0ef41Sopenharmony_ci  static constexpr int kSymbolReplaceFunctionDescriptorIndex = 16;
2301cb0ef41Sopenharmony_ci  static constexpr int kSymbolSearchFunctionDescriptorIndex = 17;
2311cb0ef41Sopenharmony_ci  static constexpr int kSymbolSplitFunctionDescriptorIndex = 18;
2321cb0ef41Sopenharmony_ci
2331cb0ef41Sopenharmony_ci  // The uninitialized value for a regexp code object.
2341cb0ef41Sopenharmony_ci  static constexpr int kUninitializedValue = -1;
2351cb0ef41Sopenharmony_ci
2361cb0ef41Sopenharmony_ci  // If the backtrack limit is set to this marker value, no limit is applied.
2371cb0ef41Sopenharmony_ci  static constexpr uint32_t kNoBacktrackLimit = 0;
2381cb0ef41Sopenharmony_ci
2391cb0ef41Sopenharmony_ci  // The heuristic value for the length of the subject string for which we
2401cb0ef41Sopenharmony_ci  // tier-up to the compiler immediately, instead of using the interpreter.
2411cb0ef41Sopenharmony_ci  static constexpr int kTierUpForSubjectLengthValue = 1000;
2421cb0ef41Sopenharmony_ci
2431cb0ef41Sopenharmony_ci  // Maximum number of captures allowed.
2441cb0ef41Sopenharmony_ci  static constexpr int kMaxCaptures = 1 << 16;
2451cb0ef41Sopenharmony_ci
2461cb0ef41Sopenharmony_ci private:
2471cb0ef41Sopenharmony_ci  inline Object DataAt(int index) const;
2481cb0ef41Sopenharmony_ci  inline void SetDataAt(int index, Object value);
2491cb0ef41Sopenharmony_ci
2501cb0ef41Sopenharmony_ci  TQ_OBJECT_CONSTRUCTORS(JSRegExp)
2511cb0ef41Sopenharmony_ci};
2521cb0ef41Sopenharmony_ci
2531cb0ef41Sopenharmony_ciDEFINE_OPERATORS_FOR_FLAGS(JSRegExp::Flags)
2541cb0ef41Sopenharmony_ci
2551cb0ef41Sopenharmony_ci// JSRegExpResult is just a JSArray with a specific initial map.
2561cb0ef41Sopenharmony_ci// This initial map adds in-object properties for "index" and "input"
2571cb0ef41Sopenharmony_ci// properties, as assigned by RegExp.prototype.exec, which allows
2581cb0ef41Sopenharmony_ci// faster creation of RegExp exec results.
2591cb0ef41Sopenharmony_ci// This class just holds constants used when creating the result.
2601cb0ef41Sopenharmony_ci// After creation the result must be treated as a JSArray in all regards.
2611cb0ef41Sopenharmony_ciclass JSRegExpResult
2621cb0ef41Sopenharmony_ci    : public TorqueGeneratedJSRegExpResult<JSRegExpResult, JSArray> {
2631cb0ef41Sopenharmony_ci public:
2641cb0ef41Sopenharmony_ci  // TODO(joshualitt): We would like to add printers and verifiers to
2651cb0ef41Sopenharmony_ci  // JSRegExpResult, and maybe JSRegExpResultIndices, but both have the same
2661cb0ef41Sopenharmony_ci  // instance type as JSArray.
2671cb0ef41Sopenharmony_ci
2681cb0ef41Sopenharmony_ci  // Indices of in-object properties.
2691cb0ef41Sopenharmony_ci  static constexpr int kIndexIndex = 0;
2701cb0ef41Sopenharmony_ci  static constexpr int kInputIndex = 1;
2711cb0ef41Sopenharmony_ci  static constexpr int kGroupsIndex = 2;
2721cb0ef41Sopenharmony_ci
2731cb0ef41Sopenharmony_ci  // Private internal only fields.
2741cb0ef41Sopenharmony_ci  static constexpr int kNamesIndex = 3;
2751cb0ef41Sopenharmony_ci  static constexpr int kRegExpInputIndex = 4;
2761cb0ef41Sopenharmony_ci  static constexpr int kRegExpLastIndex = 5;
2771cb0ef41Sopenharmony_ci  static constexpr int kInObjectPropertyCount = 6;
2781cb0ef41Sopenharmony_ci
2791cb0ef41Sopenharmony_ci  static constexpr int kMapIndexInContext = Context::REGEXP_RESULT_MAP_INDEX;
2801cb0ef41Sopenharmony_ci
2811cb0ef41Sopenharmony_ci  TQ_OBJECT_CONSTRUCTORS(JSRegExpResult)
2821cb0ef41Sopenharmony_ci};
2831cb0ef41Sopenharmony_ci
2841cb0ef41Sopenharmony_ciclass JSRegExpResultWithIndices
2851cb0ef41Sopenharmony_ci    : public TorqueGeneratedJSRegExpResultWithIndices<JSRegExpResultWithIndices,
2861cb0ef41Sopenharmony_ci                                                      JSRegExpResult> {
2871cb0ef41Sopenharmony_ci public:
2881cb0ef41Sopenharmony_ci  static_assert(
2891cb0ef41Sopenharmony_ci      JSRegExpResult::kInObjectPropertyCount == 6,
2901cb0ef41Sopenharmony_ci      "JSRegExpResultWithIndices must be a subclass of JSRegExpResult");
2911cb0ef41Sopenharmony_ci  static constexpr int kIndicesIndex = 6;
2921cb0ef41Sopenharmony_ci  static constexpr int kInObjectPropertyCount = 7;
2931cb0ef41Sopenharmony_ci
2941cb0ef41Sopenharmony_ci  TQ_OBJECT_CONSTRUCTORS(JSRegExpResultWithIndices)
2951cb0ef41Sopenharmony_ci};
2961cb0ef41Sopenharmony_ci
2971cb0ef41Sopenharmony_ci// JSRegExpResultIndices is just a JSArray with a specific initial map.
2981cb0ef41Sopenharmony_ci// This initial map adds in-object properties for "group"
2991cb0ef41Sopenharmony_ci// properties, as assigned by RegExp.prototype.exec, which allows
3001cb0ef41Sopenharmony_ci// faster creation of RegExp exec results.
3011cb0ef41Sopenharmony_ci// This class just holds constants used when creating the result.
3021cb0ef41Sopenharmony_ci// After creation the result must be treated as a JSArray in all regards.
3031cb0ef41Sopenharmony_ciclass JSRegExpResultIndices
3041cb0ef41Sopenharmony_ci    : public TorqueGeneratedJSRegExpResultIndices<JSRegExpResultIndices,
3051cb0ef41Sopenharmony_ci                                                  JSArray> {
3061cb0ef41Sopenharmony_ci public:
3071cb0ef41Sopenharmony_ci  static Handle<JSRegExpResultIndices> BuildIndices(
3081cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<RegExpMatchInfo> match_info,
3091cb0ef41Sopenharmony_ci      Handle<Object> maybe_names);
3101cb0ef41Sopenharmony_ci
3111cb0ef41Sopenharmony_ci  // Indices of in-object properties.
3121cb0ef41Sopenharmony_ci  static constexpr int kGroupsIndex = 0;
3131cb0ef41Sopenharmony_ci  static constexpr int kInObjectPropertyCount = 1;
3141cb0ef41Sopenharmony_ci
3151cb0ef41Sopenharmony_ci  // Descriptor index of groups.
3161cb0ef41Sopenharmony_ci  static constexpr int kGroupsDescriptorIndex = 1;
3171cb0ef41Sopenharmony_ci
3181cb0ef41Sopenharmony_ci  TQ_OBJECT_CONSTRUCTORS(JSRegExpResultIndices)
3191cb0ef41Sopenharmony_ci};
3201cb0ef41Sopenharmony_ci
3211cb0ef41Sopenharmony_ci}  // namespace internal
3221cb0ef41Sopenharmony_ci}  // namespace v8
3231cb0ef41Sopenharmony_ci
3241cb0ef41Sopenharmony_ci#include "src/objects/object-macros-undef.h"
3251cb0ef41Sopenharmony_ci
3261cb0ef41Sopenharmony_ci#endif  // V8_OBJECTS_JS_REGEXP_H_
327