deps: update v8 to 4.3.61.21
[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   // The field type is either a simple type or a map wrapped in a weak cell.
83   DataDescriptor(Handle<Name> key, int field_index,
84                  Handle<Object> wrapped_field_type,
85                  PropertyAttributes attributes, Representation representation)
86       : Descriptor(key, wrapped_field_type, attributes, DATA, representation,
87                    field_index) {
88     DCHECK(wrapped_field_type->IsSmi() || wrapped_field_type->IsWeakCell());
89   }
90 };
91
92
93 class DataConstantDescriptor FINAL : public Descriptor {
94  public:
95   DataConstantDescriptor(Handle<Name> key, Handle<Object> value,
96                          PropertyAttributes attributes)
97       : Descriptor(key, value, attributes, DATA_CONSTANT,
98                    value->OptimalRepresentation()) {}
99 };
100
101
102 class AccessorConstantDescriptor FINAL : public Descriptor {
103  public:
104   AccessorConstantDescriptor(Handle<Name> key, Handle<Object> foreign,
105                              PropertyAttributes attributes)
106       : Descriptor(key, foreign, attributes, ACCESSOR_CONSTANT,
107                    Representation::Tagged()) {}
108 };
109
110
111 } }  // namespace v8::internal
112
113 #endif  // V8_PROPERTY_H_