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