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
ACCESSORS(TemplateInfo,tag,Object,kTagOffset)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, prototype_template, Object,
27 kPrototypeTemplateOffset)
28 ACCESSORS(FunctionTemplateInfo, prototype_provider_template, Object,
29 kPrototypeProviderTemplateOffset)
30 ACCESSORS(FunctionTemplateInfo, parent_template, Object, kParentTemplateOffset)
31 ACCESSORS(FunctionTemplateInfo, named_property_handler, Object,
32 kNamedPropertyHandlerOffset)
33 ACCESSORS(FunctionTemplateInfo, indexed_property_handler, Object,
34 kIndexedPropertyHandlerOffset)
35 ACCESSORS(FunctionTemplateInfo, instance_template, Object,
36 kInstanceTemplateOffset)
37 ACCESSORS(FunctionTemplateInfo, class_name, Object, kClassNameOffset)
38 ACCESSORS(FunctionTemplateInfo, signature, Object, kSignatureOffset)
39 ACCESSORS(FunctionTemplateInfo, instance_call_handler, Object,
40 kInstanceCallHandlerOffset)
41 ACCESSORS(FunctionTemplateInfo, access_check_info, Object,
42 kAccessCheckInfoOffset)
43 ACCESSORS(FunctionTemplateInfo, shared_function_info, Object,
44 kSharedFunctionInfoOffset)
45 ACCESSORS(FunctionTemplateInfo, cached_property_name, Object,
46 kCachedPropertyNameOffset)
47 SMI_ACCESSORS(FunctionTemplateInfo, length, kLengthOffset)
48 BOOL_ACCESSORS(FunctionTemplateInfo, flag, hidden_prototype,
49 kHiddenPrototypeBit)
50 BOOL_ACCESSORS(FunctionTemplateInfo, flag, undetectable, kUndetectableBit)
51 BOOL_ACCESSORS(FunctionTemplateInfo, flag, needs_access_check,
52 kNeedsAccessCheckBit)
53 BOOL_ACCESSORS(FunctionTemplateInfo, flag, read_only_prototype,
54 kReadOnlyPrototypeBit)
55 BOOL_ACCESSORS(FunctionTemplateInfo, flag, remove_prototype,
56 kRemovePrototypeBit)
57 BOOL_ACCESSORS(FunctionTemplateInfo, flag, do_not_cache, kDoNotCacheBit)
58 BOOL_ACCESSORS(FunctionTemplateInfo, flag, accept_any_receiver,
59 kAcceptAnyReceiver)
60 SMI_ACCESSORS(FunctionTemplateInfo, flag, kFlagOffset)
61
62 ACCESSORS(ObjectTemplateInfo, constructor, Object, kConstructorOffset)
63 ACCESSORS(ObjectTemplateInfo, data, Object, kDataOffset)
64
65 CAST_ACCESSOR(TemplateInfo)
66 CAST_ACCESSOR(FunctionTemplateInfo)
67 CAST_ACCESSOR(ObjectTemplateInfo)
68
69 bool FunctionTemplateInfo::instantiated() {
70 return shared_function_info()->IsSharedFunctionInfo();
71 }
72
BreakAtEntry()73 bool FunctionTemplateInfo::BreakAtEntry() {
74 Object* maybe_shared = shared_function_info();
75 if (maybe_shared->IsSharedFunctionInfo()) {
76 SharedFunctionInfo* shared = SharedFunctionInfo::cast(maybe_shared);
77 return shared->BreakAtEntry();
78 }
79 return false;
80 }
81
GetParent(Isolate * isolate)82 FunctionTemplateInfo* FunctionTemplateInfo::GetParent(Isolate* isolate) {
83 Object* parent = parent_template();
84 return parent->IsUndefined(isolate) ? nullptr
85 : FunctionTemplateInfo::cast(parent);
86 }
87
GetParent(Isolate * isolate)88 ObjectTemplateInfo* ObjectTemplateInfo::GetParent(Isolate* isolate) {
89 Object* maybe_ctor = constructor();
90 if (maybe_ctor->IsUndefined(isolate)) return nullptr;
91 FunctionTemplateInfo* constructor = FunctionTemplateInfo::cast(maybe_ctor);
92 while (true) {
93 constructor = constructor->GetParent(isolate);
94 if (constructor == nullptr) return nullptr;
95 Object* maybe_obj = constructor->instance_template();
96 if (!maybe_obj->IsUndefined(isolate)) {
97 return ObjectTemplateInfo::cast(maybe_obj);
98 }
99 }
100 return nullptr;
101 }
102
embedder_field_count()103 int ObjectTemplateInfo::embedder_field_count() const {
104 Object* value = data();
105 DCHECK(value->IsSmi());
106 return EmbedderFieldCount::decode(Smi::ToInt(value));
107 }
108
set_embedder_field_count(int count)109 void ObjectTemplateInfo::set_embedder_field_count(int count) {
110 DCHECK_LE(count, JSObject::kMaxEmbedderFields);
111 return set_data(
112 Smi::FromInt(EmbedderFieldCount::update(Smi::ToInt(data()), count)));
113 }
114
immutable_proto()115 bool ObjectTemplateInfo::immutable_proto() const {
116 Object* value = data();
117 DCHECK(value->IsSmi());
118 return IsImmutablePrototype::decode(Smi::ToInt(value));
119 }
120
set_immutable_proto(bool immutable)121 void ObjectTemplateInfo::set_immutable_proto(bool immutable) {
122 return set_data(Smi::FromInt(
123 IsImmutablePrototype::update(Smi::ToInt(data()), immutable)));
124 }
125
IsTemplateFor(JSObject * object)126 bool FunctionTemplateInfo::IsTemplateFor(JSObject* object) {
127 return IsTemplateFor(object->map());
128 }
129
130 } // namespace internal
131 } // namespace v8
132
133 #include "src/objects/object-macros-undef.h"
134
135 #endif // V8_OBJECTS_TEMPLATES_INL_H_
136