V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
templates-inl.h
1 // Copyright 2018 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_TEMPLATES_INL_H_
6 #define V8_OBJECTS_TEMPLATES_INL_H_
7 
8 #include "src/objects/templates.h"
9 
10 #include "src/heap/heap-inl.h"
11 #include "src/objects/shared-function-info-inl.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 ACCESSORS(TemplateInfo, tag, Object, kTagOffset)
20 ACCESSORS(TemplateInfo, serial_number, Object, kSerialNumberOffset)
21 SMI_ACCESSORS(TemplateInfo, number_of_properties, kNumberOfProperties)
22 ACCESSORS(TemplateInfo, property_list, Object, kPropertyListOffset)
23 ACCESSORS(TemplateInfo, property_accessors, Object, kPropertyAccessorsOffset)
24 
25 ACCESSORS(FunctionTemplateInfo, call_code, Object, kCallCodeOffset)
26 ACCESSORS(FunctionTemplateInfo, class_name, Object, kClassNameOffset)
27 ACCESSORS(FunctionTemplateInfo, signature, Object, kSignatureOffset)
28 ACCESSORS(FunctionTemplateInfo, shared_function_info, Object,
29  kSharedFunctionInfoOffset)
30 ACCESSORS(FunctionTemplateInfo, rare_data, HeapObject,
31  kFunctionTemplateRareDataOffset)
32 ACCESSORS(FunctionTemplateInfo, cached_property_name, Object,
33  kCachedPropertyNameOffset)
34 SMI_ACCESSORS(FunctionTemplateInfo, length, kLengthOffset)
35 BOOL_ACCESSORS(FunctionTemplateInfo, flag, hidden_prototype,
36  kHiddenPrototypeBit)
37 BOOL_ACCESSORS(FunctionTemplateInfo, flag, undetectable, kUndetectableBit)
38 BOOL_ACCESSORS(FunctionTemplateInfo, flag, needs_access_check,
39  kNeedsAccessCheckBit)
40 BOOL_ACCESSORS(FunctionTemplateInfo, flag, read_only_prototype,
41  kReadOnlyPrototypeBit)
42 BOOL_ACCESSORS(FunctionTemplateInfo, flag, remove_prototype,
43  kRemovePrototypeBit)
44 BOOL_ACCESSORS(FunctionTemplateInfo, flag, do_not_cache, kDoNotCacheBit)
45 BOOL_ACCESSORS(FunctionTemplateInfo, flag, accept_any_receiver,
46  kAcceptAnyReceiver)
47 SMI_ACCESSORS(FunctionTemplateInfo, flag, kFlagOffset)
48 
49 // static
50 FunctionTemplateRareData* FunctionTemplateInfo::EnsureFunctionTemplateRareData(
51  Isolate* isolate, Handle<FunctionTemplateInfo> function_template_info) {
52  HeapObject* extra = function_template_info->rare_data();
53  if (extra->IsUndefined(isolate)) {
54  return AllocateFunctionTemplateRareData(isolate, function_template_info);
55  } else {
56  return FunctionTemplateRareData::cast(extra);
57  }
58 }
59 
60 #define RARE_ACCESSORS(Name, CamelName, Type) \
61  Type* FunctionTemplateInfo::Get##CamelName() { \
62  HeapObject* extra = rare_data(); \
63  HeapObject* undefined = GetReadOnlyRoots().undefined_value(); \
64  return extra == undefined ? undefined \
65  : FunctionTemplateRareData::cast(extra)->Name(); \
66  } \
67  inline void FunctionTemplateInfo::Set##CamelName( \
68  Isolate* isolate, Handle<FunctionTemplateInfo> function_template_info, \
69  Handle<Type> Name) { \
70  FunctionTemplateRareData* rare_data = \
71  EnsureFunctionTemplateRareData(isolate, function_template_info); \
72  rare_data->set_##Name(*Name); \
73  }
74 
75 RARE_ACCESSORS(prototype_template, PrototypeTemplate, Object)
76 RARE_ACCESSORS(prototype_provider_template, PrototypeProviderTemplate, Object)
77 RARE_ACCESSORS(parent_template, ParentTemplate, Object)
78 RARE_ACCESSORS(named_property_handler, NamedPropertyHandler, Object)
79 RARE_ACCESSORS(indexed_property_handler, IndexedPropertyHandler, Object)
80 RARE_ACCESSORS(instance_template, InstanceTemplate, Object)
81 RARE_ACCESSORS(instance_call_handler, InstanceCallHandler, Object)
82 RARE_ACCESSORS(access_check_info, AccessCheckInfo, Object)
83 #undef RARE_ACCESSORS
84 
85 ACCESSORS(FunctionTemplateRareData, prototype_template, Object,
86  kPrototypeTemplateOffset)
87 ACCESSORS(FunctionTemplateRareData, prototype_provider_template, Object,
88  kPrototypeProviderTemplateOffset)
89 ACCESSORS(FunctionTemplateRareData, parent_template, Object,
90  kParentTemplateOffset)
91 ACCESSORS(FunctionTemplateRareData, named_property_handler, Object,
92  kNamedPropertyHandlerOffset)
93 ACCESSORS(FunctionTemplateRareData, indexed_property_handler, Object,
94  kIndexedPropertyHandlerOffset)
95 ACCESSORS(FunctionTemplateRareData, instance_template, Object,
96  kInstanceTemplateOffset)
97 ACCESSORS(FunctionTemplateRareData, instance_call_handler, Object,
98  kInstanceCallHandlerOffset)
99 ACCESSORS(FunctionTemplateRareData, access_check_info, Object,
100  kAccessCheckInfoOffset)
101 
102 ACCESSORS(ObjectTemplateInfo, constructor, Object, kConstructorOffset)
103 ACCESSORS(ObjectTemplateInfo, data, Object, kDataOffset)
104 
105 CAST_ACCESSOR(TemplateInfo)
106 CAST_ACCESSOR(FunctionTemplateInfo)
107 CAST_ACCESSOR(FunctionTemplateRareData)
108 CAST_ACCESSOR(ObjectTemplateInfo)
109 
110 bool FunctionTemplateInfo::instantiated() {
111  return shared_function_info()->IsSharedFunctionInfo();
112 }
113 
114 bool FunctionTemplateInfo::BreakAtEntry() {
115  Object* maybe_shared = shared_function_info();
116  if (maybe_shared->IsSharedFunctionInfo()) {
117  SharedFunctionInfo* shared = SharedFunctionInfo::cast(maybe_shared);
118  return shared->BreakAtEntry();
119  }
120  return false;
121 }
122 
123 FunctionTemplateInfo* FunctionTemplateInfo::GetParent(Isolate* isolate) {
124  Object* parent = GetParentTemplate();
125  return parent->IsUndefined(isolate) ? nullptr
126  : FunctionTemplateInfo::cast(parent);
127 }
128 
129 ObjectTemplateInfo* ObjectTemplateInfo::GetParent(Isolate* isolate) {
130  Object* maybe_ctor = constructor();
131  if (maybe_ctor->IsUndefined(isolate)) return nullptr;
132  FunctionTemplateInfo* constructor = FunctionTemplateInfo::cast(maybe_ctor);
133  while (true) {
134  constructor = constructor->GetParent(isolate);
135  if (constructor == nullptr) return nullptr;
136  Object* maybe_obj = constructor->GetInstanceTemplate();
137  if (!maybe_obj->IsUndefined(isolate)) {
138  return ObjectTemplateInfo::cast(maybe_obj);
139  }
140  }
141  return nullptr;
142 }
143 
144 int ObjectTemplateInfo::embedder_field_count() const {
145  Object* value = data();
146  DCHECK(value->IsSmi());
147  return EmbedderFieldCount::decode(Smi::ToInt(value));
148 }
149 
150 void ObjectTemplateInfo::set_embedder_field_count(int count) {
151  DCHECK_LE(count, JSObject::kMaxEmbedderFields);
152  return set_data(
153  Smi::FromInt(EmbedderFieldCount::update(Smi::ToInt(data()), count)));
154 }
155 
156 bool ObjectTemplateInfo::immutable_proto() const {
157  Object* value = data();
158  DCHECK(value->IsSmi());
159  return IsImmutablePrototype::decode(Smi::ToInt(value));
160 }
161 
162 void ObjectTemplateInfo::set_immutable_proto(bool immutable) {
163  return set_data(Smi::FromInt(
164  IsImmutablePrototype::update(Smi::ToInt(data()), immutable)));
165 }
166 
167 bool FunctionTemplateInfo::IsTemplateFor(JSObject* object) {
168  return IsTemplateFor(object->map());
169 }
170 
171 } // namespace internal
172 } // namespace v8
173 
174 #include "src/objects/object-macros-undef.h"
175 
176 #endif // V8_OBJECTS_TEMPLATES_INL_H_
Definition: libplatform.h:13