| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 isolate_(name->GetIsolate()), | 52 isolate_(name->GetIsolate()), |
| 53 name_(isolate_->factory()->InternalizeName(name)), | 53 name_(isolate_->factory()->InternalizeName(name)), |
| 54 // kMaxUInt32 isn't a valid index. | 54 // kMaxUInt32 isn't a valid index. |
| 55 index_(kMaxUInt32), | 55 index_(kMaxUInt32), |
| 56 receiver_(receiver), | 56 receiver_(receiver), |
| 57 initial_holder_(GetRoot(isolate_, receiver)) { | 57 initial_holder_(GetRoot(isolate_, receiver)) { |
| 58 #ifdef DEBUG | 58 #ifdef DEBUG |
| 59 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. |
| 60 DCHECK(!name->AsArrayIndex(&index)); | 60 DCHECK(!name->AsArrayIndex(&index)); |
| 61 #endif // DEBUG | 61 #endif // DEBUG |
| 62 Start(); | 62 Start<false>(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 LookupIterator(Handle<Object> receiver, Handle<Name> name, | 65 LookupIterator(Handle<Object> receiver, Handle<Name> name, |
| 66 Handle<JSReceiver> holder, | 66 Handle<JSReceiver> holder, |
| 67 Configuration configuration = DEFAULT) | 67 Configuration configuration = DEFAULT) |
| 68 : configuration_(ComputeConfiguration(configuration, name)), | 68 : configuration_(ComputeConfiguration(configuration, name)), |
| 69 interceptor_state_(InterceptorState::kUninitialized), | 69 interceptor_state_(InterceptorState::kUninitialized), |
| 70 property_details_(PropertyDetails::Empty()), | 70 property_details_(PropertyDetails::Empty()), |
| 71 isolate_(name->GetIsolate()), | 71 isolate_(name->GetIsolate()), |
| 72 name_(isolate_->factory()->InternalizeName(name)), | 72 name_(isolate_->factory()->InternalizeName(name)), |
| 73 // kMaxUInt32 isn't a valid index. | 73 // kMaxUInt32 isn't a valid index. |
| 74 index_(kMaxUInt32), | 74 index_(kMaxUInt32), |
| 75 receiver_(receiver), | 75 receiver_(receiver), |
| 76 initial_holder_(holder) { | 76 initial_holder_(holder) { |
| 77 #ifdef DEBUG | 77 #ifdef DEBUG |
| 78 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. |
| 79 DCHECK(!name->AsArrayIndex(&index)); | 79 DCHECK(!name->AsArrayIndex(&index)); |
| 80 #endif // DEBUG | 80 #endif // DEBUG |
| 81 Start(); | 81 Start<false>(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 LookupIterator(Isolate* isolate, Handle<Object> receiver, uint32_t index, | 84 LookupIterator(Isolate* isolate, Handle<Object> receiver, uint32_t index, |
| 85 Configuration configuration = DEFAULT) | 85 Configuration configuration = DEFAULT) |
| 86 : configuration_(configuration), | 86 : configuration_(configuration), |
| 87 interceptor_state_(InterceptorState::kUninitialized), | 87 interceptor_state_(InterceptorState::kUninitialized), |
| 88 property_details_(PropertyDetails::Empty()), | 88 property_details_(PropertyDetails::Empty()), |
| 89 isolate_(isolate), | 89 isolate_(isolate), |
| 90 name_(), | 90 name_(), |
| 91 index_(index), | 91 index_(index), |
| 92 receiver_(receiver), | 92 receiver_(receiver), |
| 93 initial_holder_(GetRoot(isolate, receiver, index)) { | 93 initial_holder_(GetRoot(isolate, receiver, index)) { |
| 94 // kMaxUInt32 isn't a valid index. | 94 // kMaxUInt32 isn't a valid index. |
| 95 DCHECK_NE(kMaxUInt32, index_); | 95 DCHECK_NE(kMaxUInt32, index_); |
| 96 Start(); | 96 Start<true>(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 LookupIterator(Isolate* isolate, Handle<Object> receiver, uint32_t index, | 99 LookupIterator(Isolate* isolate, Handle<Object> receiver, uint32_t index, |
| 100 Handle<JSReceiver> holder, | 100 Handle<JSReceiver> holder, |
| 101 Configuration configuration = DEFAULT) | 101 Configuration configuration = DEFAULT) |
| 102 : configuration_(configuration), | 102 : configuration_(configuration), |
| 103 interceptor_state_(InterceptorState::kUninitialized), | 103 interceptor_state_(InterceptorState::kUninitialized), |
| 104 property_details_(PropertyDetails::Empty()), | 104 property_details_(PropertyDetails::Empty()), |
| 105 isolate_(isolate), | 105 isolate_(isolate), |
| 106 name_(), | 106 name_(), |
| 107 index_(index), | 107 index_(index), |
| 108 receiver_(receiver), | 108 receiver_(receiver), |
| 109 initial_holder_(holder) { | 109 initial_holder_(holder) { |
| 110 // kMaxUInt32 isn't a valid index. | 110 // kMaxUInt32 isn't a valid index. |
| 111 DCHECK_NE(kMaxUInt32, index_); | 111 DCHECK_NE(kMaxUInt32, index_); |
| 112 Start(); | 112 Start<true>(); |
| 113 } | 113 } |
| 114 | 114 |
| 115 static LookupIterator PropertyOrElement( | 115 static LookupIterator PropertyOrElement( |
| 116 Isolate* isolate, Handle<Object> receiver, Handle<Name> name, | 116 Isolate* isolate, Handle<Object> receiver, Handle<Name> name, |
| 117 Configuration configuration = DEFAULT) { | 117 Configuration configuration = DEFAULT) { |
| 118 uint32_t index; | 118 uint32_t index; |
| 119 if (name->AsArrayIndex(&index)) { | 119 if (name->AsArrayIndex(&index)) { |
| 120 LookupIterator it = | 120 LookupIterator it = |
| 121 LookupIterator(isolate, receiver, index, configuration); | 121 LookupIterator(isolate, receiver, index, configuration); |
| 122 it.name_ = name; | 122 it.name_ = name; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 135 it.name_ = name; | 135 it.name_ = name; |
| 136 return it; | 136 return it; |
| 137 } | 137 } |
| 138 return LookupIterator(receiver, name, holder, configuration); | 138 return LookupIterator(receiver, name, holder, configuration); |
| 139 } | 139 } |
| 140 | 140 |
| 141 static LookupIterator PropertyOrElement( | 141 static LookupIterator PropertyOrElement( |
| 142 Isolate* isolate, Handle<Object> receiver, Handle<Object> key, | 142 Isolate* isolate, Handle<Object> receiver, Handle<Object> key, |
| 143 bool* success, Configuration configuration = DEFAULT); | 143 bool* success, Configuration configuration = DEFAULT); |
| 144 | 144 |
| 145 void Restart() { RestartInternal(InterceptorState::kUninitialized); } | 145 void Restart() { |
| 146 InterceptorState state = InterceptorState::kUninitialized; |
| 147 IsElement() ? RestartInternal<true>(state) : RestartInternal<false>(state); |
| 148 } |
| 146 | 149 |
| 147 Isolate* isolate() const { return isolate_; } | 150 Isolate* isolate() const { return isolate_; } |
| 148 State state() const { return state_; } | 151 State state() const { return state_; } |
| 149 | 152 |
| 150 Handle<Name> name() const { | 153 Handle<Name> name() const { |
| 151 DCHECK(!IsElement()); | 154 DCHECK(!IsElement()); |
| 152 return name_; | 155 return name_; |
| 153 } | 156 } |
| 154 Handle<Name> GetName() { | 157 Handle<Name> GetName() { |
| 155 if (name_.is_null()) { | 158 if (name_.is_null()) { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 Handle<Object> GetAccessors() const; | 253 Handle<Object> GetAccessors() const; |
| 251 inline Handle<InterceptorInfo> GetInterceptor() const { | 254 inline Handle<InterceptorInfo> GetInterceptor() const { |
| 252 DCHECK_EQ(INTERCEPTOR, state_); | 255 DCHECK_EQ(INTERCEPTOR, state_); |
| 253 return handle(GetInterceptor(JSObject::cast(*holder_)), isolate_); | 256 return handle(GetInterceptor(JSObject::cast(*holder_)), isolate_); |
| 254 } | 257 } |
| 255 Handle<Object> GetDataValue() const; | 258 Handle<Object> GetDataValue() const; |
| 256 void WriteDataValue(Handle<Object> value); | 259 void WriteDataValue(Handle<Object> value); |
| 257 void UpdateProtector(); | 260 void UpdateProtector(); |
| 258 | 261 |
| 259 private: | 262 private: |
| 260 void Start(); | |
| 261 void NextInternal(Map* map, JSReceiver* holder); | |
| 262 | |
| 263 enum class InterceptorState { | 263 enum class InterceptorState { |
| 264 kUninitialized, | 264 kUninitialized, |
| 265 kSkipNonMasking, | 265 kSkipNonMasking, |
| 266 kProcessNonMasking | 266 kProcessNonMasking |
| 267 }; | 267 }; |
| 268 | 268 |
| 269 Handle<Map> GetReceiverMap() const; | 269 Handle<Map> GetReceiverMap() const; |
| 270 | 270 |
| 271 MUST_USE_RESULT inline JSReceiver* NextHolder(Map* map); | 271 MUST_USE_RESULT inline JSReceiver* NextHolder(Map* map); |
| 272 |
| 273 template <bool is_element> |
| 274 void Start(); |
| 275 template <bool is_element> |
| 276 void NextInternal(Map* map, JSReceiver* holder); |
| 277 template <bool is_element> |
| 272 inline State LookupInHolder(Map* map, JSReceiver* holder) { | 278 inline State LookupInHolder(Map* map, JSReceiver* holder) { |
| 273 return map->instance_type() <= LAST_SPECIAL_RECEIVER_TYPE | 279 return map->instance_type() <= LAST_SPECIAL_RECEIVER_TYPE |
| 274 ? LookupInSpecialHolder(map, holder) | 280 ? LookupInSpecialHolder<is_element>(map, holder) |
| 275 : LookupInRegularHolder(map, holder); | 281 : LookupInRegularHolder<is_element>(map, holder); |
| 276 } | 282 } |
| 283 template <bool is_element> |
| 277 State LookupInRegularHolder(Map* map, JSReceiver* holder); | 284 State LookupInRegularHolder(Map* map, JSReceiver* holder); |
| 285 template <bool is_element> |
| 278 State LookupInSpecialHolder(Map* map, JSReceiver* holder); | 286 State LookupInSpecialHolder(Map* map, JSReceiver* holder); |
| 287 template <bool is_element> |
| 279 void RestartLookupForNonMaskingInterceptors() { | 288 void RestartLookupForNonMaskingInterceptors() { |
| 280 RestartInternal(InterceptorState::kProcessNonMasking); | 289 RestartInternal<is_element>(InterceptorState::kProcessNonMasking); |
| 281 } | 290 } |
| 291 template <bool is_element> |
| 282 void RestartInternal(InterceptorState interceptor_state); | 292 void RestartInternal(InterceptorState interceptor_state); |
| 283 Handle<Object> FetchValue() const; | 293 Handle<Object> FetchValue() const; |
| 294 template <bool is_element> |
| 284 void ReloadPropertyInformation(); | 295 void ReloadPropertyInformation(); |
| 296 |
| 285 inline bool SkipInterceptor(JSObject* holder); | 297 inline bool SkipInterceptor(JSObject* holder); |
| 286 bool HasInterceptor(Map* map) const; | |
| 287 inline InterceptorInfo* GetInterceptor(JSObject* holder) const { | 298 inline InterceptorInfo* GetInterceptor(JSObject* holder) const { |
| 288 if (IsElement()) return holder->GetIndexedInterceptor(); | 299 if (IsElement()) return holder->GetIndexedInterceptor(); |
| 289 return holder->GetNamedInterceptor(); | 300 return holder->GetNamedInterceptor(); |
| 290 } | 301 } |
| 291 | 302 |
| 292 bool check_hidden() const { return (configuration_ & kHidden) != 0; } | 303 bool check_hidden() const { return (configuration_ & kHidden) != 0; } |
| 293 bool check_interceptor() const { | 304 bool check_interceptor() const { |
| 294 return (configuration_ & kInterceptor) != 0; | 305 return (configuration_ & kInterceptor) != 0; |
| 295 } | 306 } |
| 296 int descriptor_number() const { | 307 int descriptor_number() const { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 Handle<JSReceiver> holder_; | 355 Handle<JSReceiver> holder_; |
| 345 const Handle<JSReceiver> initial_holder_; | 356 const Handle<JSReceiver> initial_holder_; |
| 346 uint32_t number_; | 357 uint32_t number_; |
| 347 }; | 358 }; |
| 348 | 359 |
| 349 | 360 |
| 350 } // namespace internal | 361 } // namespace internal |
| 351 } // namespace v8 | 362 } // namespace v8 |
| 352 | 363 |
| 353 #endif // V8_LOOKUP_H_ | 364 #endif // V8_LOOKUP_H_ |
| OLD | NEW |