OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_PROPERTY_H_ | 5 #ifndef V8_PROPERTY_H_ |
6 #define V8_PROPERTY_H_ | 6 #define V8_PROPERTY_H_ |
7 | 7 |
8 #include <iosfwd> | 8 #include <iosfwd> |
9 | 9 |
10 #include "src/factory.h" | 10 #include "src/factory.h" |
11 #include "src/isolate.h" | 11 #include "src/isolate.h" |
12 | 12 |
13 namespace v8 { | 13 namespace v8 { |
14 namespace internal { | 14 namespace internal { |
15 | 15 |
16 // Abstraction for elements in instance-descriptor arrays. | 16 // Abstraction for elements in instance-descriptor arrays. |
17 // | 17 // |
18 // Each descriptor has a key, property attributes, property type, | 18 // Each descriptor has a key, property attributes, property type, |
19 // property index (in the actual instance-descriptor array) and | 19 // property index (in the actual instance-descriptor array) and |
20 // optionally a piece of data. | 20 // optionally a piece of data. |
21 class Descriptor BASE_EMBEDDED { | 21 class Descriptor final BASE_EMBEDDED { |
22 public: | 22 public: |
23 Handle<Name> GetKey() const { return key_; } | 23 Handle<Name> GetKey() const { return key_; } |
24 Handle<Object> GetValue() const { return value_; } | 24 Handle<Object> GetValue() const { return value_; } |
25 PropertyDetails GetDetails() const { return details_; } | 25 PropertyDetails GetDetails() const { return details_; } |
26 | 26 |
27 void SetSortedKeyIndex(int index) { details_ = details_.set_pointer(index); } | 27 void SetSortedKeyIndex(int index) { details_ = details_.set_pointer(index); } |
28 | 28 |
| 29 static Descriptor DataField(Handle<Name> key, int field_index, |
| 30 PropertyAttributes attributes, |
| 31 Representation representation); |
| 32 |
| 33 static Descriptor DataField(Handle<Name> key, int field_index, |
| 34 Handle<Object> wrapped_field_type, |
| 35 PropertyAttributes attributes, |
| 36 Representation representation) { |
| 37 DCHECK(wrapped_field_type->IsSmi() || wrapped_field_type->IsWeakCell()); |
| 38 return Descriptor(key, wrapped_field_type, attributes, DATA, representation, |
| 39 field_index); |
| 40 } |
| 41 |
| 42 static Descriptor DataConstant(Handle<Name> key, Handle<Object> value, |
| 43 PropertyAttributes attributes) { |
| 44 return Descriptor(key, value, attributes, DATA_CONSTANT, |
| 45 value->OptimalRepresentation()); |
| 46 } |
| 47 |
| 48 static Descriptor AccessorConstant(Handle<Name> key, Handle<Object> foreign, |
| 49 PropertyAttributes attributes) { |
| 50 return Descriptor(key, foreign, attributes, ACCESSOR_CONSTANT, |
| 51 Representation::Tagged()); |
| 52 } |
| 53 |
29 private: | 54 private: |
30 Handle<Name> key_; | 55 Handle<Name> key_; |
31 Handle<Object> value_; | 56 Handle<Object> value_; |
32 PropertyDetails details_; | 57 PropertyDetails details_; |
33 | 58 |
34 protected: | 59 protected: |
35 Descriptor() : details_(Smi::kZero) {} | 60 Descriptor() : details_(Smi::kZero) {} |
36 | 61 |
37 void Init(Handle<Name> key, Handle<Object> value, PropertyDetails details) { | 62 void Init(Handle<Name> key, Handle<Object> value, PropertyDetails details) { |
38 DCHECK(key->IsUniqueName()); | 63 DCHECK(key->IsUniqueName()); |
(...skipping 16 matching lines...) Expand all Loading... |
55 value_(value), | 80 value_(value), |
56 details_(attributes, type, representation, field_index) { | 81 details_(attributes, type, representation, field_index) { |
57 DCHECK(key->IsUniqueName()); | 82 DCHECK(key->IsUniqueName()); |
58 DCHECK_IMPLIES(key->IsPrivate(), !details_.IsEnumerable()); | 83 DCHECK_IMPLIES(key->IsPrivate(), !details_.IsEnumerable()); |
59 } | 84 } |
60 | 85 |
61 friend class DescriptorArray; | 86 friend class DescriptorArray; |
62 friend class Map; | 87 friend class Map; |
63 }; | 88 }; |
64 | 89 |
65 | |
66 std::ostream& operator<<(std::ostream& os, const Descriptor& d); | 90 std::ostream& operator<<(std::ostream& os, const Descriptor& d); |
67 | 91 |
68 | |
69 class DataDescriptor final : public Descriptor { | |
70 public: | |
71 DataDescriptor(Handle<Name> key, int field_index, | |
72 PropertyAttributes attributes, Representation representation); | |
73 // The field type is either a simple type or a map wrapped in a weak cell. | |
74 DataDescriptor(Handle<Name> key, int field_index, | |
75 Handle<Object> wrapped_field_type, | |
76 PropertyAttributes attributes, Representation representation) | |
77 : Descriptor(key, wrapped_field_type, attributes, DATA, representation, | |
78 field_index) { | |
79 DCHECK(wrapped_field_type->IsSmi() || wrapped_field_type->IsWeakCell()); | |
80 } | |
81 }; | |
82 | |
83 | |
84 class DataConstantDescriptor final : public Descriptor { | |
85 public: | |
86 DataConstantDescriptor(Handle<Name> key, Handle<Object> value, | |
87 PropertyAttributes attributes) | |
88 : Descriptor(key, value, attributes, DATA_CONSTANT, | |
89 value->OptimalRepresentation()) {} | |
90 }; | |
91 | |
92 | |
93 class AccessorConstantDescriptor final : public Descriptor { | |
94 public: | |
95 AccessorConstantDescriptor(Handle<Name> key, Handle<Object> foreign, | |
96 PropertyAttributes attributes) | |
97 : Descriptor(key, foreign, attributes, ACCESSOR_CONSTANT, | |
98 Representation::Tagged()) {} | |
99 }; | |
100 | |
101 | |
102 } // namespace internal | 92 } // namespace internal |
103 } // namespace v8 | 93 } // namespace v8 |
104 | 94 |
105 #endif // V8_PROPERTY_H_ | 95 #endif // V8_PROPERTY_H_ |
OLD | NEW |