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