V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
js-regexp-inl.h
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_JS_REGEXP_INL_H_
6 #define V8_OBJECTS_JS_REGEXP_INL_H_
7 
8 #include "src/objects/js-regexp.h"
9 
10 #include "src/objects-inl.h" // Needed for write barriers
11 #include "src/objects/smi.h"
12 #include "src/objects/string.h"
13 
14 // Has to be the last include (doesn't have include guards):
15 #include "src/objects/object-macros.h"
16 
17 namespace v8 {
18 namespace internal {
19 
20 CAST_ACCESSOR(JSRegExp)
21 
22 ACCESSORS(JSRegExp, data, Object, kDataOffset)
23 ACCESSORS(JSRegExp, flags, Object, kFlagsOffset)
24 ACCESSORS(JSRegExp, source, Object, kSourceOffset)
25 ACCESSORS(JSRegExp, last_index, Object, kLastIndexOffset)
26 
27 JSRegExp::Type JSRegExp::TypeTag() {
28  Object* data = this->data();
29  if (data->IsUndefined()) return JSRegExp::NOT_COMPILED;
30  Smi smi = Smi::cast(FixedArray::cast(data)->get(kTagIndex));
31  return static_cast<JSRegExp::Type>(smi->value());
32 }
33 
34 int JSRegExp::CaptureCount() {
35  switch (TypeTag()) {
36  case ATOM:
37  return 0;
38  case IRREGEXP:
39  return Smi::ToInt(DataAt(kIrregexpCaptureCountIndex));
40  default:
41  UNREACHABLE();
42  }
43 }
44 
45 JSRegExp::Flags JSRegExp::GetFlags() {
46  DCHECK(this->data()->IsFixedArray());
47  Object* data = this->data();
48  Smi smi = Smi::cast(FixedArray::cast(data)->get(kFlagsIndex));
49  return Flags(smi->value());
50 }
51 
52 String JSRegExp::Pattern() {
53  DCHECK(this->data()->IsFixedArray());
54  Object* data = this->data();
55  String pattern = String::cast(FixedArray::cast(data)->get(kSourceIndex));
56  return pattern;
57 }
58 
59 Object* JSRegExp::CaptureNameMap() {
60  DCHECK(this->data()->IsFixedArray());
61  DCHECK_EQ(TypeTag(), IRREGEXP);
62  Object* value = DataAt(kIrregexpCaptureNameMapIndex);
63  DCHECK_NE(value, Smi::FromInt(JSRegExp::kUninitializedValue));
64  return value;
65 }
66 
67 Object* JSRegExp::DataAt(int index) {
68  DCHECK(TypeTag() != NOT_COMPILED);
69  return FixedArray::cast(data())->get(index);
70 }
71 
72 void JSRegExp::SetDataAt(int index, Object* value) {
73  DCHECK(TypeTag() != NOT_COMPILED);
74  DCHECK_GE(index,
75  kDataIndex); // Only implementation data can be set this way.
76  FixedArray::cast(data())->set(index, value);
77 }
78 
79 } // namespace internal
80 } // namespace v8
81 
82 #include "src/objects/object-macros-undef.h"
83 
84 #endif // V8_OBJECTS_JS_REGEXP_INL_H_
Definition: libplatform.h:13