OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/conversions.h" | 8 #include "src/conversions.h" |
9 #include "src/elements.h" | 9 #include "src/elements.h" |
10 #include "src/messages.h" | 10 #include "src/messages.h" |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 } | 637 } |
638 | 638 |
639 virtual void SetLength(Handle<JSArray> array, uint32_t length) final { | 639 virtual void SetLength(Handle<JSArray> array, uint32_t length) final { |
640 ElementsAccessorSubclass::SetLengthImpl(array, length, | 640 ElementsAccessorSubclass::SetLengthImpl(array, length, |
641 handle(array->elements())); | 641 handle(array->elements())); |
642 } | 642 } |
643 | 643 |
644 static void SetLengthImpl(Handle<JSArray> array, uint32_t length, | 644 static void SetLengthImpl(Handle<JSArray> array, uint32_t length, |
645 Handle<FixedArrayBase> backing_store); | 645 Handle<FixedArrayBase> backing_store); |
646 | 646 |
647 static void GrowCapacityAndConvert(Handle<JSObject> obj, int capacity) { | 647 static void GrowCapacityAndConvertImpl(Handle<JSObject> obj, |
| 648 uint32_t capacity) { |
648 UNIMPLEMENTED(); | 649 UNIMPLEMENTED(); |
649 } | 650 } |
650 | 651 |
| 652 virtual void GrowCapacityAndConvert(Handle<JSObject> object, |
| 653 uint32_t capacity) final { |
| 654 ElementsAccessorSubclass::GrowCapacityAndConvertImpl(object, capacity); |
| 655 } |
| 656 |
651 virtual void Delete(Handle<JSObject> obj, uint32_t key, | 657 virtual void Delete(Handle<JSObject> obj, uint32_t key, |
652 LanguageMode language_mode) override = 0; | 658 LanguageMode language_mode) override = 0; |
653 | 659 |
654 static void CopyElementsImpl(FixedArrayBase* from, uint32_t from_start, | 660 static void CopyElementsImpl(FixedArrayBase* from, uint32_t from_start, |
655 FixedArrayBase* to, ElementsKind from_kind, | 661 FixedArrayBase* to, ElementsKind from_kind, |
656 uint32_t to_start, int packed_size, | 662 uint32_t to_start, int packed_size, |
657 int copy_size) { | 663 int copy_size) { |
658 UNREACHABLE(); | 664 UNREACHABLE(); |
659 } | 665 } |
660 | 666 |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1024 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ | 1030 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ |
1025 case EXTERNAL_##TYPE##_ELEMENTS: \ | 1031 case EXTERNAL_##TYPE##_ELEMENTS: \ |
1026 case TYPE##_ELEMENTS: \ | 1032 case TYPE##_ELEMENTS: \ |
1027 UNREACHABLE(); | 1033 UNREACHABLE(); |
1028 TYPED_ARRAYS(TYPED_ARRAY_CASE) | 1034 TYPED_ARRAYS(TYPED_ARRAY_CASE) |
1029 #undef TYPED_ARRAY_CASE | 1035 #undef TYPED_ARRAY_CASE |
1030 } | 1036 } |
1031 } | 1037 } |
1032 | 1038 |
1033 | 1039 |
1034 static void GrowCapacityAndConvert(Handle<JSObject> obj, uint32_t capacity) { | 1040 static void GrowCapacityAndConvertImpl(Handle<JSObject> obj, |
| 1041 uint32_t capacity) { |
1035 JSObject::SetFastElementsCapacitySmiMode set_capacity_mode = | 1042 JSObject::SetFastElementsCapacitySmiMode set_capacity_mode = |
1036 obj->HasFastSmiElements() | 1043 obj->HasFastSmiElements() |
1037 ? JSObject::kAllowSmiElements | 1044 ? JSObject::kAllowSmiElements |
1038 : JSObject::kDontAllowSmiElements; | 1045 : JSObject::kDontAllowSmiElements; |
1039 JSObject::SetFastElementsCapacity(obj, capacity, set_capacity_mode); | 1046 JSObject::SetFastElementsCapacity(obj, capacity, set_capacity_mode); |
1040 } | 1047 } |
1041 }; | 1048 }; |
1042 | 1049 |
1043 | 1050 |
1044 class FastPackedSmiElementsAccessor | 1051 class FastPackedSmiElementsAccessor |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1091 | 1098 |
1092 template<typename FastElementsAccessorSubclass, | 1099 template<typename FastElementsAccessorSubclass, |
1093 typename KindTraits> | 1100 typename KindTraits> |
1094 class FastDoubleElementsAccessor | 1101 class FastDoubleElementsAccessor |
1095 : public FastElementsAccessor<FastElementsAccessorSubclass, KindTraits> { | 1102 : public FastElementsAccessor<FastElementsAccessorSubclass, KindTraits> { |
1096 public: | 1103 public: |
1097 explicit FastDoubleElementsAccessor(const char* name) | 1104 explicit FastDoubleElementsAccessor(const char* name) |
1098 : FastElementsAccessor<FastElementsAccessorSubclass, | 1105 : FastElementsAccessor<FastElementsAccessorSubclass, |
1099 KindTraits>(name) {} | 1106 KindTraits>(name) {} |
1100 | 1107 |
1101 static void GrowCapacityAndConvert(Handle<JSObject> obj, uint32_t capacity) { | 1108 static void GrowCapacityAndConvertImpl(Handle<JSObject> object, |
1102 JSObject::SetFastDoubleElementsCapacity(obj, capacity); | 1109 uint32_t capacity) { |
| 1110 Handle<FixedArrayBase> elements = |
| 1111 object->GetIsolate()->factory()->NewFixedDoubleArray(capacity); |
| 1112 ElementsKind from_kind = object->GetElementsKind(); |
| 1113 ElementsKind to_kind = IsHoleyElementsKind(from_kind) |
| 1114 ? FAST_HOLEY_DOUBLE_ELEMENTS |
| 1115 : FAST_DOUBLE_ELEMENTS; |
| 1116 |
| 1117 Handle<Map> new_map = JSObject::GetElementsTransitionMap(object, to_kind); |
| 1118 |
| 1119 Handle<FixedArrayBase> old_elements(object->elements()); |
| 1120 int packed = kPackedSizeNotKnown; |
| 1121 if (IsFastPackedElementsKind(from_kind) && object->IsJSArray()) { |
| 1122 packed = Smi::cast(JSArray::cast(*object)->length())->value(); |
| 1123 } |
| 1124 CopyElementsImpl(*old_elements, 0, *elements, from_kind, 0, packed, |
| 1125 ElementsAccessor::kCopyToEndAndInitializeToHole); |
| 1126 |
| 1127 JSObject::SetMapAndElements(object, new_map, elements); |
| 1128 JSObject::ValidateElements(object); |
| 1129 |
| 1130 if (FLAG_trace_elements_transitions) { |
| 1131 JSObject::PrintElementsTransition(stdout, object, from_kind, old_elements, |
| 1132 to_kind, elements); |
| 1133 } |
1103 } | 1134 } |
1104 | 1135 |
1105 protected: | 1136 protected: |
1106 static void CopyElementsImpl(FixedArrayBase* from, uint32_t from_start, | 1137 static void CopyElementsImpl(FixedArrayBase* from, uint32_t from_start, |
1107 FixedArrayBase* to, ElementsKind from_kind, | 1138 FixedArrayBase* to, ElementsKind from_kind, |
1108 uint32_t to_start, int packed_size, | 1139 uint32_t to_start, int packed_size, |
1109 int copy_size) { | 1140 int copy_size) { |
1110 DisallowHeapAllocation no_allocation; | 1141 DisallowHeapAllocation no_allocation; |
1111 switch (from_kind) { | 1142 switch (from_kind) { |
1112 case FAST_SMI_ELEMENTS: | 1143 case FAST_SMI_ELEMENTS: |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1657 *backing_store, capacity - length); | 1688 *backing_store, capacity - length); |
1658 } else { | 1689 } else { |
1659 // Otherwise, fill the unused tail with holes. | 1690 // Otherwise, fill the unused tail with holes. |
1660 for (uint32_t i = length; i < old_length; i++) { | 1691 for (uint32_t i = length; i < old_length; i++) { |
1661 BackingStore::cast(*backing_store)->set_the_hole(i); | 1692 BackingStore::cast(*backing_store)->set_the_hole(i); |
1662 } | 1693 } |
1663 } | 1694 } |
1664 } else { | 1695 } else { |
1665 // Check whether the backing store should be expanded. | 1696 // Check whether the backing store should be expanded. |
1666 capacity = Max(length, JSObject::NewElementsCapacity(capacity)); | 1697 capacity = Max(length, JSObject::NewElementsCapacity(capacity)); |
1667 ElementsAccessorSubclass::GrowCapacityAndConvert(array, capacity); | 1698 ElementsAccessorSubclass::GrowCapacityAndConvertImpl(array, capacity); |
1668 } | 1699 } |
1669 | 1700 |
1670 array->set_length(Smi::FromInt(length)); | 1701 array->set_length(Smi::FromInt(length)); |
1671 JSObject::ValidateElements(array); | 1702 JSObject::ValidateElements(array); |
1672 } | 1703 } |
1673 | 1704 |
1674 | 1705 |
1675 MaybeHandle<Object> ArrayConstructInitializeElements(Handle<JSArray> array, | 1706 MaybeHandle<Object> ArrayConstructInitializeElements(Handle<JSArray> array, |
1676 Arguments* args) { | 1707 Arguments* args) { |
1677 if (args->length() == 0) { | 1708 if (args->length() == 0) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1757 break; | 1788 break; |
1758 } | 1789 } |
1759 | 1790 |
1760 array->set_elements(*elms); | 1791 array->set_elements(*elms); |
1761 array->set_length(Smi::FromInt(number_of_elements)); | 1792 array->set_length(Smi::FromInt(number_of_elements)); |
1762 return array; | 1793 return array; |
1763 } | 1794 } |
1764 | 1795 |
1765 } // namespace internal | 1796 } // namespace internal |
1766 } // namespace v8 | 1797 } // namespace v8 |
OLD | NEW |