1 // Copyright 2021 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_INL_H_
6 #define V8_OBJECTS_REGEXP_MATCH_INFO_INL_H_
7
8 #include "src/objects/fixed-array-inl.h"
9 #include "src/objects/regexp-match-info.h"
10
11 // Has to be the last include (doesn't have include guards):
12 #include "src/objects/object-macros.h"
13
14 namespace v8 {
15 namespace internal {
16
17 #include "torque-generated/src/objects/regexp-match-info-tq-inl.inc"
18
TQ_OBJECT_CONSTRUCTORS_IMPL(RegExpMatchInfo)19 TQ_OBJECT_CONSTRUCTORS_IMPL(RegExpMatchInfo)
20
21 int RegExpMatchInfo::NumberOfCaptureRegisters() {
22 DCHECK_GE(length(), kLastMatchOverhead);
23 Object obj = get(kNumberOfCapturesIndex);
24 return Smi::ToInt(obj);
25 }
26
SetNumberOfCaptureRegisters(int value)27 void RegExpMatchInfo::SetNumberOfCaptureRegisters(int value) {
28 DCHECK_GE(length(), kLastMatchOverhead);
29 set(kNumberOfCapturesIndex, Smi::FromInt(value));
30 }
31
LastSubject()32 String RegExpMatchInfo::LastSubject() {
33 DCHECK_GE(length(), kLastMatchOverhead);
34 return String::cast(get(kLastSubjectIndex));
35 }
36
SetLastSubject(String value,WriteBarrierMode mode)37 void RegExpMatchInfo::SetLastSubject(String value, WriteBarrierMode mode) {
38 DCHECK_GE(length(), kLastMatchOverhead);
39 set(kLastSubjectIndex, value, mode);
40 }
41
LastInput()42 Object RegExpMatchInfo::LastInput() {
43 DCHECK_GE(length(), kLastMatchOverhead);
44 return get(kLastInputIndex);
45 }
46
SetLastInput(Object value,WriteBarrierMode mode)47 void RegExpMatchInfo::SetLastInput(Object value, WriteBarrierMode mode) {
48 DCHECK_GE(length(), kLastMatchOverhead);
49 set(kLastInputIndex, value, mode);
50 }
51
Capture(int i)52 int RegExpMatchInfo::Capture(int i) {
53 DCHECK_LT(i, NumberOfCaptureRegisters());
54 Object obj = get(kFirstCaptureIndex + i);
55 return Smi::ToInt(obj);
56 }
57
SetCapture(int i,int value)58 void RegExpMatchInfo::SetCapture(int i, int value) {
59 DCHECK_LT(i, NumberOfCaptureRegisters());
60 set(kFirstCaptureIndex + i, Smi::FromInt(value));
61 }
62
63 } // namespace internal
64 } // namespace v8
65
66 #include "src/objects/object-macros-undef.h"
67
68 #endif // V8_OBJECTS_REGEXP_MATCH_INFO_INL_H_
69