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/isolate.h"
13 #include "src/types.h"
18 // Abstraction for elements in instance-descriptor arrays.
20 // Each descriptor has a key, property attributes, property type,
21 // property index (in the actual instance-descriptor array) and
22 // optionally a piece of data.
23 class Descriptor BASE_EMBEDDED {
25 void KeyToUniqueName() {
26 if (!key_->IsUniqueName()) {
27 key_ = key_->GetIsolate()->factory()->InternalizeString(
28 Handle<String>::cast(key_));
32 Handle<Name> GetKey() const { return key_; }
33 Handle<Object> GetValue() const { return value_; }
34 PropertyDetails GetDetails() const { return details_; }
36 void SetSortedKeyIndex(int index) { details_ = details_.set_pointer(index); }
40 Handle<Object> value_;
41 PropertyDetails details_;
44 Descriptor() : details_(Smi::FromInt(0)) {}
46 void Init(Handle<Name> key, Handle<Object> value, PropertyDetails details) {
52 Descriptor(Handle<Name> key, Handle<Object> value, PropertyDetails details)
57 Descriptor(Handle<Name> key,
59 PropertyAttributes attributes,
61 Representation representation,
65 details_(attributes, type, representation, field_index) { }
67 friend class DescriptorArray;
72 std::ostream& operator<<(std::ostream& os, const Descriptor& d);
75 class DataDescriptor final : public Descriptor {
77 DataDescriptor(Handle<Name> key, int field_index,
78 PropertyAttributes attributes, Representation representation)
79 : Descriptor(key, HeapType::Any(key->GetIsolate()), attributes, DATA,
80 representation, field_index) {}
81 // The field type is either a simple type or a map wrapped in a weak cell.
82 DataDescriptor(Handle<Name> key, int field_index,
83 Handle<Object> wrapped_field_type,
84 PropertyAttributes attributes, Representation representation)
85 : Descriptor(key, wrapped_field_type, attributes, DATA, representation,
87 DCHECK(wrapped_field_type->IsSmi() || wrapped_field_type->IsWeakCell());
92 class DataConstantDescriptor final : public Descriptor {
94 DataConstantDescriptor(Handle<Name> key, Handle<Object> value,
95 PropertyAttributes attributes)
96 : Descriptor(key, value, attributes, DATA_CONSTANT,
97 value->OptimalRepresentation()) {}
101 class AccessorConstantDescriptor final : public Descriptor {
103 AccessorConstantDescriptor(Handle<Name> key, Handle<Object> foreign,
104 PropertyAttributes attributes)
105 : Descriptor(key, foreign, attributes, ACCESSOR_CONSTANT,
106 Representation::Tagged()) {}
110 } } // namespace v8::internal
112 #endif // V8_PROPERTY_H_