1 // Copyright 2014 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.
10 #include "src/factory.h"
11 #include "src/field-index.h"
12 #include "src/field-index-inl.h"
13 #include "src/isolate.h"
14 #include "src/types.h"
19 // Abstraction for elements in instance-descriptor arrays.
21 // Each descriptor has a key, property attributes, property type,
22 // property index (in the actual instance-descriptor array) and
23 // optionally a piece of data.
24 class Descriptor BASE_EMBEDDED {
26 void KeyToUniqueName() {
27 if (!key_->IsUniqueName()) {
28 key_ = key_->GetIsolate()->factory()->InternalizeString(
29 Handle<String>::cast(key_));
33 Handle<Name> GetKey() const { return key_; }
34 Handle<Object> GetValue() const { return value_; }
35 PropertyDetails GetDetails() const { return details_; }
37 void SetSortedKeyIndex(int index) { details_ = details_.set_pointer(index); }
41 Handle<Object> value_;
42 PropertyDetails details_;
45 Descriptor() : details_(Smi::FromInt(0)) {}
47 void Init(Handle<Name> key, Handle<Object> value, PropertyDetails details) {
53 Descriptor(Handle<Name> key, Handle<Object> value, PropertyDetails details)
58 Descriptor(Handle<Name> key,
60 PropertyAttributes attributes,
62 Representation representation,
66 details_(attributes, type, representation, field_index) { }
68 friend class DescriptorArray;
73 std::ostream& operator<<(std::ostream& os, const Descriptor& d);
76 class DataDescriptor FINAL : public Descriptor {
78 DataDescriptor(Handle<Name> key, int field_index,
79 PropertyAttributes attributes, Representation representation)
80 : Descriptor(key, HeapType::Any(key->GetIsolate()), attributes, DATA,
81 representation, field_index) {}
82 DataDescriptor(Handle<Name> key, int field_index, Handle<HeapType> field_type,
83 PropertyAttributes attributes, Representation representation)
84 : Descriptor(key, field_type, attributes, DATA, representation,
89 class DataConstantDescriptor FINAL : public Descriptor {
91 DataConstantDescriptor(Handle<Name> key, Handle<Object> value,
92 PropertyAttributes attributes)
93 : Descriptor(key, value, attributes, DATA_CONSTANT,
94 value->OptimalRepresentation()) {}
98 class AccessorConstantDescriptor FINAL : public Descriptor {
100 AccessorConstantDescriptor(Handle<Name> key, Handle<Object> foreign,
101 PropertyAttributes attributes)
102 : Descriptor(key, foreign, attributes, ACCESSOR_CONSTANT,
103 Representation::Tagged()) {}
107 } } // namespace v8::internal
109 #endif // V8_PROPERTY_H_