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 6524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6535 PropertyDescriptor* desc, | 6535 PropertyDescriptor* desc, |
6536 ShouldThrow should_throw) { | 6536 ShouldThrow should_throw) { |
6537 if (object->IsJSArray()) { | 6537 if (object->IsJSArray()) { |
6538 return JSArray::DefineOwnProperty(isolate, Handle<JSArray>::cast(object), | 6538 return JSArray::DefineOwnProperty(isolate, Handle<JSArray>::cast(object), |
6539 key, desc, should_throw); | 6539 key, desc, should_throw); |
6540 } | 6540 } |
6541 if (object->IsJSProxy()) { | 6541 if (object->IsJSProxy()) { |
6542 return JSProxy::DefineOwnProperty(isolate, Handle<JSProxy>::cast(object), | 6542 return JSProxy::DefineOwnProperty(isolate, Handle<JSProxy>::cast(object), |
6543 key, desc, should_throw); | 6543 key, desc, should_throw); |
6544 } | 6544 } |
6545 if (object->IsJSTypedArray()) { | |
6546 return JSTypedArray::DefineOwnProperty( | |
6547 isolate, Handle<JSTypedArray>::cast(object), key, desc, should_throw); | |
6548 } | |
6545 // TODO(neis): Special case for JSModuleNamespace? | 6549 // TODO(neis): Special case for JSModuleNamespace? |
6546 | 6550 |
6547 // OrdinaryDefineOwnProperty, by virtue of calling | 6551 // OrdinaryDefineOwnProperty, by virtue of calling |
6548 // DefineOwnPropertyIgnoreAttributes, can handle arguments (ES6 9.4.4.2) | 6552 // DefineOwnPropertyIgnoreAttributes, can handle arguments (ES6 9.4.4.2) |
6549 // and IntegerIndexedExotics (ES6 9.4.5.3), with one exception: | |
6550 // TODO(jkummerow): Setting an indexed accessor on a typed array should throw. | |
6551 return OrdinaryDefineOwnProperty(isolate, Handle<JSObject>::cast(object), key, | 6553 return OrdinaryDefineOwnProperty(isolate, Handle<JSObject>::cast(object), key, |
6552 desc, should_throw); | 6554 desc, should_throw); |
6553 } | 6555 } |
6554 | 6556 |
6555 | 6557 |
6556 // static | 6558 // static |
6557 Maybe<bool> JSReceiver::OrdinaryDefineOwnProperty(Isolate* isolate, | 6559 Maybe<bool> JSReceiver::OrdinaryDefineOwnProperty(Isolate* isolate, |
6558 Handle<JSObject> object, | 6560 Handle<JSObject> object, |
6559 Handle<Object> key, | 6561 Handle<Object> key, |
6560 PropertyDescriptor* desc, | 6562 PropertyDescriptor* desc, |
(...skipping 10867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
17428 while (holes < limit) { | 17430 while (holes < limit) { |
17429 elements->set_the_hole(holes); | 17431 elements->set_the_hole(holes); |
17430 holes++; | 17432 holes++; |
17431 } | 17433 } |
17432 } | 17434 } |
17433 | 17435 |
17434 return isolate->factory()->NewNumberFromUint(result); | 17436 return isolate->factory()->NewNumberFromUint(result); |
17435 } | 17437 } |
17436 | 17438 |
17437 | 17439 |
17440 namespace { | |
17441 | |
17442 bool CanonicalNumericIndexString(Isolate* isolate, | |
17443 Handle<Object> s, | |
17444 Handle<Object>* index) { | |
17445 DCHECK(s->IsString() || s->IsSmi()); | |
17446 if (s->IsSmi()) { | |
17447 *index = s; | |
17448 return true; | |
17449 } | |
17450 Handle<Object> value = String::ToNumber(Handle<String>::cast(s)); | |
17451 if (value->IsMinusZero() || | |
17452 // Avoid treating strings like "2E1" and "20" as the same key | |
17453 Object::ToString(isolate, value).ToHandleChecked()->SameValue(*s)) { | |
17454 *index = value; | |
17455 return true; | |
17456 } | |
17457 return false; | |
17458 } | |
17459 | |
17460 } // anonymous namespace | |
17461 | |
17462 // ES#sec-integer-indexed-exotic-objects-defineownproperty-p-desc | |
17463 // static | |
17464 Maybe<bool> JSTypedArray::DefineOwnProperty(Isolate* isolate, | |
17465 Handle<JSTypedArray> o, | |
17466 Handle<Object> key, | |
17467 PropertyDescriptor* desc, | |
17468 ShouldThrow should_throw) { | |
17469 // 1. Assert: IsPropertyKey(P) is true. | |
17470 DCHECK(key->IsName() || key->IsNumber()); | |
17471 // 2. Assert: O is an Object that has a [[ViewedArrayBuffer]] internal slot. | |
17472 // 3. If Type(P) is String, then | |
17473 // ToPropertyKey returns Smi's too | |
17474 if (key->IsString() || key->IsSmi()) { | |
17475 // 3a. Let numericIndex be ! CanonicalNumericIndexString(P) | |
17476 // 3b. If numericIndex is not undefined, then | |
17477 Handle<Object> double_index; | |
17478 if (CanonicalNumericIndexString(isolate, key, &double_index)) { | |
17479 // 3b i. If IsInteger(numericIndex) is false, return false. | |
17480 // 3b ii. If numericIndex = -0, return false. | |
17481 // 3b iii. If numericIndex < 0, return false. | |
17482 // FIXME: the standard allows up to 2^53 elements | |
17483 uint32_t index; | |
17484 if (double_index->IsMinusZero() || !double_index->ToUint32(&index)) { | |
Henrique Ferreiro
2016/11/17 12:11:02
ToUint32 doesn't check for -0. This seems like a b
caitp
2016/11/17 15:13:22
Why would it? -0 can't be represented in uint32, a
| |
17485 RETURN_FAILURE(isolate, should_throw, | |
17486 NewTypeError(MessageTemplate::kInvalidTypedArrayIndex)); | |
17487 } | |
17488 // 3b iv. Let length be O.[[ArrayLength]]. | |
17489 uint32_t length = o->length()->Number(); | |
17490 // 3b v. If numericIndex ≥ length, return false. | |
17491 if (index >= length) { | |
17492 RETURN_FAILURE(isolate, should_throw, | |
17493 NewTypeError(MessageTemplate::kInvalidTypedArrayIndex)); | |
17494 } | |
17495 // 3b vi. If IsAccessorDescriptor(Desc) is true, return false. | |
17496 if (PropertyDescriptor::IsAccessorDescriptor(desc)) { | |
17497 RETURN_FAILURE(isolate, should_throw, | |
17498 NewTypeError(MessageTemplate::kRedefineDisallowed, key)); | |
17499 } | |
17500 // 3b vii. If Desc has a [[Configurable]] field and if | |
17501 // Desc.[[Configurable]] is true, return false. | |
17502 // 3b viii. If Desc has an [[Enumerable]] field and if Desc.[[Enumerable]] | |
17503 // is false, return false. | |
17504 // 3b ix. If Desc has a [[Writable]] field and if Desc.[[Writable]] is | |
17505 // false, return false. | |
17506 if ((desc->has_configurable() && desc->configurable()) || | |
17507 (desc->has_enumerable() && !desc->enumerable()) || | |
17508 (desc->has_writable() && !desc->writable())) { | |
17509 RETURN_FAILURE(isolate, should_throw, | |
17510 NewTypeError(MessageTemplate::kRedefineDisallowed, key)); | |
17511 } | |
17512 // 3b x. If Desc has a [[Value]] field, then | |
17513 // 3b x 1. Let value be Desc.[[Value]]. | |
17514 // 3b x 2. Return ? IntegerIndexedElementSet(O, numericIndex, value). | |
17515 if (desc->has_value()) { | |
17516 if (!desc->has_configurable()) desc->set_configurable(false); | |
17517 if (!desc->has_enumerable()) desc->set_enumerable(true); | |
17518 if (!desc->has_writable()) desc->set_writable(true); | |
17519 Handle<Object> value = desc->value(); | |
17520 RETURN_ON_EXCEPTION_VALUE(isolate, | |
17521 SetOwnElementIgnoreAttributes( | |
17522 o, index, value, desc->ToAttributes()), | |
17523 Nothing<bool>()); | |
17524 } | |
17525 // 3b xi. Return true. | |
17526 return Just(true); | |
17527 } | |
17528 } | |
17529 // 4. Return ! OrdinaryDefineOwnProperty(O, P, Desc). | |
17530 return OrdinaryDefineOwnProperty(isolate, o, key, desc, should_throw); | |
17531 } | |
17532 | |
17533 | |
17438 ExternalArrayType JSTypedArray::type() { | 17534 ExternalArrayType JSTypedArray::type() { |
17439 switch (elements()->map()->instance_type()) { | 17535 switch (elements()->map()->instance_type()) { |
17440 #define INSTANCE_TYPE_TO_ARRAY_TYPE(Type, type, TYPE, ctype, size) \ | 17536 #define INSTANCE_TYPE_TO_ARRAY_TYPE(Type, type, TYPE, ctype, size) \ |
17441 case FIXED_##TYPE##_ARRAY_TYPE: \ | 17537 case FIXED_##TYPE##_ARRAY_TYPE: \ |
17442 return kExternal##Type##Array; | 17538 return kExternal##Type##Array; |
17443 | 17539 |
17444 TYPED_ARRAYS(INSTANCE_TYPE_TO_ARRAY_TYPE) | 17540 TYPED_ARRAYS(INSTANCE_TYPE_TO_ARRAY_TYPE) |
17445 #undef INSTANCE_TYPE_TO_ARRAY_TYPE | 17541 #undef INSTANCE_TYPE_TO_ARRAY_TYPE |
17446 | 17542 |
17447 default: | 17543 default: |
(...skipping 2765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
20213 ns, Accessors::ModuleNamespaceEntryInfo(isolate, name, attr)) | 20309 ns, Accessors::ModuleNamespaceEntryInfo(isolate, name, attr)) |
20214 .Check(); | 20310 .Check(); |
20215 } | 20311 } |
20216 JSObject::PreventExtensions(ns, THROW_ON_ERROR).ToChecked(); | 20312 JSObject::PreventExtensions(ns, THROW_ON_ERROR).ToChecked(); |
20217 | 20313 |
20218 return ns; | 20314 return ns; |
20219 } | 20315 } |
20220 | 20316 |
20221 } // namespace internal | 20317 } // namespace internal |
20222 } // namespace v8 | 20318 } // namespace v8 |
OLD | NEW |