• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.h"
10 #include "src/objects/fixed-array.h"
11 
12 // Has to be the last include (doesn't have include guards):
13 #include "src/objects/object-macros.h"
14 
15 namespace v8 {
16 namespace internal {
17 
18 class Object;
19 class String;
20 
21 // The property RegExpMatchInfo includes the matchIndices
22 // array of the last successful regexp match (an array of start/end index
23 // pairs for the match and all the captured substrings), the invariant is
24 // that there are at least two capture indices.  The array also contains
25 // the subject string for the last successful match.
26 // After creation the result must be treated as a FixedArray in all regards.
NON_EXPORTED_BASE(public FixedArray)27 class V8_EXPORT_PRIVATE RegExpMatchInfo : NON_EXPORTED_BASE(public FixedArray) {
28  public:
29   // Returns the number of captures, which is defined as the length of the
30   // matchIndices objects of the last match. matchIndices contains two indices
31   // for each capture (including the match itself), i.e. 2 * #captures + 2.
32   inline int NumberOfCaptureRegisters();
33   inline void SetNumberOfCaptureRegisters(int value);
34 
35   // Returns the subject string of the last match.
36   inline String* LastSubject();
37   inline void SetLastSubject(String* value);
38 
39   // Like LastSubject, but modifiable by the user.
40   inline Object* LastInput();
41   inline void SetLastInput(Object* value);
42 
43   // Returns the i'th capture index, 0 <= i < NumberOfCaptures(). Capture(0) and
44   // Capture(1) determine the start- and endpoint of the match itself.
45   inline int Capture(int i);
46   inline void SetCapture(int i, int value);
47 
48   // Reserves space for captures.
49   static Handle<RegExpMatchInfo> ReserveCaptures(
50       Isolate* isolate, Handle<RegExpMatchInfo> match_info, int capture_count);
51 
52   DECL_CAST(RegExpMatchInfo)
53 
54   static const int kNumberOfCapturesIndex = 0;
55   static const int kLastSubjectIndex = 1;
56   static const int kLastInputIndex = 2;
57   static const int kFirstCaptureIndex = 3;
58   static const int kLastMatchOverhead = kFirstCaptureIndex;
59 
60   static const int kNumberOfCapturesOffset = FixedArray::kHeaderSize;
61   static const int kLastSubjectOffset = kNumberOfCapturesOffset + kPointerSize;
62   static const int kLastInputOffset = kLastSubjectOffset + kPointerSize;
63   static const int kFirstCaptureOffset = kLastInputOffset + kPointerSize;
64 
65   // Every match info is guaranteed to have enough space to store two captures.
66   static const int kInitialCaptureIndices = 2;
67 
68  private:
69   DISALLOW_IMPLICIT_CONSTRUCTORS(RegExpMatchInfo);
70 };
71 
72 }  // namespace internal
73 }  // namespace v8
74 
75 #include "src/objects/object-macros-undef.h"
76 
77 #endif  // V8_OBJECTS_REGEXP_MATCH_INFO_H_
78