| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 <sstream> | 9 #include <sstream> |
| 10 | 10 |
| (...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 return true; | 708 return true; |
| 709 } | 709 } |
| 710 } | 710 } |
| 711 return false; | 711 return false; |
| 712 } | 712 } |
| 713 | 713 |
| 714 | 714 |
| 715 bool Object::ToUint32(uint32_t* value) { | 715 bool Object::ToUint32(uint32_t* value) { |
| 716 if (IsSmi()) { | 716 if (IsSmi()) { |
| 717 int num = Smi::cast(this)->value(); | 717 int num = Smi::cast(this)->value(); |
| 718 if (num >= 0) { | 718 if (num < 0) return false; |
| 719 *value = static_cast<uint32_t>(num); | 719 *value = static_cast<uint32_t>(num); |
| 720 return true; |
| 721 } |
| 722 if (IsHeapNumber()) { |
| 723 double num = HeapNumber::cast(this)->value(); |
| 724 if (num < 0) return false; |
| 725 uint32_t uint_value = FastD2UI(num); |
| 726 if (FastUI2D(uint_value) == num) { |
| 727 *value = uint_value; |
| 720 return true; | 728 return true; |
| 721 } | 729 } |
| 722 } | 730 } |
| 723 if (IsHeapNumber()) { | |
| 724 double num = HeapNumber::cast(this)->value(); | |
| 725 if (num >= 0 && FastUI2D(FastD2UI(num)) == num) { | |
| 726 *value = FastD2UI(num); | |
| 727 return true; | |
| 728 } | |
| 729 } | |
| 730 return false; | 731 return false; |
| 731 } | 732 } |
| 732 | 733 |
| 733 | 734 |
| 734 bool FunctionTemplateInfo::IsTemplateFor(Object* object) { | 735 bool FunctionTemplateInfo::IsTemplateFor(Object* object) { |
| 735 if (!object->IsHeapObject()) return false; | 736 if (!object->IsHeapObject()) return false; |
| 736 return IsTemplateFor(HeapObject::cast(object)->map()); | 737 return IsTemplateFor(HeapObject::cast(object)->map()); |
| 737 } | 738 } |
| 738 | 739 |
| 739 | 740 |
| (...skipping 5646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6386 } | 6387 } |
| 6387 // 3k. Return true. | 6388 // 3k. Return true. |
| 6388 return true; | 6389 return true; |
| 6389 } | 6390 } |
| 6390 | 6391 |
| 6391 // 4. Return OrdinaryDefineOwnProperty(A, P, Desc). | 6392 // 4. Return OrdinaryDefineOwnProperty(A, P, Desc). |
| 6392 return OrdinaryDefineOwnProperty(isolate, o, name, desc, should_throw); | 6393 return OrdinaryDefineOwnProperty(isolate, o, name, desc, should_throw); |
| 6393 } | 6394 } |
| 6394 | 6395 |
| 6395 | 6396 |
| 6396 // TODO(jkummerow): Consider unification with ArrayLengthSetter in accessors.cc. | 6397 // Part of ES6 9.4.2.4 ArraySetLength. |
| 6397 bool AnythingToArrayLength(Isolate* isolate, Handle<Object> length_obj, | 6398 // static |
| 6398 uint32_t* output) { | 6399 bool JSArray::AnythingToArrayLength(Isolate* isolate, |
| 6400 Handle<Object> length_object, |
| 6401 uint32_t* output) { |
| 6399 // Fast path: check numbers and strings that can be converted directly | 6402 // Fast path: check numbers and strings that can be converted directly |
| 6400 // and unobservably. | 6403 // and unobservably. |
| 6401 if (length_obj->ToUint32(output)) return true; | 6404 if (length_object->ToArrayLength(output)) return true; |
| 6402 if (length_obj->IsString() && | 6405 if (length_object->IsString() && |
| 6403 Handle<String>::cast(length_obj)->AsArrayIndex(output)) { | 6406 Handle<String>::cast(length_object)->AsArrayIndex(output)) { |
| 6404 return true; | 6407 return true; |
| 6405 } | 6408 } |
| 6406 // Slow path: follow steps in ES6 9.4.2.4 "ArraySetLength". | 6409 // Slow path: follow steps in ES6 9.4.2.4 "ArraySetLength". |
| 6407 // 3. Let newLen be ToUint32(Desc.[[Value]]). | 6410 // 3. Let newLen be ToUint32(Desc.[[Value]]). |
| 6408 Handle<Object> uint32_v; | 6411 Handle<Object> uint32_v; |
| 6409 if (!Object::ToUint32(isolate, length_obj).ToHandle(&uint32_v)) { | 6412 if (!Object::ToUint32(isolate, length_object).ToHandle(&uint32_v)) { |
| 6410 // 4. ReturnIfAbrupt(newLen). | 6413 // 4. ReturnIfAbrupt(newLen). |
| 6411 return false; | 6414 return false; |
| 6412 } | 6415 } |
| 6413 // 5. Let numberLen be ToNumber(Desc.[[Value]]). | 6416 // 5. Let numberLen be ToNumber(Desc.[[Value]]). |
| 6414 Handle<Object> number_v; | 6417 Handle<Object> number_v; |
| 6415 if (!Object::ToNumber(length_obj).ToHandle(&number_v)) { | 6418 if (!Object::ToNumber(length_object).ToHandle(&number_v)) { |
| 6416 // 6. ReturnIfAbrupt(newLen). | 6419 // 6. ReturnIfAbrupt(newLen). |
| 6417 return false; | 6420 return false; |
| 6418 } | 6421 } |
| 6419 // 7. If newLen != numberLen, throw a RangeError exception. | 6422 // 7. If newLen != numberLen, throw a RangeError exception. |
| 6420 if (uint32_v->Number() != number_v->Number()) { | 6423 if (uint32_v->Number() != number_v->Number()) { |
| 6421 Handle<Object> exception = | 6424 Handle<Object> exception = |
| 6422 isolate->factory()->NewRangeError(MessageTemplate::kInvalidArrayLength); | 6425 isolate->factory()->NewRangeError(MessageTemplate::kInvalidArrayLength); |
| 6423 isolate->Throw(*exception); | 6426 isolate->Throw(*exception); |
| 6424 return false; | 6427 return false; |
| 6425 } | 6428 } |
| 6426 return uint32_v->ToArrayLength(output); | 6429 CHECK(uint32_v->ToArrayLength(output)); |
| 6430 return true; |
| 6427 } | 6431 } |
| 6428 | 6432 |
| 6429 | 6433 |
| 6430 // ES6 9.4.2.4 | 6434 // ES6 9.4.2.4 |
| 6431 // static | 6435 // static |
| 6432 bool JSArray::ArraySetLength(Isolate* isolate, Handle<JSArray> a, | 6436 bool JSArray::ArraySetLength(Isolate* isolate, Handle<JSArray> a, |
| 6433 PropertyDescriptor* desc, | 6437 PropertyDescriptor* desc, |
| 6434 ShouldThrow should_throw) { | 6438 ShouldThrow should_throw) { |
| 6435 // 1. If the [[Value]] field of Desc is absent, then | 6439 // 1. If the [[Value]] field of Desc is absent, then |
| 6436 if (!desc->has_value()) { | 6440 if (!desc->has_value()) { |
| (...skipping 11225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17662 if (cell->value() != *new_value) { | 17666 if (cell->value() != *new_value) { |
| 17663 cell->set_value(*new_value); | 17667 cell->set_value(*new_value); |
| 17664 Isolate* isolate = cell->GetIsolate(); | 17668 Isolate* isolate = cell->GetIsolate(); |
| 17665 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 17669 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
| 17666 isolate, DependentCode::kPropertyCellChangedGroup); | 17670 isolate, DependentCode::kPropertyCellChangedGroup); |
| 17667 } | 17671 } |
| 17668 } | 17672 } |
| 17669 | 17673 |
| 17670 } // namespace internal | 17674 } // namespace internal |
| 17671 } // namespace v8 | 17675 } // namespace v8 |
| OLD | NEW |