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 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 typedef typename KindTraits::BackingStore BackingStore; | 763 typedef typename KindTraits::BackingStore BackingStore; |
764 | 764 |
765 // Adjusts the length of the fast backing store or returns the new length or | 765 // Adjusts the length of the fast backing store or returns the new length or |
766 // undefined in case conversion to a slow backing store should be performed. | 766 // undefined in case conversion to a slow backing store should be performed. |
767 static MaybeObject* SetLengthWithoutNormalize(BackingStore* backing_store, | 767 static MaybeObject* SetLengthWithoutNormalize(BackingStore* backing_store, |
768 JSArray* array, | 768 JSArray* array, |
769 Object* length_object, | 769 Object* length_object, |
770 uint32_t length) { | 770 uint32_t length) { |
771 uint32_t old_capacity = backing_store->length(); | 771 uint32_t old_capacity = backing_store->length(); |
772 Object* old_length = array->length(); | 772 Object* old_length = array->length(); |
773 bool same_size = old_length->IsSmi() && | 773 bool same_or_smaller_size = old_length->IsSmi() && |
774 static_cast<uint32_t>(Smi::cast(old_length)->value()) == length; | 774 static_cast<uint32_t>(Smi::cast(old_length)->value()) >= length; |
775 ElementsKind kind = array->GetElementsKind(); | 775 ElementsKind kind = array->GetElementsKind(); |
776 | 776 |
777 if (!same_size && IsFastElementsKind(kind) && | 777 if (!same_or_smaller_size && IsFastElementsKind(kind) && |
778 !IsFastHoleyElementsKind(kind)) { | 778 !IsFastHoleyElementsKind(kind)) { |
779 kind = GetHoleyElementsKind(kind); | 779 kind = GetHoleyElementsKind(kind); |
780 MaybeObject* maybe_obj = array->TransitionElementsKind(kind); | 780 MaybeObject* maybe_obj = array->TransitionElementsKind(kind); |
781 if (maybe_obj->IsFailure()) return maybe_obj; | 781 if (maybe_obj->IsFailure()) return maybe_obj; |
782 } | 782 } |
783 | 783 |
784 // Check whether the backing store should be shrunk. | 784 // Check whether the backing store should be shrunk. |
785 if (length <= old_capacity) { | 785 if (length <= old_capacity) { |
786 if (array->HasFastSmiOrObjectElements()) { | 786 if (array->HasFastSmiOrObjectElements()) { |
787 MaybeObject* maybe_obj = array->EnsureWritableFastElements(); | 787 MaybeObject* maybe_obj = array->EnsureWritableFastElements(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 // Request conversion to slow elements. | 822 // Request conversion to slow elements. |
823 return array->GetHeap()->undefined_value(); | 823 return array->GetHeap()->undefined_value(); |
824 } | 824 } |
825 | 825 |
826 static MaybeObject* DeleteCommon(JSObject* obj, | 826 static MaybeObject* DeleteCommon(JSObject* obj, |
827 uint32_t key, | 827 uint32_t key, |
828 JSReceiver::DeleteMode mode) { | 828 JSReceiver::DeleteMode mode) { |
829 ASSERT(obj->HasFastSmiOrObjectElements() || | 829 ASSERT(obj->HasFastSmiOrObjectElements() || |
830 obj->HasFastDoubleElements() || | 830 obj->HasFastDoubleElements() || |
831 obj->HasFastArgumentsElements()); | 831 obj->HasFastArgumentsElements()); |
| 832 Heap* heap = obj->GetHeap(); |
| 833 Object* elements = obj->elements(); |
| 834 if (elements == heap->empty_fixed_array()) { |
| 835 return heap->true_value(); |
| 836 } |
832 typename KindTraits::BackingStore* backing_store = | 837 typename KindTraits::BackingStore* backing_store = |
833 KindTraits::BackingStore::cast(obj->elements()); | 838 KindTraits::BackingStore::cast(elements); |
834 Heap* heap = obj->GetHeap(); | 839 bool is_non_strict_arguments_elements_map = |
835 if (backing_store->map() == heap->non_strict_arguments_elements_map()) { | 840 backing_store->map() == heap->non_strict_arguments_elements_map(); |
| 841 if (is_non_strict_arguments_elements_map) { |
836 backing_store = | 842 backing_store = |
837 KindTraits::BackingStore::cast( | 843 KindTraits::BackingStore::cast( |
838 FixedArray::cast(backing_store)->get(1)); | 844 FixedArray::cast(backing_store)->get(1)); |
839 } else { | |
840 ElementsKind kind = KindTraits::Kind; | |
841 if (IsFastPackedElementsKind(kind)) { | |
842 MaybeObject* transitioned = | |
843 obj->TransitionElementsKind(GetHoleyElementsKind(kind)); | |
844 if (transitioned->IsFailure()) return transitioned; | |
845 } | |
846 if (IsFastSmiOrObjectElementsKind(KindTraits::Kind)) { | |
847 Object* writable; | |
848 MaybeObject* maybe = obj->EnsureWritableFastElements(); | |
849 if (!maybe->ToObject(&writable)) return maybe; | |
850 backing_store = KindTraits::BackingStore::cast(writable); | |
851 } | |
852 } | 845 } |
853 uint32_t length = static_cast<uint32_t>( | 846 uint32_t length = static_cast<uint32_t>( |
854 obj->IsJSArray() | 847 obj->IsJSArray() |
855 ? Smi::cast(JSArray::cast(obj)->length())->value() | 848 ? Smi::cast(JSArray::cast(obj)->length())->value() |
856 : backing_store->length()); | 849 : backing_store->length()); |
857 if (key < length) { | 850 if (key < length) { |
| 851 if (!is_non_strict_arguments_elements_map) { |
| 852 ElementsKind kind = KindTraits::Kind; |
| 853 if (IsFastPackedElementsKind(kind)) { |
| 854 MaybeObject* transitioned = |
| 855 obj->TransitionElementsKind(GetHoleyElementsKind(kind)); |
| 856 if (transitioned->IsFailure()) return transitioned; |
| 857 } |
| 858 if (IsFastSmiOrObjectElementsKind(KindTraits::Kind)) { |
| 859 Object* writable; |
| 860 MaybeObject* maybe = obj->EnsureWritableFastElements(); |
| 861 if (!maybe->ToObject(&writable)) return maybe; |
| 862 backing_store = KindTraits::BackingStore::cast(writable); |
| 863 } |
| 864 } |
858 backing_store->set_the_hole(key); | 865 backing_store->set_the_hole(key); |
859 // If an old space backing store is larger than a certain size and | 866 // If an old space backing store is larger than a certain size and |
860 // has too few used values, normalize it. | 867 // has too few used values, normalize it. |
861 // To avoid doing the check on every delete we require at least | 868 // To avoid doing the check on every delete we require at least |
862 // one adjacent hole to the value being deleted. | 869 // one adjacent hole to the value being deleted. |
863 const int kMinLengthForSparsenessCheck = 64; | 870 const int kMinLengthForSparsenessCheck = 64; |
864 if (backing_store->length() >= kMinLengthForSparsenessCheck && | 871 if (backing_store->length() >= kMinLengthForSparsenessCheck && |
865 !heap->InNewSpace(backing_store) && | 872 !heap->InNewSpace(backing_store) && |
866 ((key > 0 && backing_store->is_the_hole(key - 1)) || | 873 ((key > 0 && backing_store->is_the_hole(key - 1)) || |
867 (key + 1 < length && backing_store->is_the_hole(key + 1)))) { | 874 (key + 1 < length && backing_store->is_the_hole(key + 1)))) { |
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1680 if (!maybe_obj->To(&new_backing_store)) return maybe_obj; | 1687 if (!maybe_obj->To(&new_backing_store)) return maybe_obj; |
1681 new_backing_store->set(0, length); | 1688 new_backing_store->set(0, length); |
1682 { MaybeObject* result = array->SetContent(new_backing_store); | 1689 { MaybeObject* result = array->SetContent(new_backing_store); |
1683 if (result->IsFailure()) return result; | 1690 if (result->IsFailure()) return result; |
1684 } | 1691 } |
1685 return array; | 1692 return array; |
1686 } | 1693 } |
1687 | 1694 |
1688 | 1695 |
1689 } } // namespace v8::internal | 1696 } } // namespace v8::internal |
OLD | NEW |