Chromium Code Reviews| 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 Handle<Object> CanonicalNumericIndexString(Isolate* isolate, | |
|
Camillo Bruni
2016/11/15 13:07:22
nit: use an anonymous namespace for this helper
Y
| |
| 17441 Handle<Object> s) { | |
| 17442 DCHECK(s->IsString()); | |
| 17443 Handle<Object> index = String::ToNumber(Handle<String>::cast(s)); | |
| 17444 if (index->IsMinusZero()) return index; | |
| 17445 // Avoid treating strings like "2E1" and "20" as the same key | |
| 17446 if (!Object::ToString(isolate, index).ToHandleChecked()->SameValue(*s)) | |
| 17447 return isolate->factory()->undefined_value(); | |
|
Camillo Bruni
2016/11/15 13:07:22
nit: always use braces for if-bodies on separate l
| |
| 17448 return index; | |
| 17449 } | |
| 17450 | |
| 17451 // ES6 9.4.5.3 | |
|
Dan Ehrenberg
2016/11/15 11:28:16
Nit: New references to the spec should be identifi
| |
| 17452 // static | |
| 17453 Maybe<bool> JSTypedArray::DefineOwnProperty(Isolate* isolate, | |
| 17454 Handle<JSTypedArray> o, | |
| 17455 Handle<Object> key, | |
| 17456 PropertyDescriptor* desc, | |
| 17457 ShouldThrow should_throw) { | |
| 17458 // 1. Assert: IsPropertyKey(P) is true. | |
| 17459 DCHECK(key->IsName() || key->IsNumber()); | |
| 17460 // 2. Assert: O is an Object that has a [[ViewedArrayBuffer]] internal slot. | |
| 17461 // 3. If Type(P) is String, then | |
| 17462 // ToPropertyKey returns Smi's too | |
| 17463 if (key->IsString() || key->IsSmi()) { | |
| 17464 // 3a. Let numericIndex be ! CanonicalNumericIndexString(P) | |
| 17465 Handle<Object> numeric_index = | |
| 17466 key->IsSmi() ? key | |
| 17467 : CanonicalNumericIndexString(isolate, | |
| 17468 Handle<String>::cast(key)); | |
| 17469 // 3b. If numericIndex is not undefined, then | |
| 17470 if (!numeric_index->IsUndefined(isolate)) { | |
| 17471 // 3b i. If IsInteger(numericIndex) is false, return false. | |
| 17472 // 3b ii. If numericIndex = -0, return false. | |
| 17473 // 3b iii. If numericIndex < 0, return false. | |
| 17474 int index = numeric_index->Number(); | |
| 17475 // FIXME: the standard allows up to 2^53 elements | |
| 17476 if (!IsUint32Double(index)) | |
|
Camillo Bruni
2016/11/15 13:07:22
You may want to shuffle around the steps a bit her
| |
| 17477 RETURN_FAILURE(isolate, should_throw, | |
| 17478 NewTypeError(MessageTemplate::kInvalidTypedArrayIndex)); | |
| 17479 // 3b iv. Let length be O.[[ArrayLength]]. | |
| 17480 int length = o->length()->Number(); | |
|
Camillo Bruni
2016/11/15 13:07:23
I'd feel safer by using a uint32_t here.
| |
| 17481 // 3b v. If numericIndex ≥ length, return false. | |
| 17482 if (index >= length) | |
| 17483 RETURN_FAILURE(isolate, should_throw, | |
| 17484 NewTypeError(MessageTemplate::kInvalidTypedArrayIndex)); | |
|
Camillo Bruni
2016/11/15 13:07:23
nit: missing braces
| |
| 17485 // 3b vi. If IsAccessorDescriptor(Desc) is true, return false. | |
| 17486 if (PropertyDescriptor::IsAccessorDescriptor(desc)) | |
| 17487 RETURN_FAILURE(isolate, should_throw, | |
| 17488 NewTypeError(MessageTemplate::kRedefineDisallowed, key)); | |
|
Camillo Bruni
2016/11/15 13:07:22
nit: missing braces
| |
| 17489 // 3b vii. If Desc has a [[Configurable]] field and if | |
| 17490 // Desc.[[Configurable]] is true, return false. | |
| 17491 // 3b viii. If Desc has an [[Enumerable]] field and if Desc.[[Enumerable]] | |
| 17492 // is false, return false. | |
| 17493 // 3b ix. If Desc has a [[Writable]] field and if Desc.[[Writable]] is | |
| 17494 // false, return false. | |
| 17495 if ((desc->has_configurable() && desc->configurable()) || | |
| 17496 (desc->has_enumerable() && !desc->enumerable()) || | |
| 17497 (desc->has_writable() && !desc->writable())) | |
| 17498 RETURN_FAILURE(isolate, should_throw, | |
| 17499 NewTypeError(MessageTemplate::kRedefineDisallowed, key)); | |
|
Camillo Bruni
2016/11/15 13:07:22
nit: missing braces
| |
| 17500 // 3b x. If Desc has a [[Value]] field, then | |
| 17501 // 3b x 1. Let value be Desc.[[Value]]. | |
| 17502 // 3b x 2. Return ? IntegerIndexedElementSet(O, numericIndex, value). | |
| 17503 if (desc->has_value()) { | |
| 17504 if (!desc->has_configurable()) desc->set_configurable(false); | |
| 17505 if (!desc->has_enumerable()) desc->set_enumerable(true); | |
| 17506 if (!desc->has_writable()) desc->set_writable(true); | |
| 17507 Handle<Object> value = desc->value(); | |
| 17508 RETURN_ON_EXCEPTION_VALUE( | |
| 17509 isolate, | |
| 17510 SetOwnElementIgnoreAttributes(o, index, value, | |
| 17511 desc->ToAttributes()), | |
| 17512 Nothing<bool>()); | |
| 17513 } | |
| 17514 // 3b xi. Return true. | |
| 17515 return Just(true); | |
| 17516 } | |
| 17517 } | |
| 17518 // 4. Return ! OrdinaryDefineOwnProperty(O, P, Desc). | |
| 17519 return OrdinaryDefineOwnProperty(isolate, o, key, desc, should_throw); | |
| 17520 } | |
| 17521 | |
| 17437 | 17522 |
| 17438 ExternalArrayType JSTypedArray::type() { | 17523 ExternalArrayType JSTypedArray::type() { |
| 17439 switch (elements()->map()->instance_type()) { | 17524 switch (elements()->map()->instance_type()) { |
| 17440 #define INSTANCE_TYPE_TO_ARRAY_TYPE(Type, type, TYPE, ctype, size) \ | 17525 #define INSTANCE_TYPE_TO_ARRAY_TYPE(Type, type, TYPE, ctype, size) \ |
| 17441 case FIXED_##TYPE##_ARRAY_TYPE: \ | 17526 case FIXED_##TYPE##_ARRAY_TYPE: \ |
| 17442 return kExternal##Type##Array; | 17527 return kExternal##Type##Array; |
| 17443 | 17528 |
| 17444 TYPED_ARRAYS(INSTANCE_TYPE_TO_ARRAY_TYPE) | 17529 TYPED_ARRAYS(INSTANCE_TYPE_TO_ARRAY_TYPE) |
| 17445 #undef INSTANCE_TYPE_TO_ARRAY_TYPE | 17530 #undef INSTANCE_TYPE_TO_ARRAY_TYPE |
| 17446 | 17531 |
| (...skipping 2766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 20213 ns, Accessors::ModuleNamespaceEntryInfo(isolate, name, attr)) | 20298 ns, Accessors::ModuleNamespaceEntryInfo(isolate, name, attr)) |
| 20214 .Check(); | 20299 .Check(); |
| 20215 } | 20300 } |
| 20216 JSObject::PreventExtensions(ns, THROW_ON_ERROR).ToChecked(); | 20301 JSObject::PreventExtensions(ns, THROW_ON_ERROR).ToChecked(); |
| 20217 | 20302 |
| 20218 return ns; | 20303 return ns; |
| 20219 } | 20304 } |
| 20220 | 20305 |
| 20221 } // namespace internal | 20306 } // namespace internal |
| 20222 } // namespace v8 | 20307 } // namespace v8 |
| OLD | NEW |