OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 } | 777 } |
778 | 778 |
779 MUST_USE_RESULT static MaybeObject* SetFastElementsCapacityAndLength( | 779 MUST_USE_RESULT static MaybeObject* SetFastElementsCapacityAndLength( |
780 JSObject* obj, | 780 JSObject* obj, |
781 int capacity, | 781 int capacity, |
782 int length) { | 782 int length) { |
783 UNIMPLEMENTED(); | 783 UNIMPLEMENTED(); |
784 return obj; | 784 return obj; |
785 } | 785 } |
786 | 786 |
787 // TODO(ishell): Temporary wrapper until handlified. | |
788 MUST_USE_RESULT static Handle<FixedArray> SetFastElementsCapacityAndLength( | |
789 Handle<JSObject> obj, | |
790 int capacity, | |
791 int length) { | |
792 CALL_HEAP_FUNCTION(obj->GetIsolate(), | |
793 SetFastElementsCapacityAndLength(*obj, capacity, length), | |
794 FixedArray); | |
795 } | |
796 | |
797 MUST_USE_RESULT virtual Handle<Object> Delete( | 787 MUST_USE_RESULT virtual Handle<Object> Delete( |
798 Handle<JSObject> obj, | 788 Handle<JSObject> obj, |
799 uint32_t key, | 789 uint32_t key, |
800 JSReceiver::DeleteMode mode) V8_OVERRIDE = 0; | 790 JSReceiver::DeleteMode mode) V8_OVERRIDE = 0; |
801 | 791 |
802 MUST_USE_RESULT static MaybeObject* CopyElementsImpl(FixedArrayBase* from, | 792 MUST_USE_RESULT static MaybeObject* CopyElementsImpl(FixedArrayBase* from, |
803 uint32_t from_start, | 793 uint32_t from_start, |
804 FixedArrayBase* to, | 794 FixedArrayBase* to, |
805 ElementsKind from_kind, | 795 ElementsKind from_kind, |
806 uint32_t to_start, | 796 uint32_t to_start, |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
981 : ElementsAccessorBase<FastElementsAccessorSubclass, | 971 : ElementsAccessorBase<FastElementsAccessorSubclass, |
982 KindTraits>(name) {} | 972 KindTraits>(name) {} |
983 protected: | 973 protected: |
984 friend class ElementsAccessorBase<FastElementsAccessorSubclass, KindTraits>; | 974 friend class ElementsAccessorBase<FastElementsAccessorSubclass, KindTraits>; |
985 friend class SloppyArgumentsElementsAccessor; | 975 friend class SloppyArgumentsElementsAccessor; |
986 | 976 |
987 typedef typename KindTraits::BackingStore BackingStore; | 977 typedef typename KindTraits::BackingStore BackingStore; |
988 | 978 |
989 // Adjusts the length of the fast backing store or returns the new length or | 979 // Adjusts the length of the fast backing store or returns the new length or |
990 // undefined in case conversion to a slow backing store should be performed. | 980 // undefined in case conversion to a slow backing store should be performed. |
991 static Handle<Object> SetLengthWithoutNormalize( | 981 static MaybeObject* SetLengthWithoutNormalize(FixedArrayBase* backing_store, |
992 Handle<FixedArrayBase> backing_store, | 982 JSArray* array, |
993 Handle<JSArray> array, | 983 Object* length_object, |
994 Handle<Object> length_object, | 984 uint32_t length) { |
995 uint32_t length) { | |
996 Isolate* isolate = array->GetIsolate(); | |
997 uint32_t old_capacity = backing_store->length(); | 985 uint32_t old_capacity = backing_store->length(); |
998 Handle<Object> old_length(array->length(), isolate); | 986 Object* old_length = array->length(); |
999 bool same_or_smaller_size = old_length->IsSmi() && | 987 bool same_or_smaller_size = old_length->IsSmi() && |
1000 static_cast<uint32_t>(Handle<Smi>::cast(old_length)->value()) >= length; | 988 static_cast<uint32_t>(Smi::cast(old_length)->value()) >= length; |
1001 ElementsKind kind = array->GetElementsKind(); | 989 ElementsKind kind = array->GetElementsKind(); |
1002 | 990 |
1003 if (!same_or_smaller_size && IsFastElementsKind(kind) && | 991 if (!same_or_smaller_size && IsFastElementsKind(kind) && |
1004 !IsFastHoleyElementsKind(kind)) { | 992 !IsFastHoleyElementsKind(kind)) { |
1005 kind = GetHoleyElementsKind(kind); | 993 kind = GetHoleyElementsKind(kind); |
1006 JSObject::TransitionElementsKind(array, kind); | 994 MaybeObject* maybe_obj = array->TransitionElementsKind(kind); |
| 995 if (maybe_obj->IsFailure()) return maybe_obj; |
1007 } | 996 } |
1008 | 997 |
1009 // Check whether the backing store should be shrunk. | 998 // Check whether the backing store should be shrunk. |
1010 if (length <= old_capacity) { | 999 if (length <= old_capacity) { |
1011 if (array->HasFastSmiOrObjectElements()) { | 1000 if (array->HasFastSmiOrObjectElements()) { |
1012 backing_store = JSObject::EnsureWritableFastElements(array); | 1001 MaybeObject* maybe_obj = array->EnsureWritableFastElements(); |
| 1002 if (!maybe_obj->To(&backing_store)) return maybe_obj; |
1013 } | 1003 } |
1014 if (2 * length <= old_capacity) { | 1004 if (2 * length <= old_capacity) { |
1015 // If more than half the elements won't be used, trim the array. | 1005 // If more than half the elements won't be used, trim the array. |
1016 if (length == 0) { | 1006 if (length == 0) { |
1017 array->initialize_elements(); | 1007 array->initialize_elements(); |
1018 } else { | 1008 } else { |
1019 backing_store->set_length(length); | 1009 backing_store->set_length(length); |
1020 Address filler_start = backing_store->address() + | 1010 Address filler_start = backing_store->address() + |
1021 BackingStore::OffsetOfElementAt(length); | 1011 BackingStore::OffsetOfElementAt(length); |
1022 int filler_size = (old_capacity - length) * ElementSize; | 1012 int filler_size = (old_capacity - length) * ElementSize; |
1023 array->GetHeap()->CreateFillerObjectAt(filler_start, filler_size); | 1013 array->GetHeap()->CreateFillerObjectAt(filler_start, filler_size); |
1024 } | 1014 } |
1025 } else { | 1015 } else { |
1026 // Otherwise, fill the unused tail with holes. | 1016 // Otherwise, fill the unused tail with holes. |
1027 int old_length = FastD2IChecked(array->length()->Number()); | 1017 int old_length = FastD2IChecked(array->length()->Number()); |
1028 for (int i = length; i < old_length; i++) { | 1018 for (int i = length; i < old_length; i++) { |
1029 Handle<BackingStore>::cast(backing_store)->set_the_hole(i); | 1019 BackingStore::cast(backing_store)->set_the_hole(i); |
1030 } | 1020 } |
1031 } | 1021 } |
1032 return length_object; | 1022 return length_object; |
1033 } | 1023 } |
1034 | 1024 |
1035 // Check whether the backing store should be expanded. | 1025 // Check whether the backing store should be expanded. |
1036 uint32_t min = JSObject::NewElementsCapacity(old_capacity); | 1026 uint32_t min = JSObject::NewElementsCapacity(old_capacity); |
1037 uint32_t new_capacity = length > min ? length : min; | 1027 uint32_t new_capacity = length > min ? length : min; |
1038 if (!array->ShouldConvertToSlowElements(new_capacity)) { | 1028 if (!array->ShouldConvertToSlowElements(new_capacity)) { |
1039 FastElementsAccessorSubclass:: | 1029 MaybeObject* result = FastElementsAccessorSubclass:: |
1040 SetFastElementsCapacityAndLength(array, new_capacity, length); | 1030 SetFastElementsCapacityAndLength(array, new_capacity, length); |
| 1031 if (result->IsFailure()) return result; |
1041 array->ValidateElements(); | 1032 array->ValidateElements(); |
1042 return length_object; | 1033 return length_object; |
1043 } | 1034 } |
1044 | 1035 |
1045 // Request conversion to slow elements. | 1036 // Request conversion to slow elements. |
1046 return isolate->factory()->undefined_value(); | 1037 return array->GetHeap()->undefined_value(); |
| 1038 } |
| 1039 |
| 1040 // TODO(ishell): Temporary wrapper until handlified. |
| 1041 static Handle<Object> SetLengthWithoutNormalize( |
| 1042 Handle<FixedArrayBase> backing_store, |
| 1043 Handle<JSArray> array, |
| 1044 Handle<Object> length_object, |
| 1045 uint32_t length) { |
| 1046 CALL_HEAP_FUNCTION(array->GetIsolate(), |
| 1047 SetLengthWithoutNormalize( |
| 1048 *backing_store, *array, *length_object, length), |
| 1049 Object); |
1047 } | 1050 } |
1048 | 1051 |
1049 static Handle<Object> DeleteCommon(Handle<JSObject> obj, | 1052 static Handle<Object> DeleteCommon(Handle<JSObject> obj, |
1050 uint32_t key, | 1053 uint32_t key, |
1051 JSReceiver::DeleteMode mode) { | 1054 JSReceiver::DeleteMode mode) { |
1052 ASSERT(obj->HasFastSmiOrObjectElements() || | 1055 ASSERT(obj->HasFastSmiOrObjectElements() || |
1053 obj->HasFastDoubleElements() || | 1056 obj->HasFastDoubleElements() || |
1054 obj->HasFastArgumentsElements()); | 1057 obj->HasFastArgumentsElements()); |
1055 Isolate* isolate = obj->GetIsolate(); | 1058 Isolate* isolate = obj->GetIsolate(); |
1056 Heap* heap = obj->GetHeap(); | 1059 Heap* heap = obj->GetHeap(); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1234 uint32_t capacity, | 1237 uint32_t capacity, |
1235 uint32_t length) { | 1238 uint32_t length) { |
1236 JSObject::SetFastElementsCapacitySmiMode set_capacity_mode = | 1239 JSObject::SetFastElementsCapacitySmiMode set_capacity_mode = |
1237 obj->HasFastSmiElements() | 1240 obj->HasFastSmiElements() |
1238 ? JSObject::kAllowSmiElements | 1241 ? JSObject::kAllowSmiElements |
1239 : JSObject::kDontAllowSmiElements; | 1242 : JSObject::kDontAllowSmiElements; |
1240 return obj->SetFastElementsCapacityAndLength(capacity, | 1243 return obj->SetFastElementsCapacityAndLength(capacity, |
1241 length, | 1244 length, |
1242 set_capacity_mode); | 1245 set_capacity_mode); |
1243 } | 1246 } |
1244 | |
1245 // TODO(ishell): Temporary wrapper until handlified. | |
1246 static Handle<FixedArray> SetFastElementsCapacityAndLength( | |
1247 Handle<JSObject> obj, | |
1248 int capacity, | |
1249 int length) { | |
1250 CALL_HEAP_FUNCTION(obj->GetIsolate(), | |
1251 SetFastElementsCapacityAndLength(*obj, capacity, length), | |
1252 FixedArray); | |
1253 } | |
1254 }; | 1247 }; |
1255 | 1248 |
1256 | 1249 |
1257 class FastPackedSmiElementsAccessor | 1250 class FastPackedSmiElementsAccessor |
1258 : public FastSmiOrObjectElementsAccessor< | 1251 : public FastSmiOrObjectElementsAccessor< |
1259 FastPackedSmiElementsAccessor, | 1252 FastPackedSmiElementsAccessor, |
1260 ElementsKindTraits<FAST_SMI_ELEMENTS> > { | 1253 ElementsKindTraits<FAST_SMI_ELEMENTS> > { |
1261 public: | 1254 public: |
1262 explicit FastPackedSmiElementsAccessor(const char* name) | 1255 explicit FastPackedSmiElementsAccessor(const char* name) |
1263 : FastSmiOrObjectElementsAccessor< | 1256 : FastSmiOrObjectElementsAccessor< |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1314 KindTraits, | 1307 KindTraits, |
1315 kDoubleSize>(name) {} | 1308 kDoubleSize>(name) {} |
1316 | 1309 |
1317 static MaybeObject* SetFastElementsCapacityAndLength(JSObject* obj, | 1310 static MaybeObject* SetFastElementsCapacityAndLength(JSObject* obj, |
1318 uint32_t capacity, | 1311 uint32_t capacity, |
1319 uint32_t length) { | 1312 uint32_t length) { |
1320 return obj->SetFastDoubleElementsCapacityAndLength(capacity, | 1313 return obj->SetFastDoubleElementsCapacityAndLength(capacity, |
1321 length); | 1314 length); |
1322 } | 1315 } |
1323 | 1316 |
1324 // TODO(ishell): Temporary wrapper until handlified. | |
1325 static Handle<FixedArray> SetFastElementsCapacityAndLength( | |
1326 Handle<JSObject> obj, | |
1327 int capacity, | |
1328 int length) { | |
1329 CALL_HEAP_FUNCTION(obj->GetIsolate(), | |
1330 SetFastElementsCapacityAndLength(*obj, capacity, length), | |
1331 FixedArray); | |
1332 } | |
1333 | |
1334 protected: | 1317 protected: |
1335 static MaybeObject* CopyElementsImpl(FixedArrayBase* from, | 1318 static MaybeObject* CopyElementsImpl(FixedArrayBase* from, |
1336 uint32_t from_start, | 1319 uint32_t from_start, |
1337 FixedArrayBase* to, | 1320 FixedArrayBase* to, |
1338 ElementsKind from_kind, | 1321 ElementsKind from_kind, |
1339 uint32_t to_start, | 1322 uint32_t to_start, |
1340 int packed_size, | 1323 int packed_size, |
1341 int copy_size) { | 1324 int copy_size) { |
1342 switch (from_kind) { | 1325 switch (from_kind) { |
1343 case FAST_SMI_ELEMENTS: | 1326 case FAST_SMI_ELEMENTS: |
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2112 UNREACHABLE(); | 2095 UNREACHABLE(); |
2113 break; | 2096 break; |
2114 } | 2097 } |
2115 | 2098 |
2116 array->set_elements(*elms); | 2099 array->set_elements(*elms); |
2117 array->set_length(Smi::FromInt(number_of_elements)); | 2100 array->set_length(Smi::FromInt(number_of_elements)); |
2118 return array; | 2101 return array; |
2119 } | 2102 } |
2120 | 2103 |
2121 } } // namespace v8::internal | 2104 } } // namespace v8::internal |
OLD | NEW |