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(isolate, | |
6547 Handle<JSTypedArray>::cast(object), | |
6548 key, desc, should_throw); | |
6549 } | |
6545 // TODO(neis): Special case for JSModuleNamespace? | 6550 // TODO(neis): Special case for JSModuleNamespace? |
6546 | 6551 |
6547 // OrdinaryDefineOwnProperty, by virtue of calling | 6552 // OrdinaryDefineOwnProperty, by virtue of calling |
6548 // DefineOwnPropertyIgnoreAttributes, can handle arguments (ES6 9.4.4.2) | 6553 // 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, | 6554 return OrdinaryDefineOwnProperty(isolate, Handle<JSObject>::cast(object), key, |
6552 desc, should_throw); | 6555 desc, should_throw); |
6553 } | 6556 } |
6554 | 6557 |
6555 | 6558 |
6556 // static | 6559 // static |
6557 Maybe<bool> JSReceiver::OrdinaryDefineOwnProperty(Isolate* isolate, | 6560 Maybe<bool> JSReceiver::OrdinaryDefineOwnProperty(Isolate* isolate, |
6558 Handle<JSObject> object, | 6561 Handle<JSObject> object, |
6559 Handle<Object> key, | 6562 Handle<Object> key, |
6560 PropertyDescriptor* desc, | 6563 PropertyDescriptor* desc, |
(...skipping 10866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
17427 } | 17430 } |
17428 while (holes < limit) { | 17431 while (holes < limit) { |
17429 elements->set_the_hole(holes); | 17432 elements->set_the_hole(holes); |
17430 holes++; | 17433 holes++; |
17431 } | 17434 } |
17432 } | 17435 } |
17433 | 17436 |
17434 return isolate->factory()->NewNumberFromUint(result); | 17437 return isolate->factory()->NewNumberFromUint(result); |
17435 } | 17438 } |
17436 | 17439 |
17440 static bool IsInteger(Handle<Object> number) { | |
17441 if (!number->IsNumber() || number->IsNaN() || | |
17442 !std::isfinite(number->Number())) | |
17443 return false; | |
17444 double d = number->Number(); | |
17445 if (std::floor(std::abs(d)) != std::abs(d)) return false; | |
caitp
2016/10/20 15:39:21
Why the std::floor() and std::abs() and stuff? I t
| |
17446 return true; | |
17447 } | |
17448 | |
17449 static Handle<Object> CanonicalNumericIndexString(Isolate* isolate, | |
17450 Handle<Object> s) { | |
17451 DCHECK(s->IsString()); | |
17452 Handle<Object> index = String::ToNumber(Handle<String>::cast(s)); | |
17453 if (index->IsMinusZero()) return index; | |
17454 if (!Object::ToString(isolate, index).ToHandleChecked()->SameValue(*s)) | |
caitp
2016/10/20 15:39:21
I would leave a comment saying that we need this t
| |
17455 return isolate->factory()->undefined_value(); | |
17456 return index; | |
17457 } | |
17458 | |
17459 // ES6 9.4.5.3 | |
17460 // static | |
17461 Maybe<bool> JSTypedArray::DefineOwnProperty(Isolate* isolate, | |
17462 Handle<JSTypedArray> o, | |
17463 Handle<Object> key, | |
17464 PropertyDescriptor* desc, | |
17465 ShouldThrow should_throw) { | |
17466 // 1. Assert: IsPropertyKey(P) is true. | |
17467 DCHECK(key->IsName() || key->IsNumber()); | |
17468 // 2. Assert: O is an Object that has a [[ViewedArrayBuffer]] internal slot. | |
17469 // 3. If Type(P) is String, then | |
17470 if (key->IsString()) { | |
17471 // 3a. Let numericIndex be ! CanonicalNumericIndexString(P) | |
17472 Handle<Object> numeric_index = | |
17473 CanonicalNumericIndexString(isolate, Handle<String>::cast(key)); | |
17474 // 3b. If numericIndex is not undefined, then | |
17475 if (!numeric_index->IsUndefined(isolate)) { | |
17476 // 3b i. If IsInteger(numericIndex) is false, return false. | |
17477 // 3b ii. If numericIndex = -0, return false. | |
17478 // 3b iii. If numericIndex < 0, return false. | |
17479 if (!IsInteger(numeric_index) || numeric_index->IsMinusZero() || | |
17480 numeric_index->Number() < 0) | |
17481 return Just(false); | |
17482 // 3b iv. Let length be O.[[ArrayLength]]. | |
17483 int length = o->length()->Number(); | |
17484 // 3b v. If numericIndex ≥ length, return false. | |
17485 if (numeric_index->Number() >= length) return Just(false); | |
17486 // 3b vi. If IsAccessorDescriptor(Desc) is true, return false. | |
17487 if (PropertyDescriptor::IsAccessorDescriptor(desc)) return Just(false); | |
17488 // 3b vii. If Desc has a [[Configurable]] field and if | |
17489 // Desc.[[Configurable]] is true, return false. 3b viii. If Desc has an | |
17490 // [[Enumerable]] field and if Desc.[[Enumerable]] is false, return false. | |
17491 // 3b ix. If Desc has a [[Writable]] field and if Desc.[[Writable]] is | |
17492 // false, return false. | |
17493 if ((desc->has_configurable() && desc->configurable()) || | |
17494 (desc->has_enumerable() && !desc->enumerable()) || | |
17495 (desc->has_writable() && !desc->writable())) | |
17496 return Just(false); | |
17497 // 3b x. If Desc has a [[Value]] field, then | |
17498 // 3b x 1. Let value be Desc.[[Value]]. | |
17499 // 3b x 2. Return ? IntegerIndexedElementSet(O, numericIndex, value). | |
17500 // Performed by OrdinaryDefineOwnProperty below. | |
17501 // OrdinaryDefineOwnProperty, by virtue of calling | |
17502 // DefineOwnPropertyIgnoreAttributes, can handle IntegerIndexedExotics, | |
17503 // with one exception: | |
17504 // TODO(jkummerow): Setting an indexed accessor on a typed array should | |
17505 // throw. | |
17506 // 3b xi. Return true. | |
17507 if (!desc->has_value()) { | |
17508 return Just(true); | |
17509 } | |
caitp
2016/10/20 15:39:21
It looks like we're missing the Integer IntegerInd
| |
17510 } | |
17511 } | |
17512 // 4. Return ! OrdinaryDefineOwnProperty(O, P, Desc). | |
17513 return OrdinaryDefineOwnProperty(isolate, o, key, desc, should_throw); | |
caitp
2016/10/20 15:39:21
The ToPropertyKey implementation in v8 can return
| |
17514 } | |
17515 | |
17437 | 17516 |
17438 ExternalArrayType JSTypedArray::type() { | 17517 ExternalArrayType JSTypedArray::type() { |
17439 switch (elements()->map()->instance_type()) { | 17518 switch (elements()->map()->instance_type()) { |
17440 #define INSTANCE_TYPE_TO_ARRAY_TYPE(Type, type, TYPE, ctype, size) \ | 17519 #define INSTANCE_TYPE_TO_ARRAY_TYPE(Type, type, TYPE, ctype, size) \ |
17441 case FIXED_##TYPE##_ARRAY_TYPE: \ | 17520 case FIXED_##TYPE##_ARRAY_TYPE: \ |
17442 return kExternal##Type##Array; | 17521 return kExternal##Type##Array; |
17443 | 17522 |
17444 TYPED_ARRAYS(INSTANCE_TYPE_TO_ARRAY_TYPE) | 17523 TYPED_ARRAYS(INSTANCE_TYPE_TO_ARRAY_TYPE) |
17445 #undef INSTANCE_TYPE_TO_ARRAY_TYPE | 17524 #undef INSTANCE_TYPE_TO_ARRAY_TYPE |
17446 | 17525 |
(...skipping 2766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
20213 ns, Accessors::ModuleNamespaceEntryInfo(isolate, name, attr)) | 20292 ns, Accessors::ModuleNamespaceEntryInfo(isolate, name, attr)) |
20214 .Check(); | 20293 .Check(); |
20215 } | 20294 } |
20216 JSObject::PreventExtensions(ns, THROW_ON_ERROR).ToChecked(); | 20295 JSObject::PreventExtensions(ns, THROW_ON_ERROR).ToChecked(); |
20217 | 20296 |
20218 return ns; | 20297 return ns; |
20219 } | 20298 } |
20220 | 20299 |
20221 } // namespace internal | 20300 } // namespace internal |
20222 } // namespace v8 | 20301 } // namespace v8 |
OLD | NEW |