5f8e6da40722f200d8f5081e6f48cd8b6f8f2622
[platform/upstream/nodejs.git] / deps / v8 / src / property.h
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.
4
5 #ifndef V8_PROPERTY_H_
6 #define V8_PROPERTY_H_
7
8 #include <iosfwd>
9
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"
15
16 namespace v8 {
17 namespace internal {
18
19 // Abstraction for elements in instance-descriptor arrays.
20 //
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 {
25  public:
26   void KeyToUniqueName() {
27     if (!key_->IsUniqueName()) {
28       key_ = key_->GetIsolate()->factory()->InternalizeString(
29           Handle<String>::cast(key_));
30     }
31   }
32
33   Handle<Name> GetKey() const { return key_; }
34   Handle<Object> GetValue() const { return value_; }
35   PropertyDetails GetDetails() const { return details_; }
36
37   void SetSortedKeyIndex(int index) { details_ = details_.set_pointer(index); }
38
39  private:
40   Handle<Name> key_;
41   Handle<Object> value_;
42   PropertyDetails details_;
43
44  protected:
45   Descriptor() : details_(Smi::FromInt(0)) {}
46
47   void Init(Handle<Name> key, Handle<Object> value, PropertyDetails details) {
48     key_ = key;
49     value_ = value;
50     details_ = details;
51   }
52
53   Descriptor(Handle<Name> key, Handle<Object> value, PropertyDetails details)
54       : key_(key),
55         value_(value),
56         details_(details) { }
57
58   Descriptor(Handle<Name> key,
59              Handle<Object> value,
60              PropertyAttributes attributes,
61              PropertyType type,
62              Representation representation,
63              int field_index = 0)
64       : key_(key),
65         value_(value),
66         details_(attributes, type, representation, field_index) { }
67
68   friend class DescriptorArray;
69   friend class Map;
70 };
71
72
73 std::ostream& operator<<(std::ostream& os, const Descriptor& d);
74
75
76 class DataDescriptor FINAL : public Descriptor {
77  public:
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,
85                    field_index) {}
86 };
87
88
89 class DataConstantDescriptor FINAL : public Descriptor {
90  public:
91   DataConstantDescriptor(Handle<Name> key, Handle<Object> value,
92                          PropertyAttributes attributes)
93       : Descriptor(key, value, attributes, DATA_CONSTANT,
94                    value->OptimalRepresentation()) {}
95 };
96
97
98 class AccessorConstantDescriptor FINAL : public Descriptor {
99  public:
100   AccessorConstantDescriptor(Handle<Name> key, Handle<Object> foreign,
101                              PropertyAttributes attributes)
102       : Descriptor(key, foreign, attributes, ACCESSOR_CONSTANT,
103                    Representation::Tagged()) {}
104 };
105
106
107 } }  // namespace v8::internal
108
109 #endif  // V8_PROPERTY_H_