5 #ifndef V8_OBJECTS_TEMPLATES_INL_H_ 6 #define V8_OBJECTS_TEMPLATES_INL_H_ 8 #include "src/objects/templates.h" 10 #include "src/heap/heap-inl.h" 11 #include "src/objects/shared-function-info-inl.h" 14 #include "src/objects/object-macros.h" 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)
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,
37 BOOL_ACCESSORS(FunctionTemplateInfo, flag, undetectable, kUndetectableBit)
38 BOOL_ACCESSORS(FunctionTemplateInfo, flag, needs_access_check,
40 BOOL_ACCESSORS(FunctionTemplateInfo, flag, read_only_prototype,
41 kReadOnlyPrototypeBit)
42 BOOL_ACCESSORS(FunctionTemplateInfo, flag, remove_prototype,
44 BOOL_ACCESSORS(FunctionTemplateInfo, flag, do_not_cache, kDoNotCacheBit)
45 BOOL_ACCESSORS(FunctionTemplateInfo, flag, accept_any_receiver,
47 SMI_ACCESSORS(FunctionTemplateInfo, flag, kFlagOffset)
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);
56 return FunctionTemplateRareData::cast(extra);
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(); \ 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); \ 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)
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)
102 ACCESSORS(ObjectTemplateInfo, constructor, Object, kConstructorOffset)
103 ACCESSORS(ObjectTemplateInfo, data, Object, kDataOffset)
105 CAST_ACCESSOR(TemplateInfo)
106 CAST_ACCESSOR(FunctionTemplateInfo)
107 CAST_ACCESSOR(FunctionTemplateRareData)
108 CAST_ACCESSOR(ObjectTemplateInfo)
110 bool FunctionTemplateInfo::instantiated() {
111 return shared_function_info()->IsSharedFunctionInfo();
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();
123 FunctionTemplateInfo* FunctionTemplateInfo::GetParent(Isolate* isolate) {
124 Object* parent = GetParentTemplate();
125 return parent->IsUndefined(isolate) ? nullptr
126 : FunctionTemplateInfo::cast(parent);
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);
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);
144 int ObjectTemplateInfo::embedder_field_count()
const {
145 Object* value = data();
146 DCHECK(value->IsSmi());
147 return EmbedderFieldCount::decode(Smi::ToInt(value));
150 void ObjectTemplateInfo::set_embedder_field_count(
int count) {
151 DCHECK_LE(count, JSObject::kMaxEmbedderFields);
153 Smi::FromInt(EmbedderFieldCount::update(Smi::ToInt(data()), count)));
156 bool ObjectTemplateInfo::immutable_proto()
const {
157 Object* value = data();
158 DCHECK(value->IsSmi());
159 return IsImmutablePrototype::decode(Smi::ToInt(value));
162 void ObjectTemplateInfo::set_immutable_proto(
bool immutable) {
163 return set_data(Smi::FromInt(
164 IsImmutablePrototype::update(Smi::ToInt(data()), immutable)));
167 bool FunctionTemplateInfo::IsTemplateFor(JSObject*
object) {
168 return IsTemplateFor(object->map());
174 #include "src/objects/object-macros-undef.h" 176 #endif // V8_OBJECTS_TEMPLATES_INL_H_