1 // Copyright 2017 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef V8_OBJECTS_REGEXP_MATCH_INFO_H_
6 #define V8_OBJECTS_REGEXP_MATCH_INFO_H_
7
8 #include "src/base/compiler-specific.h"
9 #include "src/objects/fixed-array.h"
10 #include "src/objects/objects.h"
11 #include "torque-generated/field-offsets.h"
12
13 // Has to be the last include (doesn't have include guards):
14 #include "src/objects/object-macros.h"
15
16 namespace v8 {
17 namespace internal {
18
19 class Object;
20 class String;
21
22 #include "torque-generated/src/objects/regexp-match-info-tq.inc"
23
24 // The property RegExpMatchInfo includes the matchIndices
25 // array of the last successful regexp match (an array of start/end index
26 // pairs for the match and all the captured substrings), the invariant is
27 // that there are at least two capture indices. The array also contains
28 // the subject string for the last successful match.
29 // After creation the result must be treated as a FixedArray in all regards.
NON_EXPORTED_BASE(public FixedArray)30 class V8_EXPORT_PRIVATE RegExpMatchInfo : NON_EXPORTED_BASE(public FixedArray) {
31 public:
32 // Returns the number of captures, which is defined as the length of the
33 // matchIndices objects of the last match. matchIndices contains two indices
34 // for each capture (including the match itself), i.e. 2 * #captures + 2.
35 inline int NumberOfCaptureRegisters();
36 inline void SetNumberOfCaptureRegisters(int value);
37
38 // Returns the subject string of the last match.
39 inline String LastSubject();
40 inline void SetLastSubject(String value);
41
42 // Like LastSubject, but modifiable by the user.
43 inline Object LastInput();
44 inline void SetLastInput(Object value);
45
46 // Returns the i'th capture index, 0 <= i < NumberOfCaptures(). Capture(0) and
47 // Capture(1) determine the start- and endpoint of the match itself.
48 inline int Capture(int i);
49 inline void SetCapture(int i, int value);
50
51 // Creates a new RegExpMatchInfo with space for capture_count captures.
52 static Handle<RegExpMatchInfo> New(Isolate* isolate, int capture_count);
53
54 // Reserves space for captures.
55 static Handle<RegExpMatchInfo> ReserveCaptures(
56 Isolate* isolate, Handle<RegExpMatchInfo> match_info, int capture_count);
57
58 DECL_CAST(RegExpMatchInfo)
59
60 static const int kNumberOfCapturesIndex = 0;
61 static const int kLastSubjectIndex = 1;
62 static const int kLastInputIndex = 2;
63 static const int kFirstCaptureIndex = 3;
64 static const int kLastMatchOverhead = kFirstCaptureIndex;
65
66 DEFINE_FIELD_OFFSET_CONSTANTS(FixedArray::kHeaderSize,
67 TORQUE_GENERATED_REG_EXP_MATCH_INFO_FIELDS)
68
69 // Every match info is guaranteed to have enough space to store two captures.
70 static const int kInitialCaptureIndices = 2;
71
72 OBJECT_CONSTRUCTORS(RegExpMatchInfo, FixedArray);
73 };
74
75 } // namespace internal
76 } // namespace v8
77
78 #include "src/objects/object-macros-undef.h"
79
80 #endif // V8_OBJECTS_REGEXP_MATCH_INFO_H_
81