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 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 #include "torque-generated/src/objects/regexp-match-info-tq.inc" 22 23 // The property RegExpMatchInfo includes the matchIndices 24 // array of the last successful regexp match (an array of start/end index 25 // pairs for the match and all the captured substrings), the invariant is 26 // that there are at least two capture indices. The array also contains 27 // the subject string for the last successful match. 28 // After creation the result must be treated as a FixedArray in all regards. 29 class RegExpMatchInfo 30 : public TorqueGeneratedRegExpMatchInfo<RegExpMatchInfo, 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 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); 42 43 // Like LastSubject, but modifiable by the user. 44 inline Object LastInput(); 45 inline void SetLastInput(Object value, 46 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); 47 48 // Returns the i'th capture index, 0 <= i < NumberOfCaptures(). Capture(0) and 49 // Capture(1) determine the start- and endpoint of the match itself. 50 inline int Capture(int i); 51 inline void SetCapture(int i, int value); 52 53 // Creates a new RegExpMatchInfo with space for capture_count captures. 54 static Handle<RegExpMatchInfo> New(Isolate* isolate, int capture_count); 55 56 // Reserves space for captures. 57 static Handle<RegExpMatchInfo> ReserveCaptures( 58 Isolate* isolate, Handle<RegExpMatchInfo> match_info, int capture_count); 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 // Every match info is guaranteed to have enough space to store two captures. 67 static const int kInitialCaptureIndices = 2; 68 69 TQ_OBJECT_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