| 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/objects.h" | 10 #include "src/objects.h" |
| (...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 public: | 890 public: |
| 891 explicit FastElementsAccessor(const char* name) | 891 explicit FastElementsAccessor(const char* name) |
| 892 : ElementsAccessorBase<FastElementsAccessorSubclass, | 892 : ElementsAccessorBase<FastElementsAccessorSubclass, |
| 893 KindTraits>(name) {} | 893 KindTraits>(name) {} |
| 894 protected: | 894 protected: |
| 895 friend class ElementsAccessorBase<FastElementsAccessorSubclass, KindTraits>; | 895 friend class ElementsAccessorBase<FastElementsAccessorSubclass, KindTraits>; |
| 896 friend class SloppyArgumentsElementsAccessor; | 896 friend class SloppyArgumentsElementsAccessor; |
| 897 | 897 |
| 898 typedef typename KindTraits::BackingStore BackingStore; | 898 typedef typename KindTraits::BackingStore BackingStore; |
| 899 | 899 |
| 900 // Adjusts the length of the fast backing store.. | 900 // Adjusts the length of the fast backing store or returns the new length or |
| 901 // undefined in case conversion to a slow backing store should be performed. |
| 901 static Handle<Object> SetLengthWithoutNormalize( | 902 static Handle<Object> SetLengthWithoutNormalize( |
| 902 Handle<FixedArrayBase> backing_store, | 903 Handle<FixedArrayBase> backing_store, |
| 903 Handle<JSArray> array, | 904 Handle<JSArray> array, |
| 904 Handle<Object> length_object, | 905 Handle<Object> length_object, |
| 905 uint32_t length) { | 906 uint32_t length) { |
| 906 Isolate* isolate = array->GetIsolate(); | 907 Isolate* isolate = array->GetIsolate(); |
| 907 uint32_t old_capacity = backing_store->length(); | 908 uint32_t old_capacity = backing_store->length(); |
| 908 Handle<Object> old_length(array->length(), isolate); | 909 Handle<Object> old_length(array->length(), isolate); |
| 909 bool same_or_smaller_size = old_length->IsSmi() && | 910 bool same_or_smaller_size = old_length->IsSmi() && |
| 910 static_cast<uint32_t>(Handle<Smi>::cast(old_length)->value()) >= length; | 911 static_cast<uint32_t>(Handle<Smi>::cast(old_length)->value()) >= length; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 for (int i = length; i < old_length; i++) { | 943 for (int i = length; i < old_length; i++) { |
| 943 Handle<BackingStore>::cast(backing_store)->set_the_hole(i); | 944 Handle<BackingStore>::cast(backing_store)->set_the_hole(i); |
| 944 } | 945 } |
| 945 } | 946 } |
| 946 return length_object; | 947 return length_object; |
| 947 } | 948 } |
| 948 | 949 |
| 949 // Check whether the backing store should be expanded. | 950 // Check whether the backing store should be expanded. |
| 950 uint32_t min = JSObject::NewElementsCapacity(old_capacity); | 951 uint32_t min = JSObject::NewElementsCapacity(old_capacity); |
| 951 uint32_t new_capacity = length > min ? length : min; | 952 uint32_t new_capacity = length > min ? length : min; |
| 952 FastElementsAccessorSubclass::SetFastElementsCapacityAndLength( | 953 if (!array->ShouldConvertToSlowElements(new_capacity)) { |
| 953 array, new_capacity, length); | 954 FastElementsAccessorSubclass::SetFastElementsCapacityAndLength( |
| 954 JSObject::ValidateElements(array); | 955 array, new_capacity, length); |
| 955 return length_object; | 956 JSObject::ValidateElements(array); |
| 957 return length_object; |
| 958 } |
| 959 |
| 960 // Request conversion to slow elements. |
| 961 return isolate->factory()->undefined_value(); |
| 956 } | 962 } |
| 957 | 963 |
| 958 static Handle<Object> DeleteCommon(Handle<JSObject> obj, | 964 static Handle<Object> DeleteCommon(Handle<JSObject> obj, |
| 959 uint32_t key, | 965 uint32_t key, |
| 960 JSReceiver::DeleteMode mode) { | 966 JSReceiver::DeleteMode mode) { |
| 961 ASSERT(obj->HasFastSmiOrObjectElements() || | 967 ASSERT(obj->HasFastSmiOrObjectElements() || |
| 962 obj->HasFastDoubleElements() || | 968 obj->HasFastDoubleElements() || |
| 963 obj->HasFastArgumentsElements()); | 969 obj->HasFastArgumentsElements()); |
| 964 Isolate* isolate = obj->GetIsolate(); | 970 Isolate* isolate = obj->GetIsolate(); |
| 965 Heap* heap = obj->GetHeap(); | 971 Heap* heap = obj->GetHeap(); |
| (...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1984 UNREACHABLE(); | 1990 UNREACHABLE(); |
| 1985 break; | 1991 break; |
| 1986 } | 1992 } |
| 1987 | 1993 |
| 1988 array->set_elements(*elms); | 1994 array->set_elements(*elms); |
| 1989 array->set_length(Smi::FromInt(number_of_elements)); | 1995 array->set_length(Smi::FromInt(number_of_elements)); |
| 1990 return array; | 1996 return array; |
| 1991 } | 1997 } |
| 1992 | 1998 |
| 1993 } } // namespace v8::internal | 1999 } } // namespace v8::internal |
| OLD | NEW |