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 "isolate.h" | 8 #include "isolate.h" |
| 9 #include "factory.h" |
9 | 10 |
10 namespace v8 { | 11 namespace v8 { |
11 namespace internal { | 12 namespace internal { |
12 | 13 |
13 // Abstraction for elements in instance-descriptor arrays. | 14 // Abstraction for elements in instance-descriptor arrays. |
14 // | 15 // |
15 // Each descriptor has a key, property attributes, property type, | 16 // Each descriptor has a key, property attributes, property type, |
16 // property index (in the actual instance-descriptor array) and | 17 // property index (in the actual instance-descriptor array) and |
17 // optionally a piece of data. | 18 // optionally a piece of data. |
18 class Descriptor BASE_EMBEDDED { | 19 class Descriptor BASE_EMBEDDED { |
19 public: | 20 public: |
20 MUST_USE_RESULT MaybeObject* KeyToUniqueName() { | 21 void KeyToUniqueName() { |
21 if (!key_->IsUniqueName()) { | 22 if (!key_->IsUniqueName()) { |
22 MaybeObject* maybe_result = | 23 key_ = key_->GetIsolate()->factory()->InternalizeString( |
23 key_->GetIsolate()->heap()->InternalizeString(String::cast(key_)); | 24 Handle<String>::cast(key_)); |
24 if (!maybe_result->To(&key_)) return maybe_result; | |
25 } | 25 } |
26 return key_; | |
27 } | 26 } |
28 | 27 |
29 Name* GetKey() { return key_; } | 28 Handle<Name> GetKey() { return key_; } |
30 Object* GetValue() { return value_; } | 29 Handle<Object> GetValue() { return value_; } |
31 PropertyDetails GetDetails() { return details_; } | 30 PropertyDetails GetDetails() { return details_; } |
32 | 31 |
33 #ifdef OBJECT_PRINT | 32 #ifdef OBJECT_PRINT |
34 void Print(FILE* out); | 33 void Print(FILE* out); |
35 #endif | 34 #endif |
36 | 35 |
37 void SetSortedKeyIndex(int index) { details_ = details_.set_pointer(index); } | 36 void SetSortedKeyIndex(int index) { details_ = details_.set_pointer(index); } |
38 | 37 |
39 private: | 38 private: |
40 Name* key_; | 39 Handle<Name> key_; |
41 Object* value_; | 40 Handle<Object> value_; |
42 PropertyDetails details_; | 41 PropertyDetails details_; |
43 | 42 |
44 protected: | 43 protected: |
45 Descriptor() : details_(Smi::FromInt(0)) {} | 44 Descriptor() : details_(Smi::FromInt(0)) {} |
46 | 45 |
47 void Init(Name* key, Object* value, PropertyDetails details) { | 46 void Init(Handle<Name> key, Handle<Object> value, PropertyDetails details) { |
48 key_ = key; | 47 key_ = key; |
49 value_ = value; | 48 value_ = value; |
50 details_ = details; | 49 details_ = details; |
51 } | 50 } |
52 | 51 |
53 Descriptor(Name* key, Object* value, PropertyDetails details) | 52 Descriptor(Handle<Name> key, Handle<Object> value, PropertyDetails details) |
54 : key_(key), | 53 : key_(key), |
55 value_(value), | 54 value_(value), |
56 details_(details) { } | 55 details_(details) { } |
57 | 56 |
58 Descriptor(Name* key, | 57 Descriptor(Handle<Name> key, |
59 Object* value, | 58 Handle<Object> value, |
60 PropertyAttributes attributes, | 59 PropertyAttributes attributes, |
61 PropertyType type, | 60 PropertyType type, |
62 Representation representation, | 61 Representation representation, |
63 int field_index = 0) | 62 int field_index = 0) |
64 : key_(key), | 63 : key_(key), |
65 value_(value), | 64 value_(value), |
66 details_(attributes, type, representation, field_index) { } | 65 details_(attributes, type, representation, field_index) { } |
67 | 66 |
68 friend class DescriptorArray; | 67 friend class DescriptorArray; |
69 }; | 68 }; |
70 | 69 |
71 | 70 |
72 class FieldDescriptor V8_FINAL : public Descriptor { | 71 class FieldDescriptor V8_FINAL : public Descriptor { |
73 public: | 72 public: |
74 FieldDescriptor(Name* key, | 73 FieldDescriptor(Handle<Name> key, |
75 int field_index, | 74 int field_index, |
76 PropertyAttributes attributes, | 75 PropertyAttributes attributes, |
77 Representation representation) | 76 Representation representation) |
78 : Descriptor(key, Smi::FromInt(0), attributes, | 77 : Descriptor(key, handle(Smi::FromInt(0), key->GetIsolate()), attributes, |
79 FIELD, representation, field_index) {} | 78 FIELD, representation, field_index) {} |
80 }; | 79 }; |
81 | 80 |
82 | 81 |
83 class ConstantDescriptor V8_FINAL : public Descriptor { | 82 class ConstantDescriptor V8_FINAL : public Descriptor { |
84 public: | 83 public: |
85 ConstantDescriptor(Name* key, | 84 ConstantDescriptor(Handle<Name> key, |
86 Object* value, | 85 Handle<Object> value, |
87 PropertyAttributes attributes) | 86 PropertyAttributes attributes) |
88 : Descriptor(key, value, attributes, CONSTANT, | 87 : Descriptor(key, value, attributes, CONSTANT, |
89 value->OptimalRepresentation()) {} | 88 value->OptimalRepresentation()) {} |
90 }; | 89 }; |
91 | 90 |
92 | 91 |
93 class CallbacksDescriptor V8_FINAL : public Descriptor { | 92 class CallbacksDescriptor V8_FINAL : public Descriptor { |
94 public: | 93 public: |
95 CallbacksDescriptor(Name* key, | 94 CallbacksDescriptor(Handle<Name> key, |
96 Object* foreign, | 95 Handle<Object> foreign, |
97 PropertyAttributes attributes) | 96 PropertyAttributes attributes) |
98 : Descriptor(key, foreign, attributes, CALLBACKS, | 97 : Descriptor(key, foreign, attributes, CALLBACKS, |
99 Representation::Tagged()) {} | 98 Representation::Tagged()) {} |
100 }; | 99 }; |
101 | 100 |
102 | 101 |
103 // Holds a property index value distinguishing if it is a field index or an | 102 // Holds a property index value distinguishing if it is a field index or an |
104 // index inside the object header. | 103 // index inside the object header. |
105 class PropertyIndex V8_FINAL { | 104 class PropertyIndex V8_FINAL { |
106 public: | 105 public: |
(...skipping 371 matching lines...) Loading... |
478 JSReceiver* holder_; | 477 JSReceiver* holder_; |
479 Map* transition_; | 478 Map* transition_; |
480 int number_; | 479 int number_; |
481 bool cacheable_; | 480 bool cacheable_; |
482 PropertyDetails details_; | 481 PropertyDetails details_; |
483 }; | 482 }; |
484 | 483 |
485 } } // namespace v8::internal | 484 } } // namespace v8::internal |
486 | 485 |
487 #endif // V8_PROPERTY_H_ | 486 #endif // V8_PROPERTY_H_ |
OLD | NEW |