1 // Copyright 2016 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_IC_HANDLER_CONFIGURATION_INL_H_
6 #define V8_IC_HANDLER_CONFIGURATION_INL_H_
7
8 #include "src/ic/handler-configuration.h"
9
10 #include "src/handles/handles-inl.h"
11 #include "src/objects/data-handler-inl.h"
12 #include "src/objects/field-index-inl.h"
13 #include "src/objects/objects-inl.h"
14 #include "src/objects/smi.h"
15
16 // Has to be the last include (doesn't have include guards):
17 #include "src/objects/object-macros.h"
18
19 namespace v8 {
20 namespace internal {
21
OBJECT_CONSTRUCTORS_IMPL(LoadHandler,DataHandler)22 OBJECT_CONSTRUCTORS_IMPL(LoadHandler, DataHandler)
23
24 CAST_ACCESSOR(LoadHandler)
25
26 // Decodes kind from Smi-handler.
27 LoadHandler::Kind LoadHandler::GetHandlerKind(Smi smi_handler) {
28 return KindBits::decode(smi_handler.value());
29 }
30
LoadNormal(Isolate * isolate)31 Handle<Smi> LoadHandler::LoadNormal(Isolate* isolate) {
32 int config = KindBits::encode(kNormal);
33 return handle(Smi::FromInt(config), isolate);
34 }
35
LoadGlobal(Isolate * isolate)36 Handle<Smi> LoadHandler::LoadGlobal(Isolate* isolate) {
37 int config = KindBits::encode(kGlobal);
38 return handle(Smi::FromInt(config), isolate);
39 }
40
LoadInterceptor(Isolate * isolate)41 Handle<Smi> LoadHandler::LoadInterceptor(Isolate* isolate) {
42 int config = KindBits::encode(kInterceptor);
43 return handle(Smi::FromInt(config), isolate);
44 }
45
LoadSlow(Isolate * isolate)46 Handle<Smi> LoadHandler::LoadSlow(Isolate* isolate) {
47 int config = KindBits::encode(kSlow);
48 return handle(Smi::FromInt(config), isolate);
49 }
50
LoadField(Isolate * isolate,FieldIndex field_index)51 Handle<Smi> LoadHandler::LoadField(Isolate* isolate, FieldIndex field_index) {
52 int config = KindBits::encode(kField) |
53 IsInobjectBits::encode(field_index.is_inobject()) |
54 IsDoubleBits::encode(field_index.is_double()) |
55 FieldIndexBits::encode(field_index.index());
56 return handle(Smi::FromInt(config), isolate);
57 }
58
LoadConstantFromPrototype(Isolate * isolate)59 Handle<Smi> LoadHandler::LoadConstantFromPrototype(Isolate* isolate) {
60 int config = KindBits::encode(kConstantFromPrototype);
61 return handle(Smi::FromInt(config), isolate);
62 }
63
LoadAccessor(Isolate * isolate,int descriptor)64 Handle<Smi> LoadHandler::LoadAccessor(Isolate* isolate, int descriptor) {
65 int config = KindBits::encode(kAccessor) | DescriptorBits::encode(descriptor);
66 return handle(Smi::FromInt(config), isolate);
67 }
68
LoadProxy(Isolate * isolate)69 Handle<Smi> LoadHandler::LoadProxy(Isolate* isolate) {
70 int config = KindBits::encode(kProxy);
71 return handle(Smi::FromInt(config), isolate);
72 }
73
LoadNativeDataProperty(Isolate * isolate,int descriptor)74 Handle<Smi> LoadHandler::LoadNativeDataProperty(Isolate* isolate,
75 int descriptor) {
76 int config = KindBits::encode(kNativeDataProperty) |
77 DescriptorBits::encode(descriptor);
78 return handle(Smi::FromInt(config), isolate);
79 }
80
LoadApiGetter(Isolate * isolate,bool holder_is_receiver)81 Handle<Smi> LoadHandler::LoadApiGetter(Isolate* isolate,
82 bool holder_is_receiver) {
83 int config = KindBits::encode(
84 holder_is_receiver ? kApiGetter : kApiGetterHolderIsPrototype);
85 return handle(Smi::FromInt(config), isolate);
86 }
87
LoadModuleExport(Isolate * isolate,int index)88 Handle<Smi> LoadHandler::LoadModuleExport(Isolate* isolate, int index) {
89 int config =
90 KindBits::encode(kModuleExport) | ExportsIndexBits::encode(index);
91 return handle(Smi::FromInt(config), isolate);
92 }
93
LoadNonExistent(Isolate * isolate)94 Handle<Smi> LoadHandler::LoadNonExistent(Isolate* isolate) {
95 int config = KindBits::encode(kNonExistent);
96 return handle(Smi::FromInt(config), isolate);
97 }
98
LoadElement(Isolate * isolate,ElementsKind elements_kind,bool convert_hole_to_undefined,bool is_js_array,KeyedAccessLoadMode load_mode)99 Handle<Smi> LoadHandler::LoadElement(Isolate* isolate,
100 ElementsKind elements_kind,
101 bool convert_hole_to_undefined,
102 bool is_js_array,
103 KeyedAccessLoadMode load_mode) {
104 int config =
105 KindBits::encode(kElement) |
106 AllowOutOfBoundsBits::encode(load_mode == LOAD_IGNORE_OUT_OF_BOUNDS) |
107 ElementsKindBits::encode(elements_kind) |
108 ConvertHoleBits::encode(convert_hole_to_undefined) |
109 IsJsArrayBits::encode(is_js_array);
110 return handle(Smi::FromInt(config), isolate);
111 }
112
LoadIndexedString(Isolate * isolate,KeyedAccessLoadMode load_mode)113 Handle<Smi> LoadHandler::LoadIndexedString(Isolate* isolate,
114 KeyedAccessLoadMode load_mode) {
115 int config =
116 KindBits::encode(kIndexedString) |
117 AllowOutOfBoundsBits::encode(load_mode == LOAD_IGNORE_OUT_OF_BOUNDS);
118 return handle(Smi::FromInt(config), isolate);
119 }
120
OBJECT_CONSTRUCTORS_IMPL(StoreHandler,DataHandler)121 OBJECT_CONSTRUCTORS_IMPL(StoreHandler, DataHandler)
122
123 CAST_ACCESSOR(StoreHandler)
124
125 Handle<Smi> StoreHandler::StoreGlobalProxy(Isolate* isolate) {
126 int config = KindBits::encode(kGlobalProxy);
127 return handle(Smi::FromInt(config), isolate);
128 }
129
StoreNormal(Isolate * isolate)130 Handle<Smi> StoreHandler::StoreNormal(Isolate* isolate) {
131 int config = KindBits::encode(kNormal);
132 return handle(Smi::FromInt(config), isolate);
133 }
134
StoreInterceptor(Isolate * isolate)135 Handle<Smi> StoreHandler::StoreInterceptor(Isolate* isolate) {
136 int config = KindBits::encode(kInterceptor);
137 return handle(Smi::FromInt(config), isolate);
138 }
139
StoreSlow(Isolate * isolate,KeyedAccessStoreMode store_mode)140 Handle<Smi> StoreHandler::StoreSlow(Isolate* isolate,
141 KeyedAccessStoreMode store_mode) {
142 int config =
143 KindBits::encode(kSlow) | KeyedAccessStoreModeBits::encode(store_mode);
144 return handle(Smi::FromInt(config), isolate);
145 }
146
StoreProxy(Isolate * isolate)147 Handle<Smi> StoreHandler::StoreProxy(Isolate* isolate) {
148 int config = KindBits::encode(kProxy);
149 return handle(Smi::FromInt(config), isolate);
150 }
151
StoreField(Isolate * isolate,Kind kind,int descriptor,FieldIndex field_index,Representation representation)152 Handle<Smi> StoreHandler::StoreField(Isolate* isolate, Kind kind,
153 int descriptor, FieldIndex field_index,
154 Representation representation) {
155 DCHECK(!representation.IsNone());
156 DCHECK(kind == kField || kind == kConstField);
157
158 int config = KindBits::encode(kind) |
159 IsInobjectBits::encode(field_index.is_inobject()) |
160 RepresentationBits::encode(representation.kind()) |
161 DescriptorBits::encode(descriptor) |
162 FieldIndexBits::encode(field_index.index());
163 return handle(Smi::FromInt(config), isolate);
164 }
165
StoreField(Isolate * isolate,int descriptor,FieldIndex field_index,PropertyConstness constness,Representation representation)166 Handle<Smi> StoreHandler::StoreField(Isolate* isolate, int descriptor,
167 FieldIndex field_index,
168 PropertyConstness constness,
169 Representation representation) {
170 Kind kind = constness == PropertyConstness::kMutable ? kField : kConstField;
171 return StoreField(isolate, kind, descriptor, field_index, representation);
172 }
173
StoreNativeDataProperty(Isolate * isolate,int descriptor)174 Handle<Smi> StoreHandler::StoreNativeDataProperty(Isolate* isolate,
175 int descriptor) {
176 int config = KindBits::encode(kNativeDataProperty) |
177 DescriptorBits::encode(descriptor);
178 return handle(Smi::FromInt(config), isolate);
179 }
180
StoreAccessor(Isolate * isolate,int descriptor)181 Handle<Smi> StoreHandler::StoreAccessor(Isolate* isolate, int descriptor) {
182 int config = KindBits::encode(kAccessor) | DescriptorBits::encode(descriptor);
183 return handle(Smi::FromInt(config), isolate);
184 }
185
StoreApiSetter(Isolate * isolate,bool holder_is_receiver)186 Handle<Smi> StoreHandler::StoreApiSetter(Isolate* isolate,
187 bool holder_is_receiver) {
188 int config = KindBits::encode(
189 holder_is_receiver ? kApiSetter : kApiSetterHolderIsPrototype);
190 return handle(Smi::FromInt(config), isolate);
191 }
192
193 } // namespace internal
194 } // namespace v8
195
196 #include "src/objects/object-macros-undef.h"
197
198 #endif // V8_IC_HANDLER_CONFIGURATION_INL_H_
199