| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 <memory> | 9 #include <memory> |
| 10 #include <sstream> | 10 #include <sstream> |
| (...skipping 6117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6128 LanguageMode language_mode) { | 6128 LanguageMode language_mode) { |
| 6129 LookupIterator it = LookupIterator::PropertyOrElement( | 6129 LookupIterator it = LookupIterator::PropertyOrElement( |
| 6130 name->GetIsolate(), object, name, object, LookupIterator::OWN); | 6130 name->GetIsolate(), object, name, object, LookupIterator::OWN); |
| 6131 return DeleteProperty(&it, language_mode); | 6131 return DeleteProperty(&it, language_mode); |
| 6132 } | 6132 } |
| 6133 | 6133 |
| 6134 // ES6 19.1.2.4 | 6134 // ES6 19.1.2.4 |
| 6135 // static | 6135 // static |
| 6136 Object* JSReceiver::DefineProperty(Isolate* isolate, Handle<Object> object, | 6136 Object* JSReceiver::DefineProperty(Isolate* isolate, Handle<Object> object, |
| 6137 Handle<Object> key, | 6137 Handle<Object> key, |
| 6138 Handle<Object> attributes) { | 6138 Handle<Object> attributes, |
| 6139 CallInterceptors call_interceptors) { |
| 6139 // 1. If Type(O) is not Object, throw a TypeError exception. | 6140 // 1. If Type(O) is not Object, throw a TypeError exception. |
| 6140 if (!object->IsJSReceiver()) { | 6141 if (!object->IsJSReceiver()) { |
| 6141 Handle<String> fun_name = | 6142 Handle<String> fun_name = |
| 6142 isolate->factory()->InternalizeUtf8String("Object.defineProperty"); | 6143 isolate->factory()->InternalizeUtf8String("Object.defineProperty"); |
| 6143 THROW_NEW_ERROR_RETURN_FAILURE( | 6144 THROW_NEW_ERROR_RETURN_FAILURE( |
| 6144 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, fun_name)); | 6145 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, fun_name)); |
| 6145 } | 6146 } |
| 6146 // 2. Let key be ToPropertyKey(P). | 6147 // 2. Let key be ToPropertyKey(P). |
| 6147 // 3. ReturnIfAbrupt(key). | 6148 // 3. ReturnIfAbrupt(key). |
| 6148 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, key, ToPropertyKey(isolate, key)); | 6149 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, key, ToPropertyKey(isolate, key)); |
| 6149 // 4. Let desc be ToPropertyDescriptor(Attributes). | 6150 // 4. Let desc be ToPropertyDescriptor(Attributes). |
| 6150 // 5. ReturnIfAbrupt(desc). | 6151 // 5. ReturnIfAbrupt(desc). |
| 6151 PropertyDescriptor desc; | 6152 PropertyDescriptor desc; |
| 6152 if (!PropertyDescriptor::ToPropertyDescriptor(isolate, attributes, &desc)) { | 6153 if (!PropertyDescriptor::ToPropertyDescriptor(isolate, attributes, &desc)) { |
| 6153 return isolate->heap()->exception(); | 6154 return isolate->heap()->exception(); |
| 6154 } | 6155 } |
| 6155 // 6. Let success be DefinePropertyOrThrow(O,key, desc). | 6156 // 6. Let success be DefinePropertyOrThrow(O,key, desc). |
| 6156 Maybe<bool> success = DefineOwnProperty( | 6157 Maybe<bool> success = |
| 6157 isolate, Handle<JSReceiver>::cast(object), key, &desc, THROW_ON_ERROR); | 6158 DefineOwnProperty(isolate, Handle<JSReceiver>::cast(object), key, &desc, |
| 6159 THROW_ON_ERROR, call_interceptors); |
| 6158 // 7. ReturnIfAbrupt(success). | 6160 // 7. ReturnIfAbrupt(success). |
| 6159 MAYBE_RETURN(success, isolate->heap()->exception()); | 6161 MAYBE_RETURN(success, isolate->heap()->exception()); |
| 6160 CHECK(success.FromJust()); | 6162 CHECK(success.FromJust()); |
| 6161 // 8. Return O. | 6163 // 8. Return O. |
| 6162 return *object; | 6164 return *object; |
| 6163 } | 6165 } |
| 6164 | 6166 |
| 6165 | |
| 6166 // ES6 19.1.2.3.1 | 6167 // ES6 19.1.2.3.1 |
| 6167 // static | 6168 // static |
| 6168 MaybeHandle<Object> JSReceiver::DefineProperties(Isolate* isolate, | 6169 MaybeHandle<Object> JSReceiver::DefineProperties(Isolate* isolate, |
| 6169 Handle<Object> object, | 6170 Handle<Object> object, |
| 6170 Handle<Object> properties) { | 6171 Handle<Object> properties) { |
| 6171 // 1. If Type(O) is not Object, throw a TypeError exception. | 6172 // 1. If Type(O) is not Object, throw a TypeError exception. |
| 6172 if (!object->IsJSReceiver()) { | 6173 if (!object->IsJSReceiver()) { |
| 6173 Handle<String> fun_name = | 6174 Handle<String> fun_name = |
| 6174 isolate->factory()->InternalizeUtf8String("Object.defineProperties"); | 6175 isolate->factory()->InternalizeUtf8String("Object.defineProperties"); |
| 6175 THROW_NEW_ERROR(isolate, | 6176 THROW_NEW_ERROR(isolate, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6239 // 9. Return o. | 6240 // 9. Return o. |
| 6240 return object; | 6241 return object; |
| 6241 } | 6242 } |
| 6242 | 6243 |
| 6243 | 6244 |
| 6244 // static | 6245 // static |
| 6245 Maybe<bool> JSReceiver::DefineOwnProperty(Isolate* isolate, | 6246 Maybe<bool> JSReceiver::DefineOwnProperty(Isolate* isolate, |
| 6246 Handle<JSReceiver> object, | 6247 Handle<JSReceiver> object, |
| 6247 Handle<Object> key, | 6248 Handle<Object> key, |
| 6248 PropertyDescriptor* desc, | 6249 PropertyDescriptor* desc, |
| 6249 ShouldThrow should_throw) { | 6250 ShouldThrow should_throw, |
| 6251 CallInterceptors call_interceptors) { |
| 6250 if (object->IsJSArray()) { | 6252 if (object->IsJSArray()) { |
| 6251 return JSArray::DefineOwnProperty(isolate, Handle<JSArray>::cast(object), | 6253 return JSArray::DefineOwnProperty(isolate, Handle<JSArray>::cast(object), |
| 6252 key, desc, should_throw); | 6254 key, desc, should_throw, |
| 6255 call_interceptors); |
| 6253 } | 6256 } |
| 6254 if (object->IsJSProxy()) { | 6257 if (object->IsJSProxy()) { |
| 6255 return JSProxy::DefineOwnProperty(isolate, Handle<JSProxy>::cast(object), | 6258 return JSProxy::DefineOwnProperty(isolate, Handle<JSProxy>::cast(object), |
| 6256 key, desc, should_throw); | 6259 key, desc, should_throw, |
| 6260 call_interceptors); |
| 6257 } | 6261 } |
| 6258 if (object->IsJSTypedArray()) { | 6262 if (object->IsJSTypedArray()) { |
| 6259 return JSTypedArray::DefineOwnProperty( | 6263 return JSTypedArray::DefineOwnProperty( |
| 6260 isolate, Handle<JSTypedArray>::cast(object), key, desc, should_throw); | 6264 isolate, Handle<JSTypedArray>::cast(object), key, desc, should_throw, |
| 6265 call_interceptors); |
| 6261 } | 6266 } |
| 6262 // TODO(neis): Special case for JSModuleNamespace? | 6267 // TODO(neis): Special case for JSModuleNamespace? |
| 6263 | 6268 |
| 6264 // OrdinaryDefineOwnProperty, by virtue of calling | 6269 // OrdinaryDefineOwnProperty, by virtue of calling |
| 6265 // DefineOwnPropertyIgnoreAttributes, can handle arguments | 6270 // DefineOwnPropertyIgnoreAttributes, can handle arguments |
| 6266 // (ES#sec-arguments-exotic-objects-defineownproperty-p-desc). | 6271 // (ES#sec-arguments-exotic-objects-defineownproperty-p-desc). |
| 6267 return OrdinaryDefineOwnProperty(isolate, Handle<JSObject>::cast(object), key, | 6272 return OrdinaryDefineOwnProperty(isolate, Handle<JSObject>::cast(object), key, |
| 6268 desc, should_throw); | 6273 desc, should_throw, call_interceptors); |
| 6269 } | 6274 } |
| 6270 | 6275 |
| 6271 | |
| 6272 // static | 6276 // static |
| 6273 Maybe<bool> JSReceiver::OrdinaryDefineOwnProperty(Isolate* isolate, | 6277 Maybe<bool> JSReceiver::OrdinaryDefineOwnProperty( |
| 6274 Handle<JSObject> object, | 6278 Isolate* isolate, Handle<JSObject> object, Handle<Object> key, |
| 6275 Handle<Object> key, | 6279 PropertyDescriptor* desc, ShouldThrow should_throw, |
| 6276 PropertyDescriptor* desc, | 6280 CallInterceptors call_interceptors) { |
| 6277 ShouldThrow should_throw) { | |
| 6278 bool success = false; | 6281 bool success = false; |
| 6279 DCHECK(key->IsName() || key->IsNumber()); // |key| is a PropertyKey... | 6282 DCHECK(key->IsName() || key->IsNumber()); // |key| is a PropertyKey... |
| 6283 |
| 6284 LookupIterator::Configuration iterator_config = LookupIterator::OWN; |
| 6285 if (call_interceptors == CallInterceptors::kSkip) { |
| 6286 iterator_config = LookupIterator::OWN_SKIP_INTERCEPTOR; |
| 6287 } |
| 6288 |
| 6280 LookupIterator it = LookupIterator::PropertyOrElement( | 6289 LookupIterator it = LookupIterator::PropertyOrElement( |
| 6281 isolate, object, key, &success, LookupIterator::OWN); | 6290 isolate, object, key, &success, iterator_config); |
| 6291 |
| 6282 DCHECK(success); // ...so creating a LookupIterator can't fail. | 6292 DCHECK(success); // ...so creating a LookupIterator can't fail. |
| 6283 | 6293 |
| 6284 // Deal with access checks first. | 6294 // Deal with access checks first. |
| 6285 if (it.state() == LookupIterator::ACCESS_CHECK) { | 6295 if (it.state() == LookupIterator::ACCESS_CHECK) { |
| 6286 if (!it.HasAccess()) { | 6296 if (!it.HasAccess()) { |
| 6287 isolate->ReportFailedAccessCheck(it.GetHolder<JSObject>()); | 6297 isolate->ReportFailedAccessCheck(it.GetHolder<JSObject>()); |
| 6288 RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, Nothing<bool>()); | 6298 RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, Nothing<bool>()); |
| 6289 return Just(true); | 6299 return Just(true); |
| 6290 } | 6300 } |
| 6291 it.Next(); | 6301 it.Next(); |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6668 bool PropertyKeyToArrayIndex(Handle<Object> index_obj, uint32_t* output) { | 6678 bool PropertyKeyToArrayIndex(Handle<Object> index_obj, uint32_t* output) { |
| 6669 return PropertyKeyToArrayLength(index_obj, output) && *output != kMaxUInt32; | 6679 return PropertyKeyToArrayLength(index_obj, output) && *output != kMaxUInt32; |
| 6670 } | 6680 } |
| 6671 | 6681 |
| 6672 | 6682 |
| 6673 // ES6 9.4.2.1 | 6683 // ES6 9.4.2.1 |
| 6674 // static | 6684 // static |
| 6675 Maybe<bool> JSArray::DefineOwnProperty(Isolate* isolate, Handle<JSArray> o, | 6685 Maybe<bool> JSArray::DefineOwnProperty(Isolate* isolate, Handle<JSArray> o, |
| 6676 Handle<Object> name, | 6686 Handle<Object> name, |
| 6677 PropertyDescriptor* desc, | 6687 PropertyDescriptor* desc, |
| 6678 ShouldThrow should_throw) { | 6688 ShouldThrow should_throw, |
| 6689 CallInterceptors call_interceptors) { |
| 6679 // 1. Assert: IsPropertyKey(P) is true. ("P" is |name|.) | 6690 // 1. Assert: IsPropertyKey(P) is true. ("P" is |name|.) |
| 6680 // 2. If P is "length", then: | 6691 // 2. If P is "length", then: |
| 6681 // TODO(jkummerow): Check if we need slow string comparison. | 6692 // TODO(jkummerow): Check if we need slow string comparison. |
| 6682 if (*name == isolate->heap()->length_string()) { | 6693 if (*name == isolate->heap()->length_string()) { |
| 6683 // 2a. Return ArraySetLength(A, Desc). | 6694 // 2a. Return ArraySetLength(A, Desc). |
| 6684 return ArraySetLength(isolate, o, desc, should_throw); | 6695 return ArraySetLength(isolate, o, desc, should_throw, call_interceptors); |
| 6685 } | 6696 } |
| 6686 // 3. Else if P is an array index, then: | 6697 // 3. Else if P is an array index, then: |
| 6687 uint32_t index = 0; | 6698 uint32_t index = 0; |
| 6688 if (PropertyKeyToArrayIndex(name, &index)) { | 6699 if (PropertyKeyToArrayIndex(name, &index)) { |
| 6689 // 3a. Let oldLenDesc be OrdinaryGetOwnProperty(A, "length"). | 6700 // 3a. Let oldLenDesc be OrdinaryGetOwnProperty(A, "length"). |
| 6690 PropertyDescriptor old_len_desc; | 6701 PropertyDescriptor old_len_desc; |
| 6691 Maybe<bool> success = GetOwnPropertyDescriptor( | 6702 Maybe<bool> success = GetOwnPropertyDescriptor( |
| 6692 isolate, o, isolate->factory()->length_string(), &old_len_desc); | 6703 isolate, o, isolate->factory()->length_string(), &old_len_desc); |
| 6693 // 3b. (Assert) | 6704 // 3b. (Assert) |
| 6694 DCHECK(success.FromJust()); | 6705 DCHECK(success.FromJust()); |
| 6695 USE(success); | 6706 USE(success); |
| 6696 // 3c. Let oldLen be oldLenDesc.[[Value]]. | 6707 // 3c. Let oldLen be oldLenDesc.[[Value]]. |
| 6697 uint32_t old_len = 0; | 6708 uint32_t old_len = 0; |
| 6698 CHECK(old_len_desc.value()->ToArrayLength(&old_len)); | 6709 CHECK(old_len_desc.value()->ToArrayLength(&old_len)); |
| 6699 // 3d. Let index be ToUint32(P). | 6710 // 3d. Let index be ToUint32(P). |
| 6700 // (Already done above.) | 6711 // (Already done above.) |
| 6701 // 3e. (Assert) | 6712 // 3e. (Assert) |
| 6702 // 3f. If index >= oldLen and oldLenDesc.[[Writable]] is false, | 6713 // 3f. If index >= oldLen and oldLenDesc.[[Writable]] is false, |
| 6703 // return false. | 6714 // return false. |
| 6704 if (index >= old_len && old_len_desc.has_writable() && | 6715 if (index >= old_len && old_len_desc.has_writable() && |
| 6705 !old_len_desc.writable()) { | 6716 !old_len_desc.writable()) { |
| 6706 RETURN_FAILURE(isolate, should_throw, | 6717 RETURN_FAILURE(isolate, should_throw, |
| 6707 NewTypeError(MessageTemplate::kDefineDisallowed, name)); | 6718 NewTypeError(MessageTemplate::kDefineDisallowed, name)); |
| 6708 } | 6719 } |
| 6709 // 3g. Let succeeded be OrdinaryDefineOwnProperty(A, P, Desc). | 6720 // 3g. Let succeeded be OrdinaryDefineOwnProperty(A, P, Desc). |
| 6710 Maybe<bool> succeeded = | 6721 Maybe<bool> succeeded = OrdinaryDefineOwnProperty( |
| 6711 OrdinaryDefineOwnProperty(isolate, o, name, desc, should_throw); | 6722 isolate, o, name, desc, should_throw, call_interceptors); |
| 6712 // 3h. Assert: succeeded is not an abrupt completion. | 6723 // 3h. Assert: succeeded is not an abrupt completion. |
| 6713 // In our case, if should_throw == THROW_ON_ERROR, it can be! | 6724 // In our case, if should_throw == THROW_ON_ERROR, it can be! |
| 6714 // 3i. If succeeded is false, return false. | 6725 // 3i. If succeeded is false, return false. |
| 6715 if (succeeded.IsNothing() || !succeeded.FromJust()) return succeeded; | 6726 if (succeeded.IsNothing() || !succeeded.FromJust()) return succeeded; |
| 6716 // 3j. If index >= oldLen, then: | 6727 // 3j. If index >= oldLen, then: |
| 6717 if (index >= old_len) { | 6728 if (index >= old_len) { |
| 6718 // 3j i. Set oldLenDesc.[[Value]] to index + 1. | 6729 // 3j i. Set oldLenDesc.[[Value]] to index + 1. |
| 6719 old_len_desc.set_value(isolate->factory()->NewNumberFromUint(index + 1)); | 6730 old_len_desc.set_value(isolate->factory()->NewNumberFromUint(index + 1)); |
| 6720 // 3j ii. Let succeeded be | 6731 // 3j ii. Let succeeded be |
| 6721 // OrdinaryDefineOwnProperty(A, "length", oldLenDesc). | 6732 // OrdinaryDefineOwnProperty(A, "length", oldLenDesc). |
| 6722 succeeded = OrdinaryDefineOwnProperty(isolate, o, | 6733 succeeded = OrdinaryDefineOwnProperty( |
| 6723 isolate->factory()->length_string(), | 6734 isolate, o, isolate->factory()->length_string(), &old_len_desc, |
| 6724 &old_len_desc, should_throw); | 6735 should_throw, call_interceptors); |
| 6725 // 3j iii. Assert: succeeded is true. | 6736 // 3j iii. Assert: succeeded is true. |
| 6726 DCHECK(succeeded.FromJust()); | 6737 DCHECK(succeeded.FromJust()); |
| 6727 USE(succeeded); | 6738 USE(succeeded); |
| 6728 } | 6739 } |
| 6729 // 3k. Return true. | 6740 // 3k. Return true. |
| 6730 return Just(true); | 6741 return Just(true); |
| 6731 } | 6742 } |
| 6732 | 6743 |
| 6733 // 4. Return OrdinaryDefineOwnProperty(A, P, Desc). | 6744 // 4. Return OrdinaryDefineOwnProperty(A, P, Desc). |
| 6734 return OrdinaryDefineOwnProperty(isolate, o, name, desc, should_throw); | 6745 return OrdinaryDefineOwnProperty(isolate, o, name, desc, should_throw, |
| 6746 call_interceptors); |
| 6735 } | 6747 } |
| 6736 | 6748 |
| 6737 | 6749 |
| 6738 // Part of ES6 9.4.2.4 ArraySetLength. | 6750 // Part of ES6 9.4.2.4 ArraySetLength. |
| 6739 // static | 6751 // static |
| 6740 bool JSArray::AnythingToArrayLength(Isolate* isolate, | 6752 bool JSArray::AnythingToArrayLength(Isolate* isolate, |
| 6741 Handle<Object> length_object, | 6753 Handle<Object> length_object, |
| 6742 uint32_t* output) { | 6754 uint32_t* output) { |
| 6743 // Fast path: check numbers and strings that can be converted directly | 6755 // Fast path: check numbers and strings that can be converted directly |
| 6744 // and unobservably. | 6756 // and unobservably. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 6769 } | 6781 } |
| 6770 CHECK(uint32_v->ToArrayLength(output)); | 6782 CHECK(uint32_v->ToArrayLength(output)); |
| 6771 return true; | 6783 return true; |
| 6772 } | 6784 } |
| 6773 | 6785 |
| 6774 | 6786 |
| 6775 // ES6 9.4.2.4 | 6787 // ES6 9.4.2.4 |
| 6776 // static | 6788 // static |
| 6777 Maybe<bool> JSArray::ArraySetLength(Isolate* isolate, Handle<JSArray> a, | 6789 Maybe<bool> JSArray::ArraySetLength(Isolate* isolate, Handle<JSArray> a, |
| 6778 PropertyDescriptor* desc, | 6790 PropertyDescriptor* desc, |
| 6779 ShouldThrow should_throw) { | 6791 ShouldThrow should_throw, |
| 6792 CallInterceptors call_interceptors) { |
| 6780 // 1. If the [[Value]] field of Desc is absent, then | 6793 // 1. If the [[Value]] field of Desc is absent, then |
| 6781 if (!desc->has_value()) { | 6794 if (!desc->has_value()) { |
| 6782 // 1a. Return OrdinaryDefineOwnProperty(A, "length", Desc). | 6795 // 1a. Return OrdinaryDefineOwnProperty(A, "length", Desc). |
| 6783 return OrdinaryDefineOwnProperty( | 6796 return OrdinaryDefineOwnProperty(isolate, a, |
| 6784 isolate, a, isolate->factory()->length_string(), desc, should_throw); | 6797 isolate->factory()->length_string(), desc, |
| 6798 should_throw, call_interceptors); |
| 6785 } | 6799 } |
| 6786 // 2. Let newLenDesc be a copy of Desc. | 6800 // 2. Let newLenDesc be a copy of Desc. |
| 6787 // (Actual copying is not necessary.) | 6801 // (Actual copying is not necessary.) |
| 6788 PropertyDescriptor* new_len_desc = desc; | 6802 PropertyDescriptor* new_len_desc = desc; |
| 6789 // 3. - 7. Convert Desc.[[Value]] to newLen. | 6803 // 3. - 7. Convert Desc.[[Value]] to newLen. |
| 6790 uint32_t new_len = 0; | 6804 uint32_t new_len = 0; |
| 6791 if (!AnythingToArrayLength(isolate, desc->value(), &new_len)) { | 6805 if (!AnythingToArrayLength(isolate, desc->value(), &new_len)) { |
| 6792 DCHECK(isolate->has_pending_exception()); | 6806 DCHECK(isolate->has_pending_exception()); |
| 6793 return Nothing<bool>(); | 6807 return Nothing<bool>(); |
| 6794 } | 6808 } |
| 6795 // 8. Set newLenDesc.[[Value]] to newLen. | 6809 // 8. Set newLenDesc.[[Value]] to newLen. |
| 6796 // (Done below, if needed.) | 6810 // (Done below, if needed.) |
| 6797 // 9. Let oldLenDesc be OrdinaryGetOwnProperty(A, "length"). | 6811 // 9. Let oldLenDesc be OrdinaryGetOwnProperty(A, "length"). |
| 6798 PropertyDescriptor old_len_desc; | 6812 PropertyDescriptor old_len_desc; |
| 6799 Maybe<bool> success = GetOwnPropertyDescriptor( | 6813 Maybe<bool> success = GetOwnPropertyDescriptor( |
| 6800 isolate, a, isolate->factory()->length_string(), &old_len_desc); | 6814 isolate, a, isolate->factory()->length_string(), &old_len_desc); |
| 6801 // 10. (Assert) | 6815 // 10. (Assert) |
| 6802 DCHECK(success.FromJust()); | 6816 DCHECK(success.FromJust()); |
| 6803 USE(success); | 6817 USE(success); |
| 6804 // 11. Let oldLen be oldLenDesc.[[Value]]. | 6818 // 11. Let oldLen be oldLenDesc.[[Value]]. |
| 6805 uint32_t old_len = 0; | 6819 uint32_t old_len = 0; |
| 6806 CHECK(old_len_desc.value()->ToArrayLength(&old_len)); | 6820 CHECK(old_len_desc.value()->ToArrayLength(&old_len)); |
| 6807 // 12. If newLen >= oldLen, then | 6821 // 12. If newLen >= oldLen, then |
| 6808 if (new_len >= old_len) { | 6822 if (new_len >= old_len) { |
| 6809 // 8. Set newLenDesc.[[Value]] to newLen. | 6823 // 8. Set newLenDesc.[[Value]] to newLen. |
| 6810 // 12a. Return OrdinaryDefineOwnProperty(A, "length", newLenDesc). | 6824 // 12a. Return OrdinaryDefineOwnProperty(A, "length", newLenDesc). |
| 6811 new_len_desc->set_value(isolate->factory()->NewNumberFromUint(new_len)); | 6825 new_len_desc->set_value(isolate->factory()->NewNumberFromUint(new_len)); |
| 6812 return OrdinaryDefineOwnProperty(isolate, a, | 6826 return OrdinaryDefineOwnProperty( |
| 6813 isolate->factory()->length_string(), | 6827 isolate, a, isolate->factory()->length_string(), new_len_desc, |
| 6814 new_len_desc, should_throw); | 6828 should_throw, call_interceptors); |
| 6815 } | 6829 } |
| 6816 // 13. If oldLenDesc.[[Writable]] is false, return false. | 6830 // 13. If oldLenDesc.[[Writable]] is false, return false. |
| 6817 if (!old_len_desc.writable()) { | 6831 if (!old_len_desc.writable()) { |
| 6818 RETURN_FAILURE(isolate, should_throw, | 6832 RETURN_FAILURE(isolate, should_throw, |
| 6819 NewTypeError(MessageTemplate::kRedefineDisallowed, | 6833 NewTypeError(MessageTemplate::kRedefineDisallowed, |
| 6820 isolate->factory()->length_string())); | 6834 isolate->factory()->length_string())); |
| 6821 } | 6835 } |
| 6822 // 14. If newLenDesc.[[Writable]] is absent or has the value true, | 6836 // 14. If newLenDesc.[[Writable]] is absent or has the value true, |
| 6823 // let newWritable be true. | 6837 // let newWritable be true. |
| 6824 bool new_writable = false; | 6838 bool new_writable = false; |
| 6825 if (!new_len_desc->has_writable() || new_len_desc->writable()) { | 6839 if (!new_len_desc->has_writable() || new_len_desc->writable()) { |
| 6826 new_writable = true; | 6840 new_writable = true; |
| 6827 } else { | 6841 } else { |
| 6828 // 15. Else, | 6842 // 15. Else, |
| 6829 // 15a. Need to defer setting the [[Writable]] attribute to false in case | 6843 // 15a. Need to defer setting the [[Writable]] attribute to false in case |
| 6830 // any elements cannot be deleted. | 6844 // any elements cannot be deleted. |
| 6831 // 15b. Let newWritable be false. (It's initialized as "false" anyway.) | 6845 // 15b. Let newWritable be false. (It's initialized as "false" anyway.) |
| 6832 // 15c. Set newLenDesc.[[Writable]] to true. | 6846 // 15c. Set newLenDesc.[[Writable]] to true. |
| 6833 // (Not needed.) | 6847 // (Not needed.) |
| 6834 } | 6848 } |
| 6835 // Most of steps 16 through 19 is implemented by JSArray::SetLength. | 6849 // Most of steps 16 through 19 is implemented by JSArray::SetLength. |
| 6836 JSArray::SetLength(a, new_len); | 6850 JSArray::SetLength(a, new_len); |
| 6837 // Steps 19d-ii, 20. | 6851 // Steps 19d-ii, 20. |
| 6838 if (!new_writable) { | 6852 if (!new_writable) { |
| 6839 PropertyDescriptor readonly; | 6853 PropertyDescriptor readonly; |
| 6840 readonly.set_writable(false); | 6854 readonly.set_writable(false); |
| 6841 Maybe<bool> success = OrdinaryDefineOwnProperty( | 6855 Maybe<bool> success = OrdinaryDefineOwnProperty( |
| 6842 isolate, a, isolate->factory()->length_string(), &readonly, | 6856 isolate, a, isolate->factory()->length_string(), &readonly, |
| 6843 should_throw); | 6857 should_throw, call_interceptors); |
| 6844 DCHECK(success.FromJust()); | 6858 DCHECK(success.FromJust()); |
| 6845 USE(success); | 6859 USE(success); |
| 6846 } | 6860 } |
| 6847 uint32_t actual_new_len = 0; | 6861 uint32_t actual_new_len = 0; |
| 6848 CHECK(a->length()->ToArrayLength(&actual_new_len)); | 6862 CHECK(a->length()->ToArrayLength(&actual_new_len)); |
| 6849 // Steps 19d-v, 21. Return false if there were non-deletable elements. | 6863 // Steps 19d-v, 21. Return false if there were non-deletable elements. |
| 6850 bool result = actual_new_len == new_len; | 6864 bool result = actual_new_len == new_len; |
| 6851 if (!result) { | 6865 if (!result) { |
| 6852 RETURN_FAILURE( | 6866 RETURN_FAILURE( |
| 6853 isolate, should_throw, | 6867 isolate, should_throw, |
| 6854 NewTypeError(MessageTemplate::kStrictDeleteProperty, | 6868 NewTypeError(MessageTemplate::kStrictDeleteProperty, |
| 6855 isolate->factory()->NewNumberFromUint(actual_new_len - 1), | 6869 isolate->factory()->NewNumberFromUint(actual_new_len - 1), |
| 6856 a)); | 6870 a)); |
| 6857 } | 6871 } |
| 6858 return Just(result); | 6872 return Just(result); |
| 6859 } | 6873 } |
| 6860 | 6874 |
| 6861 | 6875 |
| 6862 // ES6 9.5.6 | 6876 // ES6 9.5.6 |
| 6863 // static | 6877 // static |
| 6864 Maybe<bool> JSProxy::DefineOwnProperty(Isolate* isolate, Handle<JSProxy> proxy, | 6878 Maybe<bool> JSProxy::DefineOwnProperty(Isolate* isolate, Handle<JSProxy> proxy, |
| 6865 Handle<Object> key, | 6879 Handle<Object> key, |
| 6866 PropertyDescriptor* desc, | 6880 PropertyDescriptor* desc, |
| 6867 ShouldThrow should_throw) { | 6881 ShouldThrow should_throw, |
| 6882 CallInterceptors call_interceptors) { |
| 6868 STACK_CHECK(isolate, Nothing<bool>()); | 6883 STACK_CHECK(isolate, Nothing<bool>()); |
| 6869 if (key->IsSymbol() && Handle<Symbol>::cast(key)->IsPrivate()) { | 6884 if (key->IsSymbol() && Handle<Symbol>::cast(key)->IsPrivate()) { |
| 6870 return SetPrivateProperty(isolate, proxy, Handle<Symbol>::cast(key), desc, | 6885 return SetPrivateProperty(isolate, proxy, Handle<Symbol>::cast(key), desc, |
| 6871 should_throw); | 6886 should_throw); |
| 6872 } | 6887 } |
| 6873 Handle<String> trap_name = isolate->factory()->defineProperty_string(); | 6888 Handle<String> trap_name = isolate->factory()->defineProperty_string(); |
| 6874 // 1. Assert: IsPropertyKey(P) is true. | 6889 // 1. Assert: IsPropertyKey(P) is true. |
| 6875 DCHECK(key->IsName() || key->IsNumber()); | 6890 DCHECK(key->IsName() || key->IsNumber()); |
| 6876 // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. | 6891 // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. |
| 6877 Handle<Object> handler(proxy->handler(), isolate); | 6892 Handle<Object> handler(proxy->handler(), isolate); |
| 6878 // 3. If handler is null, throw a TypeError exception. | 6893 // 3. If handler is null, throw a TypeError exception. |
| 6879 // 4. Assert: Type(handler) is Object. | 6894 // 4. Assert: Type(handler) is Object. |
| 6880 if (proxy->IsRevoked()) { | 6895 if (proxy->IsRevoked()) { |
| 6881 isolate->Throw(*isolate->factory()->NewTypeError( | 6896 isolate->Throw(*isolate->factory()->NewTypeError( |
| 6882 MessageTemplate::kProxyRevoked, trap_name)); | 6897 MessageTemplate::kProxyRevoked, trap_name)); |
| 6883 return Nothing<bool>(); | 6898 return Nothing<bool>(); |
| 6884 } | 6899 } |
| 6885 // 5. Let target be the value of the [[ProxyTarget]] internal slot of O. | 6900 // 5. Let target be the value of the [[ProxyTarget]] internal slot of O. |
| 6886 Handle<JSReceiver> target(proxy->target(), isolate); | 6901 Handle<JSReceiver> target(proxy->target(), isolate); |
| 6887 // 6. Let trap be ? GetMethod(handler, "defineProperty"). | 6902 // 6. Let trap be ? GetMethod(handler, "defineProperty"). |
| 6888 Handle<Object> trap; | 6903 Handle<Object> trap; |
| 6889 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 6904 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 6890 isolate, trap, | 6905 isolate, trap, |
| 6891 Object::GetMethod(Handle<JSReceiver>::cast(handler), trap_name), | 6906 Object::GetMethod(Handle<JSReceiver>::cast(handler), trap_name), |
| 6892 Nothing<bool>()); | 6907 Nothing<bool>()); |
| 6893 // 7. If trap is undefined, then: | 6908 // 7. If trap is undefined, then: |
| 6894 if (trap->IsUndefined(isolate)) { | 6909 if (trap->IsUndefined(isolate)) { |
| 6895 // 7a. Return target.[[DefineOwnProperty]](P, Desc). | 6910 // 7a. Return target.[[DefineOwnProperty]](P, Desc). |
| 6896 return JSReceiver::DefineOwnProperty(isolate, target, key, desc, | 6911 return JSReceiver::DefineOwnProperty(isolate, target, key, desc, |
| 6897 should_throw); | 6912 should_throw, call_interceptors); |
| 6898 } | 6913 } |
| 6899 // 8. Let descObj be FromPropertyDescriptor(Desc). | 6914 // 8. Let descObj be FromPropertyDescriptor(Desc). |
| 6900 Handle<Object> desc_obj = desc->ToObject(isolate); | 6915 Handle<Object> desc_obj = desc->ToObject(isolate); |
| 6901 // 9. Let booleanTrapResult be | 6916 // 9. Let booleanTrapResult be |
| 6902 // ToBoolean(? Call(trap, handler, «target, P, descObj»)). | 6917 // ToBoolean(? Call(trap, handler, «target, P, descObj»)). |
| 6903 Handle<Name> property_name = | 6918 Handle<Name> property_name = |
| 6904 key->IsName() | 6919 key->IsName() |
| 6905 ? Handle<Name>::cast(key) | 6920 ? Handle<Name>::cast(key) |
| 6906 : Handle<Name>::cast(isolate->factory()->NumberToString(key)); | 6921 : Handle<Name>::cast(isolate->factory()->NumberToString(key)); |
| 6907 // Do not leak private property names. | 6922 // Do not leak private property names. |
| (...skipping 10202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17110 } | 17125 } |
| 17111 } | 17126 } |
| 17112 *index = result; | 17127 *index = result; |
| 17113 return true; | 17128 return true; |
| 17114 } | 17129 } |
| 17115 | 17130 |
| 17116 } // anonymous namespace | 17131 } // anonymous namespace |
| 17117 | 17132 |
| 17118 // ES#sec-integer-indexed-exotic-objects-defineownproperty-p-desc | 17133 // ES#sec-integer-indexed-exotic-objects-defineownproperty-p-desc |
| 17119 // static | 17134 // static |
| 17120 Maybe<bool> JSTypedArray::DefineOwnProperty(Isolate* isolate, | 17135 Maybe<bool> JSTypedArray::DefineOwnProperty( |
| 17121 Handle<JSTypedArray> o, | 17136 Isolate* isolate, Handle<JSTypedArray> o, Handle<Object> key, |
| 17122 Handle<Object> key, | 17137 PropertyDescriptor* desc, ShouldThrow should_throw, |
| 17123 PropertyDescriptor* desc, | 17138 CallInterceptors call_interceptors) { |
| 17124 ShouldThrow should_throw) { | |
| 17125 // 1. Assert: IsPropertyKey(P) is true. | 17139 // 1. Assert: IsPropertyKey(P) is true. |
| 17126 DCHECK(key->IsName() || key->IsNumber()); | 17140 DCHECK(key->IsName() || key->IsNumber()); |
| 17127 // 2. Assert: O is an Object that has a [[ViewedArrayBuffer]] internal slot. | 17141 // 2. Assert: O is an Object that has a [[ViewedArrayBuffer]] internal slot. |
| 17128 // 3. If Type(P) is String, then | 17142 // 3. If Type(P) is String, then |
| 17129 if (key->IsString() || key->IsSmi()) { | 17143 if (key->IsString() || key->IsSmi()) { |
| 17130 // 3a. Let numericIndex be ! CanonicalNumericIndexString(P) | 17144 // 3a. Let numericIndex be ! CanonicalNumericIndexString(P) |
| 17131 // 3b. If numericIndex is not undefined, then | 17145 // 3b. If numericIndex is not undefined, then |
| 17132 Handle<Object> numeric_index; | 17146 Handle<Object> numeric_index; |
| 17133 if (CanonicalNumericIndexString(isolate, key, &numeric_index)) { | 17147 if (CanonicalNumericIndexString(isolate, key, &numeric_index)) { |
| 17134 // 3b i. If IsInteger(numericIndex) is false, return false. | 17148 // 3b i. If IsInteger(numericIndex) is false, return false. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17175 RETURN_ON_EXCEPTION_VALUE(isolate, | 17189 RETURN_ON_EXCEPTION_VALUE(isolate, |
| 17176 SetOwnElementIgnoreAttributes( | 17190 SetOwnElementIgnoreAttributes( |
| 17177 o, index, value, desc->ToAttributes()), | 17191 o, index, value, desc->ToAttributes()), |
| 17178 Nothing<bool>()); | 17192 Nothing<bool>()); |
| 17179 } | 17193 } |
| 17180 // 3b xi. Return true. | 17194 // 3b xi. Return true. |
| 17181 return Just(true); | 17195 return Just(true); |
| 17182 } | 17196 } |
| 17183 } | 17197 } |
| 17184 // 4. Return ! OrdinaryDefineOwnProperty(O, P, Desc). | 17198 // 4. Return ! OrdinaryDefineOwnProperty(O, P, Desc). |
| 17185 return OrdinaryDefineOwnProperty(isolate, o, key, desc, should_throw); | 17199 return OrdinaryDefineOwnProperty(isolate, o, key, desc, should_throw, |
| 17200 call_interceptors); |
| 17186 } | 17201 } |
| 17187 | 17202 |
| 17188 ExternalArrayType JSTypedArray::type() { | 17203 ExternalArrayType JSTypedArray::type() { |
| 17189 switch (elements()->map()->instance_type()) { | 17204 switch (elements()->map()->instance_type()) { |
| 17190 #define INSTANCE_TYPE_TO_ARRAY_TYPE(Type, type, TYPE, ctype, size) \ | 17205 #define INSTANCE_TYPE_TO_ARRAY_TYPE(Type, type, TYPE, ctype, size) \ |
| 17191 case FIXED_##TYPE##_ARRAY_TYPE: \ | 17206 case FIXED_##TYPE##_ARRAY_TYPE: \ |
| 17192 return kExternal##Type##Array; | 17207 return kExternal##Type##Array; |
| 17193 | 17208 |
| 17194 TYPED_ARRAYS(INSTANCE_TYPE_TO_ARRAY_TYPE) | 17209 TYPED_ARRAYS(INSTANCE_TYPE_TO_ARRAY_TYPE) |
| 17195 #undef INSTANCE_TYPE_TO_ARRAY_TYPE | 17210 #undef INSTANCE_TYPE_TO_ARRAY_TYPE |
| (...skipping 3189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20385 // not | 20400 // not |
| 20386 // depend on this. | 20401 // depend on this. |
| 20387 return DICTIONARY_ELEMENTS; | 20402 return DICTIONARY_ELEMENTS; |
| 20388 } | 20403 } |
| 20389 DCHECK_LE(kind, LAST_ELEMENTS_KIND); | 20404 DCHECK_LE(kind, LAST_ELEMENTS_KIND); |
| 20390 return kind; | 20405 return kind; |
| 20391 } | 20406 } |
| 20392 } | 20407 } |
| 20393 } // namespace internal | 20408 } // namespace internal |
| 20394 } // namespace v8 | 20409 } // namespace v8 |
| OLD | NEW |