OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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/objects.h" | 5 #include "src/objects.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <iomanip> | 8 #include <iomanip> |
9 #include <sstream> | 9 #include <sstream> |
10 | 10 |
(...skipping 3720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3731 LanguageMode language_mode, | 3731 LanguageMode language_mode, |
3732 StoreFromKeyed store_mode) { | 3732 StoreFromKeyed store_mode) { |
3733 ShouldThrow should_throw = | 3733 ShouldThrow should_throw = |
3734 is_sloppy(language_mode) ? DONT_THROW : THROW_ON_ERROR; | 3734 is_sloppy(language_mode) ? DONT_THROW : THROW_ON_ERROR; |
3735 | 3735 |
3736 bool found = false; | 3736 bool found = false; |
3737 Maybe<bool> result = | 3737 Maybe<bool> result = |
3738 SetPropertyInternal(it, value, language_mode, store_mode, &found); | 3738 SetPropertyInternal(it, value, language_mode, store_mode, &found); |
3739 if (found) return result; | 3739 if (found) return result; |
3740 | 3740 |
| 3741 // The property either doesn't exist on the holder or exists there as a data |
| 3742 // property. |
| 3743 |
3741 if (!it->GetReceiver()->IsJSReceiver()) { | 3744 if (!it->GetReceiver()->IsJSReceiver()) { |
3742 return WriteToReadOnlyProperty(it, value, should_throw); | 3745 return WriteToReadOnlyProperty(it, value, should_throw); |
3743 } | 3746 } |
3744 | 3747 |
3745 LookupIterator::Configuration c = LookupIterator::OWN; | 3748 LookupIterator::Configuration c = LookupIterator::OWN; |
3746 LookupIterator own_lookup = | 3749 LookupIterator own_lookup = |
3747 it->IsElement() | 3750 it->IsElement() |
3748 ? LookupIterator(it->isolate(), it->GetReceiver(), it->index(), c) | 3751 ? LookupIterator(it->isolate(), it->GetReceiver(), it->index(), c) |
3749 : LookupIterator(it->GetReceiver(), it->name(), c); | 3752 : LookupIterator(it->GetReceiver(), it->name(), c); |
3750 | 3753 |
3751 for (; own_lookup.IsFound(); own_lookup.Next()) { | 3754 for (; own_lookup.IsFound(); own_lookup.Next()) { |
3752 switch (own_lookup.state()) { | 3755 switch (own_lookup.state()) { |
3753 case LookupIterator::ACCESS_CHECK: | 3756 case LookupIterator::ACCESS_CHECK: |
3754 if (!own_lookup.HasAccess()) { | 3757 if (!own_lookup.HasAccess()) { |
3755 return JSObject::SetPropertyWithFailedAccessCheck(&own_lookup, value, | 3758 return JSObject::SetPropertyWithFailedAccessCheck(&own_lookup, value, |
3756 should_throw); | 3759 should_throw); |
3757 } | 3760 } |
3758 break; | 3761 break; |
3759 | 3762 |
3760 case LookupIterator::INTEGER_INDEXED_EXOTIC: | 3763 case LookupIterator::INTEGER_INDEXED_EXOTIC: |
3761 return RedefineNonconfigurableProperty(it->isolate(), it->GetName(), | 3764 return RedefineIncompatibleProperty(it->isolate(), it->GetName(), value, |
3762 value, should_throw); | 3765 should_throw); |
3763 | 3766 |
3764 case LookupIterator::DATA: { | 3767 case LookupIterator::DATA: { |
3765 PropertyDetails details = own_lookup.property_details(); | 3768 PropertyDetails details = own_lookup.property_details(); |
3766 if (details.IsConfigurable() || !details.IsReadOnly()) { | 3769 if (details.IsConfigurable() || !details.IsReadOnly()) { |
3767 return JSObject::DefineOwnPropertyIgnoreAttributes( | 3770 return JSObject::DefineOwnPropertyIgnoreAttributes( |
3768 &own_lookup, value, details.attributes(), should_throw); | 3771 &own_lookup, value, details.attributes(), should_throw); |
3769 } | 3772 } |
3770 return WriteToReadOnlyProperty(&own_lookup, value, should_throw); | 3773 return WriteToReadOnlyProperty(&own_lookup, value, should_throw); |
3771 } | 3774 } |
3772 | 3775 |
3773 case LookupIterator::ACCESSOR: { | 3776 case LookupIterator::ACCESSOR: { |
3774 PropertyDetails details = own_lookup.property_details(); | 3777 return RedefineIncompatibleProperty(it->isolate(), it->GetName(), value, |
3775 if (details.IsConfigurable()) { | 3778 should_throw); |
3776 return JSObject::DefineOwnPropertyIgnoreAttributes( | |
3777 &own_lookup, value, details.attributes(), should_throw); | |
3778 } | |
3779 | |
3780 return RedefineNonconfigurableProperty(it->isolate(), it->GetName(), | |
3781 value, should_throw); | |
3782 } | 3779 } |
3783 | 3780 |
3784 case LookupIterator::INTERCEPTOR: | 3781 case LookupIterator::INTERCEPTOR: |
3785 case LookupIterator::JSPROXY: { | 3782 case LookupIterator::JSPROXY: { |
3786 bool found = false; | 3783 bool found = false; |
3787 Maybe<bool> result = SetPropertyInternal( | 3784 Maybe<bool> result = SetPropertyInternal( |
3788 &own_lookup, value, language_mode, store_mode, &found); | 3785 &own_lookup, value, language_mode, store_mode, &found); |
3789 if (found) return result; | 3786 if (found) return result; |
3790 break; | 3787 break; |
3791 } | 3788 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3850 Handle<Object> receiver, | 3847 Handle<Object> receiver, |
3851 Handle<Object> name, | 3848 Handle<Object> name, |
3852 Handle<Object> value, | 3849 Handle<Object> value, |
3853 ShouldThrow should_throw) { | 3850 ShouldThrow should_throw) { |
3854 RETURN_FAILURE(isolate, should_throw, | 3851 RETURN_FAILURE(isolate, should_throw, |
3855 NewTypeError(MessageTemplate::kStrictReadOnlyProperty, name, | 3852 NewTypeError(MessageTemplate::kStrictReadOnlyProperty, name, |
3856 Object::TypeOf(isolate, receiver), receiver)); | 3853 Object::TypeOf(isolate, receiver), receiver)); |
3857 } | 3854 } |
3858 | 3855 |
3859 | 3856 |
3860 Maybe<bool> Object::RedefineNonconfigurableProperty(Isolate* isolate, | 3857 Maybe<bool> Object::RedefineIncompatibleProperty(Isolate* isolate, |
3861 Handle<Object> name, | 3858 Handle<Object> name, |
3862 Handle<Object> value, | 3859 Handle<Object> value, |
3863 ShouldThrow should_throw) { | 3860 ShouldThrow should_throw) { |
3864 RETURN_FAILURE(isolate, should_throw, | 3861 RETURN_FAILURE(isolate, should_throw, |
3865 NewTypeError(MessageTemplate::kRedefineDisallowed, name)); | 3862 NewTypeError(MessageTemplate::kRedefineDisallowed, name)); |
3866 } | 3863 } |
3867 | 3864 |
3868 | 3865 |
3869 Maybe<bool> Object::SetDataProperty(LookupIterator* it, Handle<Object> value, | 3866 Maybe<bool> Object::SetDataProperty(LookupIterator* it, Handle<Object> value, |
3870 ShouldThrow should_throw) { | 3867 ShouldThrow should_throw) { |
3871 // Proxies are handled on the WithHandler path. Other non-JSObjects cannot | 3868 // Proxies are handled on the WithHandler path. Other non-JSObjects cannot |
3872 // have own properties. | 3869 // have own properties. |
3873 Handle<JSObject> receiver = Handle<JSObject>::cast(it->GetReceiver()); | 3870 Handle<JSObject> receiver = Handle<JSObject>::cast(it->GetReceiver()); |
(...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4843 RETURN_ON_EXCEPTION_VALUE( | 4840 RETURN_ON_EXCEPTION_VALUE( |
4844 it->isolate(), | 4841 it->isolate(), |
4845 EnqueueChangeRecord(object, "reconfigure", it->GetName(), | 4842 EnqueueChangeRecord(object, "reconfigure", it->GetName(), |
4846 it->factory()->the_hole_value()), | 4843 it->factory()->the_hole_value()), |
4847 Nothing<bool>()); | 4844 Nothing<bool>()); |
4848 } | 4845 } |
4849 | 4846 |
4850 return Just(true); | 4847 return Just(true); |
4851 } | 4848 } |
4852 case LookupIterator::INTEGER_INDEXED_EXOTIC: | 4849 case LookupIterator::INTEGER_INDEXED_EXOTIC: |
4853 return RedefineNonconfigurableProperty(it->isolate(), it->GetName(), | 4850 return RedefineIncompatibleProperty(it->isolate(), it->GetName(), value, |
4854 value, should_throw); | 4851 should_throw); |
4855 | 4852 |
4856 case LookupIterator::DATA: { | 4853 case LookupIterator::DATA: { |
4857 PropertyDetails details = it->property_details(); | 4854 PropertyDetails details = it->property_details(); |
4858 Handle<Object> old_value = it->factory()->the_hole_value(); | 4855 Handle<Object> old_value = it->factory()->the_hole_value(); |
4859 // Regular property update if the attributes match. | 4856 // Regular property update if the attributes match. |
4860 if (details.attributes() == attributes) { | 4857 if (details.attributes() == attributes) { |
4861 return SetDataProperty(it, value, should_throw); | 4858 return SetDataProperty(it, value, should_throw); |
4862 } | 4859 } |
4863 | 4860 |
4864 // Special case: properties of typed arrays cannot be reconfigured to | 4861 // Special case: properties of typed arrays cannot be reconfigured to |
4865 // non-writable nor to non-enumerable. | 4862 // non-writable nor to non-enumerable. |
4866 if (it->IsElement() && object->HasFixedTypedArrayElements()) { | 4863 if (it->IsElement() && object->HasFixedTypedArrayElements()) { |
4867 return RedefineNonconfigurableProperty(it->isolate(), it->GetName(), | 4864 return RedefineIncompatibleProperty(it->isolate(), it->GetName(), |
4868 value, should_throw); | 4865 value, should_throw); |
4869 } | 4866 } |
4870 | 4867 |
4871 // Reconfigure the data property if the attributes mismatch. | 4868 // Reconfigure the data property if the attributes mismatch. |
4872 if (is_observed) old_value = it->GetDataValue(); | 4869 if (is_observed) old_value = it->GetDataValue(); |
4873 | 4870 |
4874 it->ReconfigureDataProperty(value, attributes); | 4871 it->ReconfigureDataProperty(value, attributes); |
4875 | 4872 |
4876 if (is_observed) { | 4873 if (is_observed) { |
4877 if (old_value->SameValue(*value)) { | 4874 if (old_value->SameValue(*value)) { |
4878 old_value = it->factory()->the_hole_value(); | 4875 old_value = it->factory()->the_hole_value(); |
(...skipping 13133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18012 if (cell->value() != *new_value) { | 18009 if (cell->value() != *new_value) { |
18013 cell->set_value(*new_value); | 18010 cell->set_value(*new_value); |
18014 Isolate* isolate = cell->GetIsolate(); | 18011 Isolate* isolate = cell->GetIsolate(); |
18015 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 18012 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
18016 isolate, DependentCode::kPropertyCellChangedGroup); | 18013 isolate, DependentCode::kPropertyCellChangedGroup); |
18017 } | 18014 } |
18018 } | 18015 } |
18019 | 18016 |
18020 } // namespace internal | 18017 } // namespace internal |
18021 } // namespace v8 | 18018 } // namespace v8 |
OLD | NEW |