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 6110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6121 // 6. Let success be DefinePropertyOrThrow(O,key, desc). | 6121 // 6. Let success be DefinePropertyOrThrow(O,key, desc). |
6122 Maybe<bool> success = DefineOwnProperty( | 6122 Maybe<bool> success = DefineOwnProperty( |
6123 isolate, Handle<JSReceiver>::cast(object), key, &desc, THROW_ON_ERROR); | 6123 isolate, Handle<JSReceiver>::cast(object), key, &desc, THROW_ON_ERROR); |
6124 // 7. ReturnIfAbrupt(success). | 6124 // 7. ReturnIfAbrupt(success). |
6125 MAYBE_RETURN(success, isolate->heap()->exception()); | 6125 MAYBE_RETURN(success, isolate->heap()->exception()); |
6126 CHECK(success.FromJust()); | 6126 CHECK(success.FromJust()); |
6127 // 8. Return O. | 6127 // 8. Return O. |
6128 return *object; | 6128 return *object; |
6129 } | 6129 } |
6130 | 6130 |
| 6131 Object* JSReceiver::DefinePropertyWithoutInterceptors( |
| 6132 Isolate* isolate, Handle<Object> object, Handle<Object> key, |
| 6133 Handle<Object> attributes) { |
| 6134 // 1. If Type(O) is not Object, throw a TypeError exception. |
| 6135 if (!object->IsJSReceiver()) { |
| 6136 Handle<String> fun_name = isolate->factory()->InternalizeUtf8String( |
| 6137 "Object.definePropertyWithoutInterceptors"); |
| 6138 THROW_NEW_ERROR_RETURN_FAILURE( |
| 6139 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, fun_name)); |
| 6140 } |
| 6141 // 2. Let key be ToPropertyKey(P). |
| 6142 // 3. ReturnIfAbrupt(key). |
| 6143 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, key, ToPropertyKey(isolate, key)); |
| 6144 // 4. Let desc be ToPropertyDescriptor(Attributes). |
| 6145 // 5. ReturnIfAbrupt(desc). |
| 6146 PropertyDescriptor desc; |
| 6147 if (!PropertyDescriptor::ToPropertyDescriptor(isolate, attributes, &desc)) { |
| 6148 return isolate->heap()->exception(); |
| 6149 } |
| 6150 // 6. Let success be DefinePropertyOrThrow(O,key, desc). |
| 6151 Maybe<bool> success = OrdinaryDefineOwnPropertyWithoutIntercept( |
| 6152 isolate, Handle<JSObject>::cast(object), key, &desc, THROW_ON_ERROR); |
| 6153 |
| 6154 // 7. ReturnIfAbrupt(success). |
| 6155 MAYBE_RETURN(success, isolate->heap()->exception()); |
| 6156 CHECK(success.FromJust()); |
| 6157 // 8. Return O. |
| 6158 return *object; |
| 6159 } |
6131 | 6160 |
6132 // ES6 19.1.2.3.1 | 6161 // ES6 19.1.2.3.1 |
6133 // static | 6162 // static |
6134 MaybeHandle<Object> JSReceiver::DefineProperties(Isolate* isolate, | 6163 MaybeHandle<Object> JSReceiver::DefineProperties(Isolate* isolate, |
6135 Handle<Object> object, | 6164 Handle<Object> object, |
6136 Handle<Object> properties) { | 6165 Handle<Object> properties) { |
6137 // 1. If Type(O) is not Object, throw a TypeError exception. | 6166 // 1. If Type(O) is not Object, throw a TypeError exception. |
6138 if (!object->IsJSReceiver()) { | 6167 if (!object->IsJSReceiver()) { |
6139 Handle<String> fun_name = | 6168 Handle<String> fun_name = |
6140 isolate->factory()->InternalizeUtf8String("Object.defineProperties"); | 6169 isolate->factory()->InternalizeUtf8String("Object.defineProperties"); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6229 | 6258 |
6230 // OrdinaryDefineOwnProperty, by virtue of calling | 6259 // OrdinaryDefineOwnProperty, by virtue of calling |
6231 // DefineOwnPropertyIgnoreAttributes, can handle arguments | 6260 // DefineOwnPropertyIgnoreAttributes, can handle arguments |
6232 // (ES#sec-arguments-exotic-objects-defineownproperty-p-desc). | 6261 // (ES#sec-arguments-exotic-objects-defineownproperty-p-desc). |
6233 return OrdinaryDefineOwnProperty(isolate, Handle<JSObject>::cast(object), key, | 6262 return OrdinaryDefineOwnProperty(isolate, Handle<JSObject>::cast(object), key, |
6234 desc, should_throw); | 6263 desc, should_throw); |
6235 } | 6264 } |
6236 | 6265 |
6237 | 6266 |
6238 // static | 6267 // static |
| 6268 Maybe<bool> JSReceiver::DefineOwnPropertyWithoutIntercept( |
| 6269 Isolate* isolate, Handle<JSReceiver> object, Handle<Object> key, |
| 6270 PropertyDescriptor* desc, ShouldThrow should_throw) { |
| 6271 if (object->IsJSArray()) { |
| 6272 return JSArray::DefineOwnPropertyWithoutIntercept( |
| 6273 isolate, Handle<JSArray>::cast(object), key, desc, should_throw); |
| 6274 } |
| 6275 if (object->IsJSProxy()) { |
| 6276 return JSProxy::DefineOwnPropertyWithoutIntercept( |
| 6277 isolate, Handle<JSProxy>::cast(object), key, desc, should_throw); |
| 6278 } |
| 6279 if (object->IsJSTypedArray()) { |
| 6280 return JSTypedArray::DefineOwnPropertyWithoutIntercept( |
| 6281 isolate, Handle<JSTypedArray>::cast(object), key, desc, should_throw); |
| 6282 } |
| 6283 // TODO(neis): Special case for JSModuleNamespace? |
| 6284 |
| 6285 // OrdinaryDefineOwnProperty, by virtue of calling |
| 6286 // DefineOwnPropertyIgnoreAttributes, can handle arguments |
| 6287 // (ES#sec-arguments-exotic-objects-defineownproperty-p-desc). |
| 6288 return OrdinaryDefineOwnPropertyWithoutIntercept( |
| 6289 isolate, Handle<JSObject>::cast(object), key, desc, should_throw); |
| 6290 } |
| 6291 |
| 6292 // static |
6239 Maybe<bool> JSReceiver::OrdinaryDefineOwnProperty(Isolate* isolate, | 6293 Maybe<bool> JSReceiver::OrdinaryDefineOwnProperty(Isolate* isolate, |
6240 Handle<JSObject> object, | 6294 Handle<JSObject> object, |
6241 Handle<Object> key, | 6295 Handle<Object> key, |
6242 PropertyDescriptor* desc, | 6296 PropertyDescriptor* desc, |
6243 ShouldThrow should_throw) { | 6297 ShouldThrow should_throw) { |
6244 bool success = false; | 6298 bool success = false; |
6245 DCHECK(key->IsName() || key->IsNumber()); // |key| is a PropertyKey... | 6299 DCHECK(key->IsName() || key->IsNumber()); // |key| is a PropertyKey... |
6246 LookupIterator it = LookupIterator::PropertyOrElement( | 6300 LookupIterator it = LookupIterator::PropertyOrElement( |
6247 isolate, object, key, &success, LookupIterator::OWN); | 6301 isolate, object, key, &success, LookupIterator::OWN); |
6248 DCHECK(success); // ...so creating a LookupIterator can't fail. | 6302 DCHECK(success); // ...so creating a LookupIterator can't fail. |
(...skipping 15 matching lines...) Expand all Loading... |
6264 &it, it.GetInterceptor(), should_throw, *desc); | 6318 &it, it.GetInterceptor(), should_throw, *desc); |
6265 if (result.IsNothing() || result.FromJust()) { | 6319 if (result.IsNothing() || result.FromJust()) { |
6266 return result; | 6320 return result; |
6267 } | 6321 } |
6268 } | 6322 } |
6269 } | 6323 } |
6270 | 6324 |
6271 return OrdinaryDefineOwnProperty(&it, desc, should_throw); | 6325 return OrdinaryDefineOwnProperty(&it, desc, should_throw); |
6272 } | 6326 } |
6273 | 6327 |
| 6328 // static |
| 6329 Maybe<bool> JSReceiver::OrdinaryDefineOwnPropertyWithoutIntercept( |
| 6330 Isolate* isolate, Handle<JSObject> object, Handle<Object> key, |
| 6331 PropertyDescriptor* desc, ShouldThrow should_throw) { |
| 6332 bool success = false; |
| 6333 DCHECK(key->IsName() || key->IsNumber()); // |key| is a PropertyKey... |
| 6334 LookupIterator it = LookupIterator::PropertyOrElement( |
| 6335 isolate, object, key, &success, LookupIterator::OWN_SKIP_INTERCEPTOR); |
| 6336 DCHECK(success); // ...so creating a LookupIterator can't fail. |
| 6337 |
| 6338 // Deal with access checks first. |
| 6339 if (it.state() == LookupIterator::ACCESS_CHECK) { |
| 6340 if (!it.HasAccess()) { |
| 6341 isolate->ReportFailedAccessCheck(it.GetHolder<JSObject>()); |
| 6342 RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, Nothing<bool>()); |
| 6343 return Just(true); |
| 6344 } |
| 6345 it.Next(); |
| 6346 } |
| 6347 |
| 6348 return OrdinaryDefineOwnProperty(&it, desc, should_throw); |
| 6349 } |
6274 | 6350 |
6275 // ES6 9.1.6.1 | 6351 // ES6 9.1.6.1 |
6276 // static | 6352 // static |
6277 Maybe<bool> JSReceiver::OrdinaryDefineOwnProperty(LookupIterator* it, | 6353 Maybe<bool> JSReceiver::OrdinaryDefineOwnProperty(LookupIterator* it, |
6278 PropertyDescriptor* desc, | 6354 PropertyDescriptor* desc, |
6279 ShouldThrow should_throw) { | 6355 ShouldThrow should_throw) { |
6280 Isolate* isolate = it->isolate(); | 6356 Isolate* isolate = it->isolate(); |
6281 // 1. Let current be O.[[GetOwnProperty]](P). | 6357 // 1. Let current be O.[[GetOwnProperty]](P). |
6282 // 2. ReturnIfAbrupt(current). | 6358 // 2. ReturnIfAbrupt(current). |
6283 PropertyDescriptor current; | 6359 PropertyDescriptor current; |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6693 USE(succeeded); | 6769 USE(succeeded); |
6694 } | 6770 } |
6695 // 3k. Return true. | 6771 // 3k. Return true. |
6696 return Just(true); | 6772 return Just(true); |
6697 } | 6773 } |
6698 | 6774 |
6699 // 4. Return OrdinaryDefineOwnProperty(A, P, Desc). | 6775 // 4. Return OrdinaryDefineOwnProperty(A, P, Desc). |
6700 return OrdinaryDefineOwnProperty(isolate, o, name, desc, should_throw); | 6776 return OrdinaryDefineOwnProperty(isolate, o, name, desc, should_throw); |
6701 } | 6777 } |
6702 | 6778 |
| 6779 // static |
| 6780 Maybe<bool> JSArray::DefineOwnPropertyWithoutIntercept( |
| 6781 Isolate* isolate, Handle<JSArray> o, Handle<Object> name, |
| 6782 PropertyDescriptor* desc, ShouldThrow should_throw) { |
| 6783 // 1. Assert: IsPropertyKey(P) is true. ("P" is |name|.) |
| 6784 // 2. If P is "length", then: |
| 6785 // TODO(jkummerow): Check if we need slow string comparison. |
| 6786 if (*name == isolate->heap()->length_string()) { |
| 6787 // 2a. Return ArraySetLength(A, Desc). |
| 6788 return ArraySetLength(isolate, o, desc, should_throw); |
| 6789 } |
| 6790 // 3. Else if P is an array index, then: |
| 6791 uint32_t index = 0; |
| 6792 if (PropertyKeyToArrayIndex(name, &index)) { |
| 6793 // 3a. Let oldLenDesc be OrdinaryGetOwnProperty(A, "length"). |
| 6794 PropertyDescriptor old_len_desc; |
| 6795 Maybe<bool> success = GetOwnPropertyDescriptor( |
| 6796 isolate, o, isolate->factory()->length_string(), &old_len_desc); |
| 6797 // 3b. (Assert) |
| 6798 DCHECK(success.FromJust()); |
| 6799 USE(success); |
| 6800 // 3c. Let oldLen be oldLenDesc.[[Value]]. |
| 6801 uint32_t old_len = 0; |
| 6802 CHECK(old_len_desc.value()->ToArrayLength(&old_len)); |
| 6803 // 3d. Let index be ToUint32(P). |
| 6804 // (Already done above.) |
| 6805 // 3e. (Assert) |
| 6806 // 3f. If index >= oldLen and oldLenDesc.[[Writable]] is false, |
| 6807 // return false. |
| 6808 if (index >= old_len && old_len_desc.has_writable() && |
| 6809 !old_len_desc.writable()) { |
| 6810 RETURN_FAILURE(isolate, should_throw, |
| 6811 NewTypeError(MessageTemplate::kDefineDisallowed, name)); |
| 6812 } |
| 6813 // 3g. Let succeeded be OrdinaryDefineOwnPropertyWithoutIntercept(A, P, |
| 6814 // Desc). |
| 6815 Maybe<bool> succeeded = OrdinaryDefineOwnPropertyWithoutIntercept( |
| 6816 isolate, o, name, desc, should_throw); |
| 6817 // 3h. Assert: succeeded is not an abrupt completion. |
| 6818 // In our case, if should_throw == THROW_ON_ERROR, it can be! |
| 6819 // 3i. If succeeded is false, return false. |
| 6820 if (succeeded.IsNothing() || !succeeded.FromJust()) return succeeded; |
| 6821 // 3j. If index >= oldLen, then: |
| 6822 if (index >= old_len) { |
| 6823 // 3j i. Set oldLenDesc.[[Value]] to index + 1. |
| 6824 old_len_desc.set_value(isolate->factory()->NewNumberFromUint(index + 1)); |
| 6825 // 3j ii. Let succeeded be |
| 6826 // OrdinaryDefineOwnProperty(A, "length", oldLenDesc). |
| 6827 succeeded = OrdinaryDefineOwnPropertyWithoutIntercept( |
| 6828 isolate, o, isolate->factory()->length_string(), &old_len_desc, |
| 6829 should_throw); |
| 6830 // 3j iii. Assert: succeeded is true. |
| 6831 DCHECK(succeeded.FromJust()); |
| 6832 USE(succeeded); |
| 6833 } |
| 6834 // 3k. Return true. |
| 6835 return Just(true); |
| 6836 } |
| 6837 |
| 6838 // 4. Return OrdinaryDefineOwnProperty(A, P, Desc). |
| 6839 return OrdinaryDefineOwnPropertyWithoutIntercept(isolate, o, name, desc, |
| 6840 should_throw); |
| 6841 } |
6703 | 6842 |
6704 // Part of ES6 9.4.2.4 ArraySetLength. | 6843 // Part of ES6 9.4.2.4 ArraySetLength. |
6705 // static | 6844 // static |
6706 bool JSArray::AnythingToArrayLength(Isolate* isolate, | 6845 bool JSArray::AnythingToArrayLength(Isolate* isolate, |
6707 Handle<Object> length_object, | 6846 Handle<Object> length_object, |
6708 uint32_t* output) { | 6847 uint32_t* output) { |
6709 // Fast path: check numbers and strings that can be converted directly | 6848 // Fast path: check numbers and strings that can be converted directly |
6710 // and unobservably. | 6849 // and unobservably. |
6711 if (length_object->ToArrayLength(output)) return true; | 6850 if (length_object->ToArrayLength(output)) return true; |
6712 if (length_object->IsString() && | 6851 if (length_object->IsString() && |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6932 MessageTemplate::kProxyDefinePropertyNonConfigurable, property_name)); | 7071 MessageTemplate::kProxyDefinePropertyNonConfigurable, property_name)); |
6933 return Nothing<bool>(); | 7072 return Nothing<bool>(); |
6934 } | 7073 } |
6935 } | 7074 } |
6936 // 17. Return true. | 7075 // 17. Return true. |
6937 return Just(true); | 7076 return Just(true); |
6938 } | 7077 } |
6939 | 7078 |
6940 | 7079 |
6941 // static | 7080 // static |
| 7081 Maybe<bool> JSProxy::DefineOwnPropertyWithoutIntercept( |
| 7082 Isolate* isolate, Handle<JSProxy> proxy, Handle<Object> key, |
| 7083 PropertyDescriptor* desc, ShouldThrow should_throw) { |
| 7084 STACK_CHECK(isolate, Nothing<bool>()); |
| 7085 if (key->IsSymbol() && Handle<Symbol>::cast(key)->IsPrivate()) { |
| 7086 return SetPrivateProperty(isolate, proxy, Handle<Symbol>::cast(key), desc, |
| 7087 should_throw); |
| 7088 } |
| 7089 Handle<String> trap_name = isolate->factory()->defineProperty_string(); |
| 7090 // 1. Assert: IsPropertyKey(P) is true. |
| 7091 DCHECK(key->IsName() || key->IsNumber()); |
| 7092 // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. |
| 7093 Handle<Object> handler(proxy->handler(), isolate); |
| 7094 // 3. If handler is null, throw a TypeError exception. |
| 7095 // 4. Assert: Type(handler) is Object. |
| 7096 if (proxy->IsRevoked()) { |
| 7097 isolate->Throw(*isolate->factory()->NewTypeError( |
| 7098 MessageTemplate::kProxyRevoked, trap_name)); |
| 7099 return Nothing<bool>(); |
| 7100 } |
| 7101 // 5. Let target be the value of the [[ProxyTarget]] internal slot of O. |
| 7102 Handle<JSReceiver> target(proxy->target(), isolate); |
| 7103 // 6. Let trap be ? GetMethod(handler, "defineProperty"). |
| 7104 Handle<Object> trap; |
| 7105 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 7106 isolate, trap, |
| 7107 Object::GetMethod(Handle<JSReceiver>::cast(handler), trap_name), |
| 7108 Nothing<bool>()); |
| 7109 // 7. If trap is undefined, then: |
| 7110 if (trap->IsUndefined(isolate)) { |
| 7111 // 7a. Return target.[[DefineOwnProperty]](P, Desc). |
| 7112 return JSReceiver::DefineOwnPropertyWithoutIntercept(isolate, target, key, |
| 7113 desc, should_throw); |
| 7114 } |
| 7115 // 8. Let descObj be FromPropertyDescriptor(Desc). |
| 7116 Handle<Object> desc_obj = desc->ToObject(isolate); |
| 7117 // 9. Let booleanTrapResult be |
| 7118 // ToBoolean(? Call(trap, handler, «target, P, descObj»)). |
| 7119 Handle<Name> property_name = |
| 7120 key->IsName() |
| 7121 ? Handle<Name>::cast(key) |
| 7122 : Handle<Name>::cast(isolate->factory()->NumberToString(key)); |
| 7123 // Do not leak private property names. |
| 7124 DCHECK(!property_name->IsPrivate()); |
| 7125 Handle<Object> trap_result_obj; |
| 7126 Handle<Object> args[] = {target, property_name, desc_obj}; |
| 7127 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 7128 isolate, trap_result_obj, |
| 7129 Execution::Call(isolate, trap, handler, arraysize(args), args), |
| 7130 Nothing<bool>()); |
| 7131 // 10. If booleanTrapResult is false, return false. |
| 7132 if (!trap_result_obj->BooleanValue()) { |
| 7133 RETURN_FAILURE(isolate, should_throw, |
| 7134 NewTypeError(MessageTemplate::kProxyTrapReturnedFalsishFor, |
| 7135 trap_name, property_name)); |
| 7136 } |
| 7137 // 11. Let targetDesc be ? target.[[GetOwnProperty]](P). |
| 7138 PropertyDescriptor target_desc; |
| 7139 Maybe<bool> target_found = |
| 7140 JSReceiver::GetOwnPropertyDescriptor(isolate, target, key, &target_desc); |
| 7141 MAYBE_RETURN(target_found, Nothing<bool>()); |
| 7142 // 12. Let extensibleTarget be ? IsExtensible(target). |
| 7143 Maybe<bool> maybe_extensible = JSReceiver::IsExtensible(target); |
| 7144 MAYBE_RETURN(maybe_extensible, Nothing<bool>()); |
| 7145 bool extensible_target = maybe_extensible.FromJust(); |
| 7146 // 13. If Desc has a [[Configurable]] field and if Desc.[[Configurable]] |
| 7147 // is false, then: |
| 7148 // 13a. Let settingConfigFalse be true. |
| 7149 // 14. Else let settingConfigFalse be false. |
| 7150 bool setting_config_false = desc->has_configurable() && !desc->configurable(); |
| 7151 // 15. If targetDesc is undefined, then |
| 7152 if (!target_found.FromJust()) { |
| 7153 // 15a. If extensibleTarget is false, throw a TypeError exception. |
| 7154 if (!extensible_target) { |
| 7155 isolate->Throw(*isolate->factory()->NewTypeError( |
| 7156 MessageTemplate::kProxyDefinePropertyNonExtensible, property_name)); |
| 7157 return Nothing<bool>(); |
| 7158 } |
| 7159 // 15b. If settingConfigFalse is true, throw a TypeError exception. |
| 7160 if (setting_config_false) { |
| 7161 isolate->Throw(*isolate->factory()->NewTypeError( |
| 7162 MessageTemplate::kProxyDefinePropertyNonConfigurable, property_name)); |
| 7163 return Nothing<bool>(); |
| 7164 } |
| 7165 } else { |
| 7166 // 16. Else targetDesc is not undefined, |
| 7167 // 16a. If IsCompatiblePropertyDescriptor(extensibleTarget, Desc, |
| 7168 // targetDesc) is false, throw a TypeError exception. |
| 7169 Maybe<bool> valid = |
| 7170 IsCompatiblePropertyDescriptor(isolate, extensible_target, desc, |
| 7171 &target_desc, property_name, DONT_THROW); |
| 7172 MAYBE_RETURN(valid, Nothing<bool>()); |
| 7173 if (!valid.FromJust()) { |
| 7174 isolate->Throw(*isolate->factory()->NewTypeError( |
| 7175 MessageTemplate::kProxyDefinePropertyIncompatible, property_name)); |
| 7176 return Nothing<bool>(); |
| 7177 } |
| 7178 // 16b. If settingConfigFalse is true and targetDesc.[[Configurable]] is |
| 7179 // true, throw a TypeError exception. |
| 7180 if (setting_config_false && target_desc.configurable()) { |
| 7181 isolate->Throw(*isolate->factory()->NewTypeError( |
| 7182 MessageTemplate::kProxyDefinePropertyNonConfigurable, property_name)); |
| 7183 return Nothing<bool>(); |
| 7184 } |
| 7185 } |
| 7186 // 17. Return true. |
| 7187 return Just(true); |
| 7188 } |
| 7189 |
| 7190 // static |
6942 Maybe<bool> JSProxy::SetPrivateProperty(Isolate* isolate, Handle<JSProxy> proxy, | 7191 Maybe<bool> JSProxy::SetPrivateProperty(Isolate* isolate, Handle<JSProxy> proxy, |
6943 Handle<Symbol> private_name, | 7192 Handle<Symbol> private_name, |
6944 PropertyDescriptor* desc, | 7193 PropertyDescriptor* desc, |
6945 ShouldThrow should_throw) { | 7194 ShouldThrow should_throw) { |
6946 // Despite the generic name, this can only add private data properties. | 7195 // Despite the generic name, this can only add private data properties. |
6947 if (!PropertyDescriptor::IsDataDescriptor(desc) || | 7196 if (!PropertyDescriptor::IsDataDescriptor(desc) || |
6948 desc->ToAttributes() != DONT_ENUM) { | 7197 desc->ToAttributes() != DONT_ENUM) { |
6949 RETURN_FAILURE(isolate, should_throw, | 7198 RETURN_FAILURE(isolate, should_throw, |
6950 NewTypeError(MessageTemplate::kProxyPrivate)); | 7199 NewTypeError(MessageTemplate::kProxyPrivate)); |
6951 } | 7200 } |
(...skipping 10268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17220 Nothing<bool>()); | 17469 Nothing<bool>()); |
17221 } | 17470 } |
17222 // 3b xi. Return true. | 17471 // 3b xi. Return true. |
17223 return Just(true); | 17472 return Just(true); |
17224 } | 17473 } |
17225 } | 17474 } |
17226 // 4. Return ! OrdinaryDefineOwnProperty(O, P, Desc). | 17475 // 4. Return ! OrdinaryDefineOwnProperty(O, P, Desc). |
17227 return OrdinaryDefineOwnProperty(isolate, o, key, desc, should_throw); | 17476 return OrdinaryDefineOwnProperty(isolate, o, key, desc, should_throw); |
17228 } | 17477 } |
17229 | 17478 |
| 17479 // static |
| 17480 Maybe<bool> JSTypedArray::DefineOwnPropertyWithoutIntercept( |
| 17481 Isolate* isolate, Handle<JSTypedArray> o, Handle<Object> key, |
| 17482 PropertyDescriptor* desc, ShouldThrow should_throw) { |
| 17483 // 1. Assert: IsPropertyKey(P) is true. |
| 17484 DCHECK(key->IsName() || key->IsNumber()); |
| 17485 // 2. Assert: O is an Object that has a [[ViewedArrayBuffer]] internal slot. |
| 17486 // 3. If Type(P) is String, then |
| 17487 if (key->IsString() || key->IsSmi()) { |
| 17488 // 3a. Let numericIndex be ! CanonicalNumericIndexString(P) |
| 17489 // 3b. If numericIndex is not undefined, then |
| 17490 Handle<Object> numeric_index; |
| 17491 if (CanonicalNumericIndexString(isolate, key, &numeric_index)) { |
| 17492 // 3b i. If IsInteger(numericIndex) is false, return false. |
| 17493 // 3b ii. If numericIndex = -0, return false. |
| 17494 // 3b iii. If numericIndex < 0, return false. |
| 17495 // FIXME: the standard allows up to 2^53 elements. |
| 17496 uint32_t index; |
| 17497 if (numeric_index->IsMinusZero() || !numeric_index->ToUint32(&index)) { |
| 17498 RETURN_FAILURE(isolate, should_throw, |
| 17499 NewTypeError(MessageTemplate::kInvalidTypedArrayIndex)); |
| 17500 } |
| 17501 // 3b iv. Let length be O.[[ArrayLength]]. |
| 17502 uint32_t length = o->length()->Number(); |
| 17503 // 3b v. If numericIndex ≥ length, return false. |
| 17504 if (index >= length) { |
| 17505 RETURN_FAILURE(isolate, should_throw, |
| 17506 NewTypeError(MessageTemplate::kInvalidTypedArrayIndex)); |
| 17507 } |
| 17508 // 3b vi. If IsAccessorDescriptor(Desc) is true, return false. |
| 17509 if (PropertyDescriptor::IsAccessorDescriptor(desc)) { |
| 17510 RETURN_FAILURE(isolate, should_throw, |
| 17511 NewTypeError(MessageTemplate::kRedefineDisallowed, key)); |
| 17512 } |
| 17513 // 3b vii. If Desc has a [[Configurable]] field and if |
| 17514 // Desc.[[Configurable]] is true, return false. |
| 17515 // 3b viii. If Desc has an [[Enumerable]] field and if Desc.[[Enumerable]] |
| 17516 // is false, return false. |
| 17517 // 3b ix. If Desc has a [[Writable]] field and if Desc.[[Writable]] is |
| 17518 // false, return false. |
| 17519 if ((desc->has_configurable() && desc->configurable()) || |
| 17520 (desc->has_enumerable() && !desc->enumerable()) || |
| 17521 (desc->has_writable() && !desc->writable())) { |
| 17522 RETURN_FAILURE(isolate, should_throw, |
| 17523 NewTypeError(MessageTemplate::kRedefineDisallowed, key)); |
| 17524 } |
| 17525 // 3b x. If Desc has a [[Value]] field, then |
| 17526 // 3b x 1. Let value be Desc.[[Value]]. |
| 17527 // 3b x 2. Return ? IntegerIndexedElementSet(O, numericIndex, value). |
| 17528 if (desc->has_value()) { |
| 17529 if (!desc->has_configurable()) desc->set_configurable(false); |
| 17530 if (!desc->has_enumerable()) desc->set_enumerable(true); |
| 17531 if (!desc->has_writable()) desc->set_writable(true); |
| 17532 Handle<Object> value = desc->value(); |
| 17533 RETURN_ON_EXCEPTION_VALUE(isolate, |
| 17534 SetOwnElementIgnoreAttributes( |
| 17535 o, index, value, desc->ToAttributes()), |
| 17536 Nothing<bool>()); |
| 17537 } |
| 17538 // 3b xi. Return true. |
| 17539 return Just(true); |
| 17540 } |
| 17541 } |
| 17542 // 4. Return ! OrdinaryDefineOwnProperty(O, P, Desc). |
| 17543 return OrdinaryDefineOwnPropertyWithoutIntercept(isolate, o, key, desc, |
| 17544 should_throw); |
| 17545 } |
| 17546 |
17230 ExternalArrayType JSTypedArray::type() { | 17547 ExternalArrayType JSTypedArray::type() { |
17231 switch (elements()->map()->instance_type()) { | 17548 switch (elements()->map()->instance_type()) { |
17232 #define INSTANCE_TYPE_TO_ARRAY_TYPE(Type, type, TYPE, ctype, size) \ | 17549 #define INSTANCE_TYPE_TO_ARRAY_TYPE(Type, type, TYPE, ctype, size) \ |
17233 case FIXED_##TYPE##_ARRAY_TYPE: \ | 17550 case FIXED_##TYPE##_ARRAY_TYPE: \ |
17234 return kExternal##Type##Array; | 17551 return kExternal##Type##Array; |
17235 | 17552 |
17236 TYPED_ARRAYS(INSTANCE_TYPE_TO_ARRAY_TYPE) | 17553 TYPED_ARRAYS(INSTANCE_TYPE_TO_ARRAY_TYPE) |
17237 #undef INSTANCE_TYPE_TO_ARRAY_TYPE | 17554 #undef INSTANCE_TYPE_TO_ARRAY_TYPE |
17238 | 17555 |
17239 default: | 17556 default: |
(...skipping 3180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20420 // depend on this. | 20737 // depend on this. |
20421 return DICTIONARY_ELEMENTS; | 20738 return DICTIONARY_ELEMENTS; |
20422 } | 20739 } |
20423 DCHECK_LE(kind, LAST_ELEMENTS_KIND); | 20740 DCHECK_LE(kind, LAST_ELEMENTS_KIND); |
20424 return kind; | 20741 return kind; |
20425 } | 20742 } |
20426 } | 20743 } |
20427 | 20744 |
20428 } // namespace internal | 20745 } // namespace internal |
20429 } // namespace v8 | 20746 } // namespace v8 |
OLD | NEW |