handler-configuration-inl.h 7.25 KB
Newer Older
1 2 3 4 5 6 7 8 9
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_IC_HANDLER_CONFIGURATION_INL_H_
#define V8_IC_HANDLER_CONFIGURATION_INL_H_

#include "src/ic/handler-configuration.h"

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 17

// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"
18 19 20 21

namespace v8 {
namespace internal {

22 23
OBJECT_CONSTRUCTORS_IMPL(LoadHandler, DataHandler)

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
}

31
Handle<Smi> LoadHandler::LoadNormal(Isolate* isolate) {
32 33
  // TODO(v8:11167) remove DCHECK once OrderedNameDictionary supported.
  DCHECK(!V8_DICT_MODE_PROTOTYPES_BOOL);
34
  int config = KindBits::encode(kNormal);
35 36 37
  return handle(Smi::FromInt(config), isolate);
}

38 39 40 41 42
Handle<Smi> LoadHandler::LoadGlobal(Isolate* isolate) {
  int config = KindBits::encode(kGlobal);
  return handle(Smi::FromInt(config), isolate);
}

43 44 45 46 47
Handle<Smi> LoadHandler::LoadInterceptor(Isolate* isolate) {
  int config = KindBits::encode(kInterceptor);
  return handle(Smi::FromInt(config), isolate);
}

48 49 50 51 52
Handle<Smi> LoadHandler::LoadSlow(Isolate* isolate) {
  int config = KindBits::encode(kSlow);
  return handle(Smi::FromInt(config), isolate);
}

53
Handle<Smi> LoadHandler::LoadField(Isolate* isolate, FieldIndex field_index) {
54
  int config = KindBits::encode(kField) |
55 56
               IsInobjectBits::encode(field_index.is_inobject()) |
               IsDoubleBits::encode(field_index.is_double()) |
57
               FieldIndexBits::encode(field_index.index());
58 59 60
  return handle(Smi::FromInt(config), isolate);
}

61 62
Handle<Smi> LoadHandler::LoadConstantFromPrototype(Isolate* isolate) {
  int config = KindBits::encode(kConstantFromPrototype);
63 64 65
  return handle(Smi::FromInt(config), isolate);
}

66
Handle<Smi> LoadHandler::LoadAccessor(Isolate* isolate, int descriptor) {
67
  int config = KindBits::encode(kAccessor) | DescriptorBits::encode(descriptor);
68 69 70
  return handle(Smi::FromInt(config), isolate);
}

71 72 73 74 75
Handle<Smi> LoadHandler::LoadProxy(Isolate* isolate) {
  int config = KindBits::encode(kProxy);
  return handle(Smi::FromInt(config), isolate);
}

76 77 78
Handle<Smi> LoadHandler::LoadNativeDataProperty(Isolate* isolate,
                                                int descriptor) {
  int config = KindBits::encode(kNativeDataProperty) |
79
               DescriptorBits::encode(descriptor);
80 81 82
  return handle(Smi::FromInt(config), isolate);
}

83 84 85 86 87 88 89
Handle<Smi> LoadHandler::LoadApiGetter(Isolate* isolate,
                                       bool holder_is_receiver) {
  int config = KindBits::encode(
      holder_is_receiver ? kApiGetter : kApiGetterHolderIsPrototype);
  return handle(Smi::FromInt(config), isolate);
}

90 91 92 93 94 95
Handle<Smi> LoadHandler::LoadModuleExport(Isolate* isolate, int index) {
  int config =
      KindBits::encode(kModuleExport) | ExportsIndexBits::encode(index);
  return handle(Smi::FromInt(config), isolate);
}

96 97
Handle<Smi> LoadHandler::LoadNonExistent(Isolate* isolate) {
  int config = KindBits::encode(kNonExistent);
98 99 100
  return handle(Smi::FromInt(config), isolate);
}

101 102 103
Handle<Smi> LoadHandler::LoadElement(Isolate* isolate,
                                     ElementsKind elements_kind,
                                     bool convert_hole_to_undefined,
104 105 106 107 108 109 110 111
                                     bool is_js_array,
                                     KeyedAccessLoadMode load_mode) {
  int config =
      KindBits::encode(kElement) |
      AllowOutOfBoundsBits::encode(load_mode == LOAD_IGNORE_OUT_OF_BOUNDS) |
      ElementsKindBits::encode(elements_kind) |
      ConvertHoleBits::encode(convert_hole_to_undefined) |
      IsJsArrayBits::encode(is_js_array);
112 113 114
  return handle(Smi::FromInt(config), isolate);
}

115
Handle<Smi> LoadHandler::LoadIndexedString(Isolate* isolate,
116 117 118 119
                                           KeyedAccessLoadMode load_mode) {
  int config =
      KindBits::encode(kIndexedString) |
      AllowOutOfBoundsBits::encode(load_mode == LOAD_IGNORE_OUT_OF_BOUNDS);
120 121 122
  return handle(Smi::FromInt(config), isolate);
}

123 124
OBJECT_CONSTRUCTORS_IMPL(StoreHandler, DataHandler)

125
CAST_ACCESSOR(StoreHandler)
126

127
Handle<Smi> StoreHandler::StoreGlobalProxy(Isolate* isolate) {
128
  int config = KindBits::encode(kGlobalProxy);
129 130 131
  return handle(Smi::FromInt(config), isolate);
}

132
Handle<Smi> StoreHandler::StoreNormal(Isolate* isolate) {
133 134
  // TODO(v8:11167) remove DCHECK once OrderedNameDictionary supported.
  DCHECK(!V8_DICT_MODE_PROTOTYPES_BOOL);
135
  int config = KindBits::encode(kNormal);
136 137 138
  return handle(Smi::FromInt(config), isolate);
}

139 140 141 142 143
Handle<Smi> StoreHandler::StoreInterceptor(Isolate* isolate) {
  int config = KindBits::encode(kInterceptor);
  return handle(Smi::FromInt(config), isolate);
}

144 145 146 147
Handle<Smi> StoreHandler::StoreSlow(Isolate* isolate,
                                    KeyedAccessStoreMode store_mode) {
  int config =
      KindBits::encode(kSlow) | KeyedAccessStoreModeBits::encode(store_mode);
148 149 150
  return handle(Smi::FromInt(config), isolate);
}

151 152 153 154 155
Handle<Smi> StoreHandler::StoreProxy(Isolate* isolate) {
  int config = KindBits::encode(kProxy);
  return handle(Smi::FromInt(config), isolate);
}

156 157
Handle<Smi> StoreHandler::StoreField(Isolate* isolate, Kind kind,
                                     int descriptor, FieldIndex field_index,
158
                                     Representation representation) {
159
  DCHECK(!representation.IsNone());
160
  DCHECK(kind == kField || kind == kConstField);
161

162 163
  int config = KindBits::encode(kind) |
               IsInobjectBits::encode(field_index.is_inobject()) |
164
               RepresentationBits::encode(representation.kind()) |
165 166
               DescriptorBits::encode(descriptor) |
               FieldIndexBits::encode(field_index.index());
167 168 169
  return handle(Smi::FromInt(config), isolate);
}

170 171 172 173
Handle<Smi> StoreHandler::StoreField(Isolate* isolate, int descriptor,
                                     FieldIndex field_index,
                                     PropertyConstness constness,
                                     Representation representation) {
174
  Kind kind = constness == PropertyConstness::kMutable ? kField : kConstField;
175
  return StoreField(isolate, kind, descriptor, field_index, representation);
176 177
}

178 179 180 181 182 183 184
Handle<Smi> StoreHandler::StoreNativeDataProperty(Isolate* isolate,
                                                  int descriptor) {
  int config = KindBits::encode(kNativeDataProperty) |
               DescriptorBits::encode(descriptor);
  return handle(Smi::FromInt(config), isolate);
}

185 186
Handle<Smi> StoreHandler::StoreAccessor(Isolate* isolate, int descriptor) {
  int config = KindBits::encode(kAccessor) | DescriptorBits::encode(descriptor);
187 188 189 190 191 192 193
  return handle(Smi::FromInt(config), isolate);
}

Handle<Smi> StoreHandler::StoreApiSetter(Isolate* isolate,
                                         bool holder_is_receiver) {
  int config = KindBits::encode(
      holder_is_receiver ? kApiSetter : kApiSetterHolderIsPrototype);
194 195 196
  return handle(Smi::FromInt(config), isolate);
}

197 198 199
}  // namespace internal
}  // namespace v8

200 201
#include "src/objects/object-macros-undef.h"

202
#endif  // V8_IC_HANDLER_CONFIGURATION_INL_H_