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_LOOKUP_H_ | 5 #ifndef V8_LOOKUP_H_ |
6 #define V8_LOOKUP_H_ | 6 #define V8_LOOKUP_H_ |
7 | 7 |
8 #include "src/factory.h" | 8 #include "src/factory.h" |
9 #include "src/isolate.h" | 9 #include "src/isolate.h" |
10 #include "src/objects.h" | 10 #include "src/objects.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 NOT_FOUND, | 36 NOT_FOUND, |
37 UNKNOWN, // Dictionary-mode holder map without a holder. | 37 UNKNOWN, // Dictionary-mode holder map without a holder. |
38 ACCESSOR, | 38 ACCESSOR, |
39 DATA, | 39 DATA, |
40 TRANSITION, | 40 TRANSITION, |
41 // Set state_ to BEFORE_PROPERTY to ensure that the next lookup will be a | 41 // Set state_ to BEFORE_PROPERTY to ensure that the next lookup will be a |
42 // PROPERTY lookup. | 42 // PROPERTY lookup. |
43 BEFORE_PROPERTY = INTERCEPTOR | 43 BEFORE_PROPERTY = INTERCEPTOR |
44 }; | 44 }; |
45 | 45 |
46 enum PropertyEncoding { | |
47 DICTIONARY, | |
48 DESCRIPTOR | |
49 }; | |
50 | |
51 LookupIterator(Handle<Object> receiver, Handle<Name> name, | 46 LookupIterator(Handle<Object> receiver, Handle<Name> name, |
52 Configuration configuration = PROTOTYPE_CHAIN) | 47 Configuration configuration = PROTOTYPE_CHAIN) |
53 : configuration_(ComputeConfiguration(configuration, name)), | 48 : configuration_(ComputeConfiguration(configuration, name)), |
54 state_(NOT_FOUND), | 49 state_(NOT_FOUND), |
55 property_encoding_(DESCRIPTOR), | |
56 property_details_(NONE, NORMAL, Representation::None()), | 50 property_details_(NONE, NORMAL, Representation::None()), |
57 isolate_(name->GetIsolate()), | 51 isolate_(name->GetIsolate()), |
58 name_(name), | 52 name_(name), |
59 maybe_receiver_(receiver), | 53 maybe_receiver_(receiver), |
60 number_(DescriptorArray::kNotFound) { | 54 number_(DescriptorArray::kNotFound) { |
61 Handle<JSReceiver> root = GetRoot(); | 55 Handle<JSReceiver> root = GetRoot(); |
62 holder_map_ = handle(root->map(), isolate_); | 56 holder_map_ = handle(root->map(), isolate_); |
63 maybe_holder_ = root; | 57 maybe_holder_ = root; |
64 Next(); | 58 Next(); |
65 } | 59 } |
66 | 60 |
67 LookupIterator(Handle<Object> receiver, Handle<Name> name, | 61 LookupIterator(Handle<Object> receiver, Handle<Name> name, |
68 Handle<JSReceiver> holder, | 62 Handle<JSReceiver> holder, |
69 Configuration configuration = PROTOTYPE_CHAIN) | 63 Configuration configuration = PROTOTYPE_CHAIN) |
70 : configuration_(ComputeConfiguration(configuration, name)), | 64 : configuration_(ComputeConfiguration(configuration, name)), |
71 state_(NOT_FOUND), | 65 state_(NOT_FOUND), |
72 property_encoding_(DESCRIPTOR), | |
73 property_details_(NONE, NORMAL, Representation::None()), | 66 property_details_(NONE, NORMAL, Representation::None()), |
74 isolate_(name->GetIsolate()), | 67 isolate_(name->GetIsolate()), |
75 name_(name), | 68 name_(name), |
76 holder_map_(holder->map(), isolate_), | 69 holder_map_(holder->map(), isolate_), |
77 maybe_receiver_(receiver), | 70 maybe_receiver_(receiver), |
78 maybe_holder_(holder), | 71 maybe_holder_(holder), |
79 number_(DescriptorArray::kNotFound) { | 72 number_(DescriptorArray::kNotFound) { |
80 Next(); | 73 Next(); |
81 } | 74 } |
82 | 75 |
83 Isolate* isolate() const { return isolate_; } | 76 Isolate* isolate() const { return isolate_; } |
84 State state() const { return state_; } | 77 State state() const { return state_; } |
85 Handle<Name> name() const { return name_; } | 78 Handle<Name> name() const { return name_; } |
86 | 79 |
87 bool IsFound() const { return state_ != NOT_FOUND; } | 80 bool IsFound() const { return state_ != NOT_FOUND; } |
88 void Next(); | 81 void Next(); |
89 void NotFound() { | 82 void NotFound() { |
90 has_property_ = false; | 83 has_property_ = false; |
91 state_ = NOT_FOUND; | 84 state_ = NOT_FOUND; |
92 } | 85 } |
93 | 86 |
94 Factory* factory() const { return isolate_->factory(); } | 87 Factory* factory() const { return isolate_->factory(); } |
95 Handle<Object> GetReceiver() const { | 88 Handle<Object> GetReceiver() const { |
96 return maybe_receiver_.ToHandleChecked(); | 89 return maybe_receiver_.ToHandleChecked(); |
97 } | 90 } |
98 Handle<JSObject> GetStoreTarget() const; | 91 Handle<JSObject> GetStoreTarget() const; |
99 Handle<Map> holder_map() const { return holder_map_; } | 92 bool is_dictionary_holder() const { return holder_map_->is_dictionary_map(); } |
100 Handle<Map> transition_map() const { | 93 Handle<Map> transition_map() const { |
101 DCHECK_EQ(TRANSITION, state_); | 94 DCHECK_EQ(TRANSITION, state_); |
102 return transition_map_; | 95 return transition_map_; |
103 } | 96 } |
104 template <class T> | 97 template <class T> |
105 Handle<T> GetHolder() const { | 98 Handle<T> GetHolder() const { |
106 DCHECK(IsFound()); | 99 DCHECK(IsFound()); |
107 return Handle<T>::cast(maybe_holder_.ToHandleChecked()); | 100 return Handle<T>::cast(maybe_holder_.ToHandleChecked()); |
108 } | 101 } |
109 Handle<JSReceiver> GetRoot() const; | 102 Handle<JSReceiver> GetRoot() const; |
(...skipping 15 matching lines...) Expand all Loading... |
125 has_property_ = true; | 118 has_property_ = true; |
126 } | 119 } |
127 return cacheable; | 120 return cacheable; |
128 } | 121 } |
129 void ApplyTransitionToDataProperty(); | 122 void ApplyTransitionToDataProperty(); |
130 void ReconfigureDataProperty(Handle<Object> value, | 123 void ReconfigureDataProperty(Handle<Object> value, |
131 PropertyAttributes attributes); | 124 PropertyAttributes attributes); |
132 void TransitionToAccessorProperty(AccessorComponent component, | 125 void TransitionToAccessorProperty(AccessorComponent component, |
133 Handle<Object> accessor, | 126 Handle<Object> accessor, |
134 PropertyAttributes attributes); | 127 PropertyAttributes attributes); |
135 PropertyEncoding property_encoding() const { | |
136 DCHECK(has_property_); | |
137 return property_encoding_; | |
138 } | |
139 PropertyDetails property_details() const { | 128 PropertyDetails property_details() const { |
140 DCHECK(has_property_); | 129 DCHECK(has_property_); |
141 return property_details_; | 130 return property_details_; |
142 } | 131 } |
143 bool IsConfigurable() const { return property_details().IsConfigurable(); } | 132 bool IsConfigurable() const { return property_details().IsConfigurable(); } |
144 bool IsReadOnly() const { return property_details().IsReadOnly(); } | 133 bool IsReadOnly() const { return property_details().IsReadOnly(); } |
145 Representation representation() const { | 134 Representation representation() const { |
146 return property_details().representation(); | 135 return property_details().representation(); |
147 } | 136 } |
148 FieldIndex GetFieldIndex() const; | 137 FieldIndex GetFieldIndex() const; |
(...skipping 25 matching lines...) Expand all Loading... |
174 } | 163 } |
175 bool check_hidden() const { return (configuration_ & kHidden) != 0; } | 164 bool check_hidden() const { return (configuration_ & kHidden) != 0; } |
176 bool check_interceptor() const { | 165 bool check_interceptor() const { |
177 return !IsBootstrapping() && (configuration_ & kInterceptor) != 0; | 166 return !IsBootstrapping() && (configuration_ & kInterceptor) != 0; |
178 } | 167 } |
179 bool check_prototype_chain() const { | 168 bool check_prototype_chain() const { |
180 return (configuration_ & kPrototypeChain) != 0; | 169 return (configuration_ & kPrototypeChain) != 0; |
181 } | 170 } |
182 int descriptor_number() const { | 171 int descriptor_number() const { |
183 DCHECK(has_property_); | 172 DCHECK(has_property_); |
184 DCHECK_EQ(DESCRIPTOR, property_encoding_); | 173 DCHECK(!holder_map_->is_dictionary_map()); |
185 return number_; | 174 return number_; |
186 } | 175 } |
187 int dictionary_entry() const { | 176 int dictionary_entry() const { |
188 DCHECK(has_property_); | 177 DCHECK(has_property_); |
189 DCHECK_EQ(DICTIONARY, property_encoding_); | 178 DCHECK(holder_map_->is_dictionary_map()); |
190 return number_; | 179 return number_; |
191 } | 180 } |
192 | 181 |
193 static Configuration ComputeConfiguration( | 182 static Configuration ComputeConfiguration( |
194 Configuration configuration, Handle<Name> name) { | 183 Configuration configuration, Handle<Name> name) { |
195 if (name->IsOwn()) { | 184 if (name->IsOwn()) { |
196 return static_cast<Configuration>(configuration & HIDDEN); | 185 return static_cast<Configuration>(configuration & HIDDEN); |
197 } else { | 186 } else { |
198 return configuration; | 187 return configuration; |
199 } | 188 } |
200 } | 189 } |
201 | 190 |
202 // If configuration_ becomes mutable, update | 191 // If configuration_ becomes mutable, update |
203 // HolderIsReceiverOrHiddenPrototype. | 192 // HolderIsReceiverOrHiddenPrototype. |
204 Configuration configuration_; | 193 Configuration configuration_; |
205 State state_; | 194 State state_; |
206 bool has_property_; | 195 bool has_property_; |
207 PropertyEncoding property_encoding_; | |
208 PropertyDetails property_details_; | 196 PropertyDetails property_details_; |
209 Isolate* isolate_; | 197 Isolate* isolate_; |
210 Handle<Name> name_; | 198 Handle<Name> name_; |
211 Handle<Map> holder_map_; | 199 Handle<Map> holder_map_; |
212 Handle<Map> transition_map_; | 200 Handle<Map> transition_map_; |
213 MaybeHandle<Object> maybe_receiver_; | 201 MaybeHandle<Object> maybe_receiver_; |
214 MaybeHandle<JSReceiver> maybe_holder_; | 202 MaybeHandle<JSReceiver> maybe_holder_; |
215 | 203 |
216 int number_; | 204 int number_; |
217 }; | 205 }; |
218 | 206 |
219 | 207 |
220 } } // namespace v8::internal | 208 } } // namespace v8::internal |
221 | 209 |
222 #endif // V8_LOOKUP_H_ | 210 #endif // V8_LOOKUP_H_ |
OLD | NEW |