| 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 29 matching lines...) Expand all Loading... |
| 40 DATA, | 40 DATA, |
| 41 TRANSITION, | 41 TRANSITION, |
| 42 // Set state_ to BEFORE_PROPERTY to ensure that the next lookup will be a | 42 // Set state_ to BEFORE_PROPERTY to ensure that the next lookup will be a |
| 43 // PROPERTY lookup. | 43 // PROPERTY lookup. |
| 44 BEFORE_PROPERTY = INTERCEPTOR | 44 BEFORE_PROPERTY = INTERCEPTOR |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 LookupIterator(Handle<Object> receiver, Handle<Name> name, | 47 LookupIterator(Handle<Object> receiver, Handle<Name> name, |
| 48 Configuration configuration = DEFAULT) | 48 Configuration configuration = DEFAULT) |
| 49 : configuration_(ComputeConfiguration(configuration, name)), | 49 : configuration_(ComputeConfiguration(configuration, name)), |
| 50 state_(NOT_FOUND), | |
| 51 interceptor_state_(InterceptorState::kUninitialized), | 50 interceptor_state_(InterceptorState::kUninitialized), |
| 52 property_details_(PropertyDetails::Empty()), | 51 property_details_(PropertyDetails::Empty()), |
| 53 isolate_(name->GetIsolate()), | 52 isolate_(name->GetIsolate()), |
| 54 name_(isolate_->factory()->InternalizeName(name)), | 53 name_(isolate_->factory()->InternalizeName(name)), |
| 55 // kMaxUInt32 isn't a valid index. | 54 // kMaxUInt32 isn't a valid index. |
| 56 index_(kMaxUInt32), | 55 index_(kMaxUInt32), |
| 57 receiver_(receiver), | 56 receiver_(receiver), |
| 58 holder_(GetRoot(isolate_, receiver)), | 57 initial_holder_(GetRoot(isolate_, receiver)) { |
| 59 initial_holder_(holder_), | |
| 60 number_(DescriptorArray::kNotFound) { | |
| 61 #ifdef DEBUG | 58 #ifdef DEBUG |
| 62 uint32_t index; // Assert that the name is not an array index. | 59 uint32_t index; // Assert that the name is not an array index. |
| 63 DCHECK(!name->AsArrayIndex(&index)); | 60 DCHECK(!name->AsArrayIndex(&index)); |
| 64 #endif // DEBUG | 61 #endif // DEBUG |
| 65 Next(); | 62 Start(); |
| 66 } | 63 } |
| 67 | 64 |
| 68 LookupIterator(Handle<Object> receiver, Handle<Name> name, | 65 LookupIterator(Handle<Object> receiver, Handle<Name> name, |
| 69 Handle<JSReceiver> holder, | 66 Handle<JSReceiver> holder, |
| 70 Configuration configuration = DEFAULT) | 67 Configuration configuration = DEFAULT) |
| 71 : configuration_(ComputeConfiguration(configuration, name)), | 68 : configuration_(ComputeConfiguration(configuration, name)), |
| 72 state_(NOT_FOUND), | |
| 73 interceptor_state_(InterceptorState::kUninitialized), | 69 interceptor_state_(InterceptorState::kUninitialized), |
| 74 property_details_(PropertyDetails::Empty()), | 70 property_details_(PropertyDetails::Empty()), |
| 75 isolate_(name->GetIsolate()), | 71 isolate_(name->GetIsolate()), |
| 76 name_(isolate_->factory()->InternalizeName(name)), | 72 name_(isolate_->factory()->InternalizeName(name)), |
| 77 // kMaxUInt32 isn't a valid index. | 73 // kMaxUInt32 isn't a valid index. |
| 78 index_(kMaxUInt32), | 74 index_(kMaxUInt32), |
| 79 receiver_(receiver), | 75 receiver_(receiver), |
| 80 holder_(holder), | 76 initial_holder_(holder) { |
| 81 initial_holder_(holder_), | |
| 82 number_(DescriptorArray::kNotFound) { | |
| 83 #ifdef DEBUG | 77 #ifdef DEBUG |
| 84 uint32_t index; // Assert that the name is not an array index. | 78 uint32_t index; // Assert that the name is not an array index. |
| 85 DCHECK(!name->AsArrayIndex(&index)); | 79 DCHECK(!name->AsArrayIndex(&index)); |
| 86 #endif // DEBUG | 80 #endif // DEBUG |
| 87 Next(); | 81 Start(); |
| 88 } | 82 } |
| 89 | 83 |
| 90 LookupIterator(Isolate* isolate, Handle<Object> receiver, uint32_t index, | 84 LookupIterator(Isolate* isolate, Handle<Object> receiver, uint32_t index, |
| 91 Configuration configuration = DEFAULT) | 85 Configuration configuration = DEFAULT) |
| 92 : configuration_(configuration), | 86 : configuration_(configuration), |
| 93 state_(NOT_FOUND), | |
| 94 interceptor_state_(InterceptorState::kUninitialized), | 87 interceptor_state_(InterceptorState::kUninitialized), |
| 95 property_details_(PropertyDetails::Empty()), | 88 property_details_(PropertyDetails::Empty()), |
| 96 isolate_(isolate), | 89 isolate_(isolate), |
| 97 name_(), | 90 name_(), |
| 98 index_(index), | 91 index_(index), |
| 99 receiver_(receiver), | 92 receiver_(receiver), |
| 100 holder_(GetRoot(isolate, receiver, index)), | 93 initial_holder_(GetRoot(isolate, receiver, index)) { |
| 101 initial_holder_(holder_), | |
| 102 number_(DescriptorArray::kNotFound) { | |
| 103 // kMaxUInt32 isn't a valid index. | 94 // kMaxUInt32 isn't a valid index. |
| 104 DCHECK_NE(kMaxUInt32, index_); | 95 DCHECK_NE(kMaxUInt32, index_); |
| 105 Next(); | 96 Start(); |
| 106 } | 97 } |
| 107 | 98 |
| 108 LookupIterator(Isolate* isolate, Handle<Object> receiver, uint32_t index, | 99 LookupIterator(Isolate* isolate, Handle<Object> receiver, uint32_t index, |
| 109 Handle<JSReceiver> holder, | 100 Handle<JSReceiver> holder, |
| 110 Configuration configuration = DEFAULT) | 101 Configuration configuration = DEFAULT) |
| 111 : configuration_(configuration), | 102 : configuration_(configuration), |
| 112 state_(NOT_FOUND), | |
| 113 interceptor_state_(InterceptorState::kUninitialized), | 103 interceptor_state_(InterceptorState::kUninitialized), |
| 114 property_details_(PropertyDetails::Empty()), | 104 property_details_(PropertyDetails::Empty()), |
| 115 isolate_(isolate), | 105 isolate_(isolate), |
| 116 name_(), | 106 name_(), |
| 117 index_(index), | 107 index_(index), |
| 118 receiver_(receiver), | 108 receiver_(receiver), |
| 119 holder_(holder), | 109 initial_holder_(holder) { |
| 120 initial_holder_(holder_), | |
| 121 number_(DescriptorArray::kNotFound) { | |
| 122 // kMaxUInt32 isn't a valid index. | 110 // kMaxUInt32 isn't a valid index. |
| 123 DCHECK_NE(kMaxUInt32, index_); | 111 DCHECK_NE(kMaxUInt32, index_); |
| 124 Next(); | 112 Start(); |
| 125 } | 113 } |
| 126 | 114 |
| 127 static LookupIterator PropertyOrElement( | 115 static LookupIterator PropertyOrElement( |
| 128 Isolate* isolate, Handle<Object> receiver, Handle<Name> name, | 116 Isolate* isolate, Handle<Object> receiver, Handle<Name> name, |
| 129 Configuration configuration = DEFAULT) { | 117 Configuration configuration = DEFAULT) { |
| 130 uint32_t index; | 118 uint32_t index; |
| 131 if (name->AsArrayIndex(&index)) { | 119 if (name->AsArrayIndex(&index)) { |
| 132 LookupIterator it = | 120 LookupIterator it = |
| 133 LookupIterator(isolate, receiver, index, configuration); | 121 LookupIterator(isolate, receiver, index, configuration); |
| 134 it.name_ = name; | 122 it.name_ = name; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 bool IsFound() const { return state_ != NOT_FOUND; } | 165 bool IsFound() const { return state_ != NOT_FOUND; } |
| 178 void Next(); | 166 void Next(); |
| 179 void NotFound() { | 167 void NotFound() { |
| 180 has_property_ = false; | 168 has_property_ = false; |
| 181 state_ = NOT_FOUND; | 169 state_ = NOT_FOUND; |
| 182 } | 170 } |
| 183 | 171 |
| 184 Heap* heap() const { return isolate_->heap(); } | 172 Heap* heap() const { return isolate_->heap(); } |
| 185 Factory* factory() const { return isolate_->factory(); } | 173 Factory* factory() const { return isolate_->factory(); } |
| 186 Handle<Object> GetReceiver() const { return receiver_; } | 174 Handle<Object> GetReceiver() const { return receiver_; } |
| 187 Handle<JSObject> GetStoreTarget() const; | 175 |
| 176 Handle<JSObject> GetStoreTarget() const { |
| 177 if (receiver_->IsJSGlobalProxy()) { |
| 178 Map* map = JSGlobalProxy::cast(*receiver_)->map(); |
| 179 if (map->has_hidden_prototype()) { |
| 180 return handle(JSGlobalObject::cast(map->prototype()), isolate_); |
| 181 } |
| 182 } |
| 183 return Handle<JSObject>::cast(receiver_); |
| 184 } |
| 185 |
| 188 bool is_dictionary_holder() const { return !holder_->HasFastProperties(); } | 186 bool is_dictionary_holder() const { return !holder_->HasFastProperties(); } |
| 189 Handle<Map> transition_map() const { | 187 Handle<Map> transition_map() const { |
| 190 DCHECK_EQ(TRANSITION, state_); | 188 DCHECK_EQ(TRANSITION, state_); |
| 191 return Handle<Map>::cast(transition_); | 189 return Handle<Map>::cast(transition_); |
| 192 } | 190 } |
| 193 template <class T> | 191 template <class T> |
| 194 Handle<T> GetHolder() const { | 192 Handle<T> GetHolder() const { |
| 195 DCHECK(IsFound()); | 193 DCHECK(IsFound()); |
| 196 return Handle<T>::cast(holder_); | 194 return Handle<T>::cast(holder_); |
| 197 } | 195 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 Handle<Object> GetAccessors() const; | 250 Handle<Object> GetAccessors() const; |
| 253 inline Handle<InterceptorInfo> GetInterceptor() const { | 251 inline Handle<InterceptorInfo> GetInterceptor() const { |
| 254 DCHECK_EQ(INTERCEPTOR, state_); | 252 DCHECK_EQ(INTERCEPTOR, state_); |
| 255 return handle(GetInterceptor(JSObject::cast(*holder_)), isolate_); | 253 return handle(GetInterceptor(JSObject::cast(*holder_)), isolate_); |
| 256 } | 254 } |
| 257 Handle<Object> GetDataValue() const; | 255 Handle<Object> GetDataValue() const; |
| 258 void WriteDataValue(Handle<Object> value); | 256 void WriteDataValue(Handle<Object> value); |
| 259 void UpdateProtector(); | 257 void UpdateProtector(); |
| 260 | 258 |
| 261 private: | 259 private: |
| 260 void Start(); |
| 261 void NextInternal(Map* map, JSReceiver* holder); |
| 262 |
| 262 enum class InterceptorState { | 263 enum class InterceptorState { |
| 263 kUninitialized, | 264 kUninitialized, |
| 264 kSkipNonMasking, | 265 kSkipNonMasking, |
| 265 kProcessNonMasking | 266 kProcessNonMasking |
| 266 }; | 267 }; |
| 267 | 268 |
| 268 Handle<Map> GetReceiverMap() const; | 269 Handle<Map> GetReceiverMap() const; |
| 269 | 270 |
| 270 MUST_USE_RESULT inline JSReceiver* NextHolder(Map* map); | 271 MUST_USE_RESULT inline JSReceiver* NextHolder(Map* map); |
| 271 inline State LookupInHolder(Map* map, JSReceiver* holder); | 272 inline State LookupInHolder(Map* map, JSReceiver* holder) { |
| 273 return map->instance_type() <= LAST_SPECIAL_RECEIVER_TYPE |
| 274 ? LookupInSpecialHolder(map, holder) |
| 275 : LookupInRegularHolder(map, holder); |
| 276 } |
| 277 State LookupInRegularHolder(Map* map, JSReceiver* holder); |
| 278 State LookupInSpecialHolder(Map* map, JSReceiver* holder); |
| 272 void RestartLookupForNonMaskingInterceptors() { | 279 void RestartLookupForNonMaskingInterceptors() { |
| 273 RestartInternal(InterceptorState::kProcessNonMasking); | 280 RestartInternal(InterceptorState::kProcessNonMasking); |
| 274 } | 281 } |
| 275 void RestartInternal(InterceptorState interceptor_state); | 282 void RestartInternal(InterceptorState interceptor_state); |
| 276 State LookupNonMaskingInterceptorInHolder(Map* map, JSReceiver* holder); | |
| 277 Handle<Object> FetchValue() const; | 283 Handle<Object> FetchValue() const; |
| 278 void ReloadPropertyInformation(); | 284 void ReloadPropertyInformation(); |
| 279 inline bool SkipInterceptor(JSObject* holder); | 285 inline bool SkipInterceptor(JSObject* holder); |
| 280 bool HasInterceptor(Map* map) const; | 286 bool HasInterceptor(Map* map) const; |
| 281 inline InterceptorInfo* GetInterceptor(JSObject* holder) const { | 287 inline InterceptorInfo* GetInterceptor(JSObject* holder) const { |
| 282 if (IsElement()) return holder->GetIndexedInterceptor(); | 288 if (IsElement()) return holder->GetIndexedInterceptor(); |
| 283 return holder->GetNamedInterceptor(); | 289 return holder->GetNamedInterceptor(); |
| 284 } | 290 } |
| 285 | 291 |
| 286 bool check_hidden() const { return (configuration_ & kHidden) != 0; } | 292 bool check_hidden() const { return (configuration_ & kHidden) != 0; } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 Handle<JSReceiver> holder_; | 344 Handle<JSReceiver> holder_; |
| 339 const Handle<JSReceiver> initial_holder_; | 345 const Handle<JSReceiver> initial_holder_; |
| 340 uint32_t number_; | 346 uint32_t number_; |
| 341 }; | 347 }; |
| 342 | 348 |
| 343 | 349 |
| 344 } // namespace internal | 350 } // namespace internal |
| 345 } // namespace v8 | 351 } // namespace v8 |
| 346 | 352 |
| 347 #endif // V8_LOOKUP_H_ | 353 #endif // V8_LOOKUP_H_ |
| OLD | NEW |