• 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 final BASE_EMBEDDED {
22  public:
Descriptor()23   Descriptor() : details_(Smi::kZero) {}
24 
GetKey()25   Handle<Name> GetKey() const { return key_; }
GetValue()26   Handle<Object> GetValue() const { return value_; }
GetDetails()27   PropertyDetails GetDetails() const { return details_; }
28 
SetSortedKeyIndex(int index)29   void SetSortedKeyIndex(int index) { details_ = details_.set_pointer(index); }
30 
31   static Descriptor DataField(Handle<Name> key, int field_index,
32                               PropertyAttributes attributes,
33                               Representation representation);
34 
35   static Descriptor DataField(Handle<Name> key, int field_index,
36                               PropertyAttributes attributes,
37                               PropertyConstness constness,
38                               Representation representation,
39                               Handle<Object> wrapped_field_type);
40 
DataConstant(Handle<Name> key,Handle<Object> value,PropertyAttributes attributes)41   static Descriptor DataConstant(Handle<Name> key, Handle<Object> value,
42                                  PropertyAttributes attributes) {
43     return Descriptor(key, value, kData, attributes, kDescriptor, kConst,
44                       value->OptimalRepresentation(), 0);
45   }
46 
47   static Descriptor DataConstant(Handle<Name> key, int field_index,
48                                  Handle<Object> value,
49                                  PropertyAttributes attributes);
50 
AccessorConstant(Handle<Name> key,Handle<Object> foreign,PropertyAttributes attributes)51   static Descriptor AccessorConstant(Handle<Name> key, Handle<Object> foreign,
52                                      PropertyAttributes attributes) {
53     return Descriptor(key, foreign, kAccessor, attributes, kDescriptor, kConst,
54                       Representation::Tagged(), 0);
55   }
56 
57  private:
58   Handle<Name> key_;
59   Handle<Object> value_;
60   PropertyDetails details_;
61 
62  protected:
Init(Handle<Name> key,Handle<Object> value,PropertyDetails details)63   void Init(Handle<Name> key, Handle<Object> value, PropertyDetails details) {
64     DCHECK(key->IsUniqueName());
65     DCHECK_IMPLIES(key->IsPrivate(), !details.IsEnumerable());
66     key_ = key;
67     value_ = value;
68     details_ = details;
69   }
70 
Descriptor(Handle<Name> key,Handle<Object> value,PropertyDetails details)71   Descriptor(Handle<Name> key, Handle<Object> value, PropertyDetails details)
72       : key_(key), value_(value), details_(details) {
73     DCHECK(key->IsUniqueName());
74     DCHECK_IMPLIES(key->IsPrivate(), !details_.IsEnumerable());
75   }
76 
Descriptor(Handle<Name> key,Handle<Object> value,PropertyKind kind,PropertyAttributes attributes,PropertyLocation location,PropertyConstness constness,Representation representation,int field_index)77   Descriptor(Handle<Name> key, Handle<Object> value, PropertyKind kind,
78              PropertyAttributes attributes, PropertyLocation location,
79              PropertyConstness constness, Representation representation,
80              int field_index)
81       : key_(key),
82         value_(value),
83         details_(kind, attributes, location, constness, representation,
84                  field_index) {
85     DCHECK(key->IsUniqueName());
86     DCHECK_IMPLIES(key->IsPrivate(), !details_.IsEnumerable());
87   }
88 
89   friend class DescriptorArray;
90   friend class Map;
91   friend class MapUpdater;
92 };
93 
94 }  // namespace internal
95 }  // namespace v8
96 
97 #endif  // V8_PROPERTY_H_
98