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,ElementsKind kind)51 Handle<Smi> LoadHandler::LoadField(Isolate* isolate, FieldIndex field_index,
52                                    ElementsKind kind) {
53   int config = KindBits::encode(kField) |
54                IsInobjectBits::encode(field_index.is_inobject()) |
55                IsDoubleBits::encode(field_index.is_double()) |
56                FieldIndexBits::encode(field_index.index()) |
57                CompactElementsKindBits::encode(ToCompactElementsKind(kind));
58   return handle(Smi::FromInt(config), isolate);
59 }
60 
LoadConstantFromPrototype(Isolate * isolate,ElementsKind kind)61 Handle<Smi> LoadHandler::LoadConstantFromPrototype(Isolate* isolate,
62                                                    ElementsKind kind) {
63   int config = KindBits::encode(kConstantFromPrototype) |
64                CompactElementsKindBits::encode(ToCompactElementsKind(kind));
65   return handle(Smi::FromInt(config), isolate);
66 }
67 
LoadAccessor(Isolate * isolate,int descriptor)68 Handle<Smi> LoadHandler::LoadAccessor(Isolate* isolate, int descriptor) {
69   int config = KindBits::encode(kAccessor) | DescriptorBits::encode(descriptor);
70   return handle(Smi::FromInt(config), isolate);
71 }
72 
LoadProxy(Isolate * isolate)73 Handle<Smi> LoadHandler::LoadProxy(Isolate* isolate) {
74   int config = KindBits::encode(kProxy);
75   return handle(Smi::FromInt(config), isolate);
76 }
77 
LoadNativeDataProperty(Isolate * isolate,int descriptor)78 Handle<Smi> LoadHandler::LoadNativeDataProperty(Isolate* isolate,
79                                                 int descriptor) {
80   int config = KindBits::encode(kNativeDataProperty) |
81                DescriptorBits::encode(descriptor);
82   return handle(Smi::FromInt(config), isolate);
83 }
84 
LoadApiGetter(Isolate * isolate,bool holder_is_receiver)85 Handle<Smi> LoadHandler::LoadApiGetter(Isolate* isolate,
86                                        bool holder_is_receiver) {
87   int config = KindBits::encode(
88       holder_is_receiver ? kApiGetter : kApiGetterHolderIsPrototype);
89   return handle(Smi::FromInt(config), isolate);
90 }
91 
LoadModuleExport(Isolate * isolate,int index)92 Handle<Smi> LoadHandler::LoadModuleExport(Isolate* isolate, int index) {
93   int config =
94       KindBits::encode(kModuleExport) | ExportsIndexBits::encode(index);
95   return handle(Smi::FromInt(config), isolate);
96 }
97 
LoadNonExistent(Isolate * isolate)98 Handle<Smi> LoadHandler::LoadNonExistent(Isolate* isolate) {
99   int config = KindBits::encode(kNonExistent);
100   return handle(Smi::FromInt(config), isolate);
101 }
102 
LoadElement(Isolate * isolate,ElementsKind elements_kind,bool convert_hole_to_undefined,bool is_js_array,KeyedAccessLoadMode load_mode)103 Handle<Smi> LoadHandler::LoadElement(Isolate* isolate,
104                                      ElementsKind elements_kind,
105                                      bool convert_hole_to_undefined,
106                                      bool is_js_array,
107                                      KeyedAccessLoadMode load_mode) {
108   int config =
109       KindBits::encode(kElement) |
110       AllowOutOfBoundsBits::encode(load_mode == LOAD_IGNORE_OUT_OF_BOUNDS) |
111       ElementsKindBits::encode(elements_kind) |
112       ConvertHoleBits::encode(convert_hole_to_undefined) |
113       IsJsArrayBits::encode(is_js_array);
114   return handle(Smi::FromInt(config), isolate);
115 }
116 
LoadIndexedString(Isolate * isolate,KeyedAccessLoadMode load_mode)117 Handle<Smi> LoadHandler::LoadIndexedString(Isolate* isolate,
118                                            KeyedAccessLoadMode load_mode) {
119   int config =
120       KindBits::encode(kIndexedString) |
121       AllowOutOfBoundsBits::encode(load_mode == LOAD_IGNORE_OUT_OF_BOUNDS);
122   return handle(Smi::FromInt(config), isolate);
123 }
124 
OBJECT_CONSTRUCTORS_IMPL(StoreHandler,DataHandler)125 OBJECT_CONSTRUCTORS_IMPL(StoreHandler, DataHandler)
126 
127 CAST_ACCESSOR(StoreHandler)
128 
129 Handle<Smi> StoreHandler::StoreGlobalProxy(Isolate* isolate) {
130   int config = KindBits::encode(kGlobalProxy);
131   return handle(Smi::FromInt(config), isolate);
132 }
133 
StoreNormal(Isolate * isolate)134 Handle<Smi> StoreHandler::StoreNormal(Isolate* isolate) {
135   int config = KindBits::encode(kNormal);
136   return handle(Smi::FromInt(config), isolate);
137 }
138 
StoreInterceptor(Isolate * isolate)139 Handle<Smi> StoreHandler::StoreInterceptor(Isolate* isolate) {
140   int config = KindBits::encode(kInterceptor);
141   return handle(Smi::FromInt(config), isolate);
142 }
143 
StoreSlow(Isolate * isolate,KeyedAccessStoreMode store_mode)144 Handle<Smi> StoreHandler::StoreSlow(Isolate* isolate,
145                                     KeyedAccessStoreMode store_mode) {
146   int config =
147       KindBits::encode(kSlow) | KeyedAccessStoreModeBits::encode(store_mode);
148   return handle(Smi::FromInt(config), isolate);
149 }
150 
StoreProxy(Isolate * isolate)151 Handle<Smi> StoreHandler::StoreProxy(Isolate* isolate) {
152   int config = KindBits::encode(kProxy);
153   return handle(Smi::FromInt(config), isolate);
154 }
155 
StoreField(Isolate * isolate,Kind kind,int descriptor,FieldIndex field_index,Representation representation)156 Handle<Smi> StoreHandler::StoreField(Isolate* isolate, Kind kind,
157                                      int descriptor, FieldIndex field_index,
158                                      Representation representation) {
159   DCHECK(!representation.IsNone());
160   DCHECK(kind == kField || kind == kConstField);
161 
162   int config = KindBits::encode(kind) |
163                IsInobjectBits::encode(field_index.is_inobject()) |
164                RepresentationBits::encode(representation.kind()) |
165                DescriptorBits::encode(descriptor) |
166                FieldIndexBits::encode(field_index.index());
167   return handle(Smi::FromInt(config), isolate);
168 }
169 
StoreField(Isolate * isolate,int descriptor,FieldIndex field_index,PropertyConstness constness,Representation representation)170 Handle<Smi> StoreHandler::StoreField(Isolate* isolate, int descriptor,
171                                      FieldIndex field_index,
172                                      PropertyConstness constness,
173                                      Representation representation) {
174   Kind kind = constness == PropertyConstness::kMutable ? kField : kConstField;
175   return StoreField(isolate, kind, descriptor, field_index, representation);
176 }
177 
StoreNativeDataProperty(Isolate * isolate,int descriptor)178 Handle<Smi> StoreHandler::StoreNativeDataProperty(Isolate* isolate,
179                                                   int descriptor) {
180   int config = KindBits::encode(kNativeDataProperty) |
181                DescriptorBits::encode(descriptor);
182   return handle(Smi::FromInt(config), isolate);
183 }
184 
StoreAccessor(Isolate * isolate,int descriptor)185 Handle<Smi> StoreHandler::StoreAccessor(Isolate* isolate, int descriptor) {
186   int config = KindBits::encode(kAccessor) | DescriptorBits::encode(descriptor);
187   return handle(Smi::FromInt(config), isolate);
188 }
189 
StoreApiSetter(Isolate * isolate,bool holder_is_receiver)190 Handle<Smi> StoreHandler::StoreApiSetter(Isolate* isolate,
191                                          bool holder_is_receiver) {
192   int config = KindBits::encode(
193       holder_is_receiver ? kApiSetter : kApiSetterHolderIsPrototype);
194   return handle(Smi::FromInt(config), isolate);
195 }
196 
197 }  // namespace internal
198 }  // namespace v8
199 
200 #include "src/objects/object-macros-undef.h"
201 
202 #endif  // V8_IC_HANDLER_CONFIGURATION_INL_H_
203