| 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 #include "src/lookup.h" | 5 #include "src/lookup.h" |
| 6 | 6 |
| 7 #include "src/bootstrapper.h" | 7 #include "src/bootstrapper.h" |
| 8 #include "src/deoptimizer.h" | 8 #include "src/deoptimizer.h" |
| 9 #include "src/elements.h" | 9 #include "src/elements.h" |
| 10 #include "src/isolate-inl.h" | 10 #include "src/isolate-inl.h" |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 Handle<JSObject> receiver = GetStoreTarget(); | 263 Handle<JSObject> receiver = GetStoreTarget(); |
| 264 if (receiver->IsJSGlobalObject()) return; | 264 if (receiver->IsJSGlobalObject()) return; |
| 265 holder_ = receiver; | 265 holder_ = receiver; |
| 266 holder_map_ = transition_map(); | 266 holder_map_ = transition_map(); |
| 267 JSObject::MigrateToMap(receiver, holder_map_); | 267 JSObject::MigrateToMap(receiver, holder_map_); |
| 268 ReloadPropertyInformation(); | 268 ReloadPropertyInformation(); |
| 269 } | 269 } |
| 270 | 270 |
| 271 | 271 |
| 272 void LookupIterator::Delete() { | 272 void LookupIterator::Delete() { |
| 273 Handle<JSObject> holder = Handle<JSObject>::cast(holder_); | 273 Handle<JSReceiver> holder = Handle<JSReceiver>::cast(holder_); |
| 274 if (IsElement()) { | 274 if (IsElement()) { |
| 275 ElementsAccessor* accessor = holder->GetElementsAccessor(); | 275 Handle<JSObject> object = Handle<JSObject>::cast(holder); |
| 276 accessor->Delete(holder, number_); | 276 ElementsAccessor* accessor = object->GetElementsAccessor(); |
| 277 accessor->Delete(object, number_); |
| 277 } else { | 278 } else { |
| 278 PropertyNormalizationMode mode = holder->map()->is_prototype_map() | 279 PropertyNormalizationMode mode = holder->map()->is_prototype_map() |
| 279 ? KEEP_INOBJECT_PROPERTIES | 280 ? KEEP_INOBJECT_PROPERTIES |
| 280 : CLEAR_INOBJECT_PROPERTIES; | 281 : CLEAR_INOBJECT_PROPERTIES; |
| 281 | 282 |
| 282 if (holder->HasFastProperties()) { | 283 if (holder->HasFastProperties()) { |
| 283 JSObject::NormalizeProperties(holder, mode, 0, "DeletingProperty"); | 284 JSObject::NormalizeProperties(Handle<JSObject>::cast(holder), mode, 0, |
| 285 "DeletingProperty"); |
| 284 holder_map_ = handle(holder->map(), isolate_); | 286 holder_map_ = handle(holder->map(), isolate_); |
| 285 ReloadPropertyInformation(); | 287 ReloadPropertyInformation(); |
| 286 } | 288 } |
| 287 // TODO(verwaest): Get rid of the name_ argument. | 289 // TODO(verwaest): Get rid of the name_ argument. |
| 288 JSObject::DeleteNormalizedProperty(holder, name_, number_); | 290 JSReceiver::DeleteNormalizedProperty(holder, name_, number_); |
| 289 JSObject::ReoptimizeIfPrototype(holder); | 291 if (holder->IsJSObject()) { |
| 292 JSObject::ReoptimizeIfPrototype(Handle<JSObject>::cast(holder)); |
| 293 } |
| 290 } | 294 } |
| 291 } | 295 } |
| 292 | 296 |
| 293 | 297 |
| 294 void LookupIterator::TransitionToAccessorProperty( | 298 void LookupIterator::TransitionToAccessorProperty( |
| 295 AccessorComponent component, Handle<Object> accessor, | 299 AccessorComponent component, Handle<Object> accessor, |
| 296 PropertyAttributes attributes) { | 300 PropertyAttributes attributes) { |
| 297 DCHECK(!accessor->IsNull()); | 301 DCHECK(!accessor->IsNull()); |
| 298 // Can only be called when the receiver is a JSObject. JSProxy has to be | 302 // Can only be called when the receiver is a JSObject. JSProxy has to be |
| 299 // handled via a trap. Adding properties to primitive values is not | 303 // handled via a trap. Adding properties to primitive values is not |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 if (iter.GetCurrent<JSReceiver>() == holder) return true; | 410 if (iter.GetCurrent<JSReceiver>() == holder) return true; |
| 407 DCHECK(!current->IsJSProxy()); | 411 DCHECK(!current->IsJSProxy()); |
| 408 iter.Advance(); | 412 iter.Advance(); |
| 409 } while (!iter.IsAtEnd(PrototypeIterator::END_AT_NON_HIDDEN)); | 413 } while (!iter.IsAtEnd(PrototypeIterator::END_AT_NON_HIDDEN)); |
| 410 return false; | 414 return false; |
| 411 } | 415 } |
| 412 | 416 |
| 413 | 417 |
| 414 Handle<Object> LookupIterator::FetchValue() const { | 418 Handle<Object> LookupIterator::FetchValue() const { |
| 415 Object* result = NULL; | 419 Object* result = NULL; |
| 416 Handle<JSObject> holder = GetHolder<JSObject>(); | |
| 417 if (IsElement()) { | 420 if (IsElement()) { |
| 421 Handle<JSObject> holder = GetHolder<JSObject>(); |
| 418 // TODO(verwaest): Optimize. | 422 // TODO(verwaest): Optimize. |
| 419 if (holder->IsStringObjectWithCharacterAt(index_)) { | 423 if (holder->IsStringObjectWithCharacterAt(index_)) { |
| 420 Handle<JSValue> js_value = Handle<JSValue>::cast(holder); | 424 Handle<JSValue> js_value = Handle<JSValue>::cast(holder); |
| 421 Handle<String> string(String::cast(js_value->value())); | 425 Handle<String> string(String::cast(js_value->value())); |
| 422 return factory()->LookupSingleCharacterStringFromCode( | 426 return factory()->LookupSingleCharacterStringFromCode( |
| 423 String::Flatten(string)->Get(index_)); | 427 String::Flatten(string)->Get(index_)); |
| 424 } | 428 } |
| 425 | 429 |
| 426 ElementsAccessor* accessor = holder->GetElementsAccessor(); | 430 ElementsAccessor* accessor = holder->GetElementsAccessor(); |
| 427 return accessor->Get(handle(holder->elements()), number_); | 431 return accessor->Get(handle(holder->elements()), number_); |
| 428 } else if (holder_map_->IsJSGlobalObjectMap()) { | 432 } else if (holder_map_->IsJSGlobalObjectMap()) { |
| 433 Handle<JSObject> holder = GetHolder<JSObject>(); |
| 429 result = holder->global_dictionary()->ValueAt(number_); | 434 result = holder->global_dictionary()->ValueAt(number_); |
| 430 DCHECK(result->IsPropertyCell()); | 435 DCHECK(result->IsPropertyCell()); |
| 431 result = PropertyCell::cast(result)->value(); | 436 result = PropertyCell::cast(result)->value(); |
| 432 } else if (holder_map_->is_dictionary_map()) { | 437 } else if (holder_map_->is_dictionary_map()) { |
| 433 result = holder->property_dictionary()->ValueAt(number_); | 438 result = holder_->property_dictionary()->ValueAt(number_); |
| 434 } else if (property_details_.type() == v8::internal::DATA) { | 439 } else if (property_details_.type() == v8::internal::DATA) { |
| 440 Handle<JSObject> holder = GetHolder<JSObject>(); |
| 435 FieldIndex field_index = FieldIndex::ForDescriptor(*holder_map_, number_); | 441 FieldIndex field_index = FieldIndex::ForDescriptor(*holder_map_, number_); |
| 436 return JSObject::FastPropertyAt(holder, property_details_.representation(), | 442 return JSObject::FastPropertyAt(holder, property_details_.representation(), |
| 437 field_index); | 443 field_index); |
| 438 } else { | 444 } else { |
| 439 result = holder_map_->instance_descriptors()->GetValue(number_); | 445 result = holder_map_->instance_descriptors()->GetValue(number_); |
| 440 } | 446 } |
| 441 return handle(result, isolate_); | 447 return handle(result, isolate_); |
| 442 } | 448 } |
| 443 | 449 |
| 444 | 450 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 | 505 |
| 500 Handle<Object> LookupIterator::GetDataValue() const { | 506 Handle<Object> LookupIterator::GetDataValue() const { |
| 501 DCHECK_EQ(DATA, state_); | 507 DCHECK_EQ(DATA, state_); |
| 502 Handle<Object> value = FetchValue(); | 508 Handle<Object> value = FetchValue(); |
| 503 return value; | 509 return value; |
| 504 } | 510 } |
| 505 | 511 |
| 506 | 512 |
| 507 void LookupIterator::WriteDataValue(Handle<Object> value) { | 513 void LookupIterator::WriteDataValue(Handle<Object> value) { |
| 508 DCHECK_EQ(DATA, state_); | 514 DCHECK_EQ(DATA, state_); |
| 509 Handle<JSObject> holder = GetHolder<JSObject>(); | 515 Handle<JSReceiver> holder = GetHolder<JSReceiver>(); |
| 510 if (IsElement()) { | 516 if (IsElement()) { |
| 511 ElementsAccessor* accessor = holder->GetElementsAccessor(); | 517 Handle<JSObject> object = Handle<JSObject>::cast(holder); |
| 512 accessor->Set(holder->elements(), number_, *value); | 518 ElementsAccessor* accessor = object->GetElementsAccessor(); |
| 519 accessor->Set(object->elements(), number_, *value); |
| 513 } else if (holder->IsJSGlobalObject()) { | 520 } else if (holder->IsJSGlobalObject()) { |
| 514 Handle<GlobalDictionary> property_dictionary = | 521 Handle<GlobalDictionary> property_dictionary = |
| 515 handle(holder->global_dictionary()); | 522 handle(JSObject::cast(*holder)->global_dictionary()); |
| 516 PropertyCell::UpdateCell(property_dictionary, dictionary_entry(), value, | 523 PropertyCell::UpdateCell(property_dictionary, dictionary_entry(), value, |
| 517 property_details_); | 524 property_details_); |
| 518 } else if (holder_map_->is_dictionary_map()) { | 525 } else if (holder_map_->is_dictionary_map()) { |
| 519 NameDictionary* property_dictionary = holder->property_dictionary(); | 526 NameDictionary* property_dictionary = holder->property_dictionary(); |
| 520 property_dictionary->ValueAtPut(dictionary_entry(), *value); | 527 property_dictionary->ValueAtPut(dictionary_entry(), *value); |
| 521 } else if (property_details_.type() == v8::internal::DATA) { | 528 } else if (property_details_.type() == v8::internal::DATA) { |
| 522 holder->WriteToField(descriptor_number(), *value); | 529 JSObject::cast(*holder)->WriteToField(descriptor_number(), *value); |
| 523 } else { | 530 } else { |
| 524 DCHECK_EQ(v8::internal::DATA_CONSTANT, property_details_.type()); | 531 DCHECK_EQ(v8::internal::DATA_CONSTANT, property_details_.type()); |
| 525 } | 532 } |
| 526 } | 533 } |
| 527 | 534 |
| 528 | 535 |
| 529 bool LookupIterator::IsIntegerIndexedExotic(JSReceiver* holder) { | 536 bool LookupIterator::IsIntegerIndexedExotic(JSReceiver* holder) { |
| 530 DCHECK(exotic_index_state_ != ExoticIndexState::kNotExotic); | 537 DCHECK(exotic_index_state_ != ExoticIndexState::kNotExotic); |
| 531 if (exotic_index_state_ == ExoticIndexState::kExotic) return true; | 538 if (exotic_index_state_ == ExoticIndexState::kExotic) return true; |
| 532 if (!InternalHolderIsReceiverOrHiddenPrototype()) { | 539 if (!InternalHolderIsReceiverOrHiddenPrototype()) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 JSReceiver* const holder) { | 611 JSReceiver* const holder) { |
| 605 STATIC_ASSERT(INTERCEPTOR == BEFORE_PROPERTY); | 612 STATIC_ASSERT(INTERCEPTOR == BEFORE_PROPERTY); |
| 606 DisallowHeapAllocation no_gc; | 613 DisallowHeapAllocation no_gc; |
| 607 if (interceptor_state_ == InterceptorState::kProcessNonMasking) { | 614 if (interceptor_state_ == InterceptorState::kProcessNonMasking) { |
| 608 return LookupNonMaskingInterceptorInHolder(map, holder); | 615 return LookupNonMaskingInterceptorInHolder(map, holder); |
| 609 } | 616 } |
| 610 switch (state_) { | 617 switch (state_) { |
| 611 case NOT_FOUND: | 618 case NOT_FOUND: |
| 612 if (map->IsJSProxyMap()) { | 619 if (map->IsJSProxyMap()) { |
| 613 // Do not leak private property names. | 620 // Do not leak private property names. |
| 614 if (!name_.is_null() && name_->IsPrivate()) return NOT_FOUND; | 621 if (IsElement() || !name_->IsPrivate()) return JSPROXY; |
| 615 return JSPROXY; | |
| 616 } | 622 } |
| 617 if (map->is_access_check_needed() && | 623 if (map->is_access_check_needed() && |
| 618 (IsElement() || !isolate_->IsInternallyUsedPropertyName(name_))) { | 624 (IsElement() || !isolate_->IsInternallyUsedPropertyName(name_))) { |
| 619 return ACCESS_CHECK; | 625 return ACCESS_CHECK; |
| 620 } | 626 } |
| 621 // Fall through. | 627 // Fall through. |
| 622 case ACCESS_CHECK: | 628 case ACCESS_CHECK: |
| 623 if (exotic_index_state_ != ExoticIndexState::kNotExotic && | 629 if (exotic_index_state_ != ExoticIndexState::kNotExotic && |
| 624 holder->IsJSTypedArray() && IsIntegerIndexedExotic(holder)) { | 630 holder->IsJSTypedArray() && IsIntegerIndexedExotic(holder)) { |
| 625 return INTEGER_INDEXED_EXOTIC; | 631 return INTEGER_INDEXED_EXOTIC; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 } else if (map->IsJSGlobalObjectMap()) { | 667 } else if (map->IsJSGlobalObjectMap()) { |
| 662 GlobalDictionary* dict = JSObject::cast(holder)->global_dictionary(); | 668 GlobalDictionary* dict = JSObject::cast(holder)->global_dictionary(); |
| 663 int number = dict->FindEntry(name_); | 669 int number = dict->FindEntry(name_); |
| 664 if (number == GlobalDictionary::kNotFound) return NOT_FOUND; | 670 if (number == GlobalDictionary::kNotFound) return NOT_FOUND; |
| 665 number_ = static_cast<uint32_t>(number); | 671 number_ = static_cast<uint32_t>(number); |
| 666 DCHECK(dict->ValueAt(number_)->IsPropertyCell()); | 672 DCHECK(dict->ValueAt(number_)->IsPropertyCell()); |
| 667 PropertyCell* cell = PropertyCell::cast(dict->ValueAt(number_)); | 673 PropertyCell* cell = PropertyCell::cast(dict->ValueAt(number_)); |
| 668 if (cell->value()->IsTheHole()) return NOT_FOUND; | 674 if (cell->value()->IsTheHole()) return NOT_FOUND; |
| 669 property_details_ = cell->property_details(); | 675 property_details_ = cell->property_details(); |
| 670 } else { | 676 } else { |
| 671 NameDictionary* dict = JSObject::cast(holder)->property_dictionary(); | 677 NameDictionary* dict = holder->property_dictionary(); |
| 672 int number = dict->FindEntry(name_); | 678 int number = dict->FindEntry(name_); |
| 673 if (number == NameDictionary::kNotFound) return NOT_FOUND; | 679 if (number == NameDictionary::kNotFound) return NOT_FOUND; |
| 674 number_ = static_cast<uint32_t>(number); | 680 number_ = static_cast<uint32_t>(number); |
| 675 property_details_ = dict->DetailsAt(number_); | 681 property_details_ = dict->DetailsAt(number_); |
| 676 } | 682 } |
| 677 has_property_ = true; | 683 has_property_ = true; |
| 678 switch (property_details_.kind()) { | 684 switch (property_details_.kind()) { |
| 679 case v8::internal::kData: | 685 case v8::internal::kData: |
| 680 return DATA; | 686 return DATA; |
| 681 case v8::internal::kAccessor: | 687 case v8::internal::kAccessor: |
| (...skipping 23 matching lines...) Expand all Loading... |
| 705 // Fall through. | 711 // Fall through. |
| 706 default: | 712 default: |
| 707 return NOT_FOUND; | 713 return NOT_FOUND; |
| 708 } | 714 } |
| 709 UNREACHABLE(); | 715 UNREACHABLE(); |
| 710 return state_; | 716 return state_; |
| 711 } | 717 } |
| 712 | 718 |
| 713 } // namespace internal | 719 } // namespace internal |
| 714 } // namespace v8 | 720 } // namespace v8 |
| OLD | NEW |