• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/isolate.h"
12 
13 namespace v8 {
14 namespace internal {
15 
16 // Abstraction for elements in instance-descriptor arrays.
17 //
18 // Each descriptor has a key, property attributes, property type,
19 // property index (in the actual instance-descriptor array) and
20 // optionally a piece of data.
21 class Descriptor BASE_EMBEDDED {
22  public:
GetKey()23   Handle<Name> GetKey() const { return key_; }
GetValue()24   Handle<Object> GetValue() const { return value_; }
GetDetails()25   PropertyDetails GetDetails() const { return details_; }
26 
SetSortedKeyIndex(int index)27   void SetSortedKeyIndex(int index) { details_ = details_.set_pointer(index); }
28 
29  private:
30   Handle<Name> key_;
31   Handle<Object> value_;
32   PropertyDetails details_;
33 
34  protected:
Descriptor()35   Descriptor() : details_(Smi::FromInt(0)) {}
36 
Init(Handle<Name> key,Handle<Object> value,PropertyDetails details)37   void Init(Handle<Name> key, Handle<Object> value, PropertyDetails details) {
38     DCHECK(key->IsUniqueName());
39     key_ = key;
40     value_ = value;
41     details_ = details;
42   }
43 
Descriptor(Handle<Name> key,Handle<Object> value,PropertyDetails details)44   Descriptor(Handle<Name> key, Handle<Object> value, PropertyDetails details)
45       : key_(key), value_(value), details_(details) {
46     DCHECK(key->IsUniqueName());
47   }
48 
49   Descriptor(Handle<Name> key, Handle<Object> value,
50              PropertyAttributes attributes, PropertyType type,
51              Representation representation, int field_index = 0)
key_(key)52       : key_(key),
53         value_(value),
54         details_(attributes, type, representation, field_index) {
55     DCHECK(key->IsUniqueName());
56   }
57 
58   friend class DescriptorArray;
59   friend class Map;
60 };
61 
62 
63 std::ostream& operator<<(std::ostream& os, const Descriptor& d);
64 
65 
66 class DataDescriptor final : public Descriptor {
67  public:
68   DataDescriptor(Handle<Name> key, int field_index,
69                  PropertyAttributes attributes, Representation representation);
70   // The field type is either a simple type or a map wrapped in a weak cell.
DataDescriptor(Handle<Name> key,int field_index,Handle<Object> wrapped_field_type,PropertyAttributes attributes,Representation representation)71   DataDescriptor(Handle<Name> key, int field_index,
72                  Handle<Object> wrapped_field_type,
73                  PropertyAttributes attributes, Representation representation)
74       : Descriptor(key, wrapped_field_type, attributes, DATA, representation,
75                    field_index) {
76     DCHECK(wrapped_field_type->IsSmi() || wrapped_field_type->IsWeakCell());
77   }
78 };
79 
80 
81 class DataConstantDescriptor final : public Descriptor {
82  public:
DataConstantDescriptor(Handle<Name> key,Handle<Object> value,PropertyAttributes attributes)83   DataConstantDescriptor(Handle<Name> key, Handle<Object> value,
84                          PropertyAttributes attributes)
85       : Descriptor(key, value, attributes, DATA_CONSTANT,
86                    value->OptimalRepresentation()) {}
87 };
88 
89 
90 class AccessorConstantDescriptor final : public Descriptor {
91  public:
AccessorConstantDescriptor(Handle<Name> key,Handle<Object> foreign,PropertyAttributes attributes)92   AccessorConstantDescriptor(Handle<Name> key, Handle<Object> foreign,
93                              PropertyAttributes attributes)
94       : Descriptor(key, foreign, attributes, ACCESSOR_CONSTANT,
95                    Representation::Tagged()) {}
96 };
97 
98 
99 }  // namespace internal
100 }  // namespace v8
101 
102 #endif  // V8_PROPERTY_H_
103