| 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 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 } | 744 } |
| 745 Handle<FixedArrayBase> from(from_holder->elements()); | 745 Handle<FixedArrayBase> from(from_holder->elements()); |
| 746 ElementsAccessorSubclass::CopyElementsImpl( | 746 ElementsAccessorSubclass::CopyElementsImpl( |
| 747 from, from_start, to, from_kind, to_start, packed_size, copy_size); | 747 from, from_start, to, from_kind, to_start, packed_size, copy_size); |
| 748 } | 748 } |
| 749 | 749 |
| 750 virtual MaybeHandle<FixedArray> AddElementsToFixedArray( | 750 virtual MaybeHandle<FixedArray> AddElementsToFixedArray( |
| 751 Handle<Object> receiver, | 751 Handle<Object> receiver, |
| 752 Handle<JSObject> holder, | 752 Handle<JSObject> holder, |
| 753 Handle<FixedArray> to, | 753 Handle<FixedArray> to, |
| 754 Handle<FixedArrayBase> from) V8_FINAL V8_OVERRIDE { | 754 Handle<FixedArrayBase> from, |
| 755 FixedArray::KeyFilter filter) V8_FINAL V8_OVERRIDE { |
| 755 int len0 = to->length(); | 756 int len0 = to->length(); |
| 756 #ifdef ENABLE_SLOW_DCHECKS | 757 #ifdef ENABLE_SLOW_DCHECKS |
| 757 if (FLAG_enable_slow_asserts) { | 758 if (FLAG_enable_slow_asserts) { |
| 758 for (int i = 0; i < len0; i++) { | 759 for (int i = 0; i < len0; i++) { |
| 759 DCHECK(!to->get(i)->IsTheHole()); | 760 DCHECK(!to->get(i)->IsTheHole()); |
| 760 } | 761 } |
| 761 } | 762 } |
| 762 #endif | 763 #endif |
| 763 | 764 |
| 764 // Optimize if 'other' is empty. | 765 // Optimize if 'other' is empty. |
| 765 // We cannot optimize if 'this' is empty, as other may have holes. | 766 // We cannot optimize if 'this' is empty, as other may have holes. |
| 766 uint32_t len1 = ElementsAccessorSubclass::GetCapacityImpl(from); | 767 uint32_t len1 = ElementsAccessorSubclass::GetCapacityImpl(from); |
| 767 if (len1 == 0) return to; | 768 if (len1 == 0) return to; |
| 768 | 769 |
| 769 Isolate* isolate = from->GetIsolate(); | 770 Isolate* isolate = from->GetIsolate(); |
| 770 | 771 |
| 771 // Compute how many elements are not in other. | 772 // Compute how many elements are not in other. |
| 772 uint32_t extra = 0; | 773 uint32_t extra = 0; |
| 773 for (uint32_t y = 0; y < len1; y++) { | 774 for (uint32_t y = 0; y < len1; y++) { |
| 774 uint32_t key = ElementsAccessorSubclass::GetKeyForIndexImpl(from, y); | 775 uint32_t key = ElementsAccessorSubclass::GetKeyForIndexImpl(from, y); |
| 775 if (ElementsAccessorSubclass::HasElementImpl( | 776 if (ElementsAccessorSubclass::HasElementImpl( |
| 776 receiver, holder, key, from)) { | 777 receiver, holder, key, from)) { |
| 777 Handle<Object> value; | 778 Handle<Object> value; |
| 778 ASSIGN_RETURN_ON_EXCEPTION( | 779 ASSIGN_RETURN_ON_EXCEPTION( |
| 779 isolate, value, | 780 isolate, value, |
| 780 ElementsAccessorSubclass::GetImpl(receiver, holder, key, from), | 781 ElementsAccessorSubclass::GetImpl(receiver, holder, key, from), |
| 781 FixedArray); | 782 FixedArray); |
| 782 | 783 |
| 783 DCHECK(!value->IsTheHole()); | 784 DCHECK(!value->IsTheHole()); |
| 785 |
| 786 if (filter == FixedArray::NON_SYMBOL_KEYS && value->IsSymbol()) { |
| 787 continue; |
| 788 } |
| 789 |
| 784 if (!HasKey(to, value)) { | 790 if (!HasKey(to, value)) { |
| 785 extra++; | 791 extra++; |
| 786 } | 792 } |
| 787 } | 793 } |
| 788 } | 794 } |
| 789 | 795 |
| 790 if (extra == 0) return to; | 796 if (extra == 0) return to; |
| 791 | 797 |
| 792 // Allocate the result | 798 // Allocate the result |
| 793 Handle<FixedArray> result = isolate->factory()->NewFixedArray(len0 + extra); | 799 Handle<FixedArray> result = isolate->factory()->NewFixedArray(len0 + extra); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 807 for (uint32_t y = 0; y < len1; y++) { | 813 for (uint32_t y = 0; y < len1; y++) { |
| 808 uint32_t key = | 814 uint32_t key = |
| 809 ElementsAccessorSubclass::GetKeyForIndexImpl(from, y); | 815 ElementsAccessorSubclass::GetKeyForIndexImpl(from, y); |
| 810 if (ElementsAccessorSubclass::HasElementImpl( | 816 if (ElementsAccessorSubclass::HasElementImpl( |
| 811 receiver, holder, key, from)) { | 817 receiver, holder, key, from)) { |
| 812 Handle<Object> value; | 818 Handle<Object> value; |
| 813 ASSIGN_RETURN_ON_EXCEPTION( | 819 ASSIGN_RETURN_ON_EXCEPTION( |
| 814 isolate, value, | 820 isolate, value, |
| 815 ElementsAccessorSubclass::GetImpl(receiver, holder, key, from), | 821 ElementsAccessorSubclass::GetImpl(receiver, holder, key, from), |
| 816 FixedArray); | 822 FixedArray); |
| 823 if (filter == FixedArray::NON_SYMBOL_KEYS && value->IsSymbol()) { |
| 824 continue; |
| 825 } |
| 817 if (!value->IsTheHole() && !HasKey(to, value)) { | 826 if (!value->IsTheHole() && !HasKey(to, value)) { |
| 818 result->set(len0 + index, *value); | 827 result->set(len0 + index, *value); |
| 819 index++; | 828 index++; |
| 820 } | 829 } |
| 821 } | 830 } |
| 822 } | 831 } |
| 823 DCHECK(extra == index); | 832 DCHECK(extra == index); |
| 824 return result; | 833 return result; |
| 825 } | 834 } |
| 826 | 835 |
| (...skipping 1070 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1897 UNREACHABLE(); | 1906 UNREACHABLE(); |
| 1898 break; | 1907 break; |
| 1899 } | 1908 } |
| 1900 | 1909 |
| 1901 array->set_elements(*elms); | 1910 array->set_elements(*elms); |
| 1902 array->set_length(Smi::FromInt(number_of_elements)); | 1911 array->set_length(Smi::FromInt(number_of_elements)); |
| 1903 return array; | 1912 return array; |
| 1904 } | 1913 } |
| 1905 | 1914 |
| 1906 } } // namespace v8::internal | 1915 } } // namespace v8::internal |
| OLD | NEW |