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