OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 if (maybe_object->IsFailure()) return maybe_object; | 765 if (maybe_object->IsFailure()) return maybe_object; |
766 | 766 |
767 AssertNoAllocation no_gc; | 767 AssertNoAllocation no_gc; |
768 CopyElements(heap, &no_gc, result_elms, 0, elms, k, result_len); | 768 CopyElements(heap, &no_gc, result_elms, 0, elms, k, result_len); |
769 | 769 |
770 // Set elements. | 770 // Set elements. |
771 result_array->set_elements(result_elms); | 771 result_array->set_elements(result_elms); |
772 | 772 |
773 // Set the length. | 773 // Set the length. |
774 result_array->set_length(Smi::FromInt(result_len)); | 774 result_array->set_length(Smi::FromInt(result_len)); |
| 775 |
| 776 // Set the ElementsKind. |
| 777 ElementsKind elements_kind = JSObject::cast(receiver)->GetElementsKind(); |
| 778 if (result_array->GetElementsKind() != elements_kind) { |
| 779 MaybeObject* maybe = result_array->TransitionElementsKind(elements_kind); |
| 780 if (maybe->IsFailure()) return maybe; |
| 781 } |
775 return result_array; | 782 return result_array; |
776 } | 783 } |
777 | 784 |
778 | 785 |
779 BUILTIN(ArraySplice) { | 786 BUILTIN(ArraySplice) { |
780 Heap* heap = isolate->heap(); | 787 Heap* heap = isolate->heap(); |
781 Object* receiver = *args.receiver(); | 788 Object* receiver = *args.receiver(); |
782 Object* elms_obj; | 789 Object* elms_obj; |
783 { MaybeObject* maybe_elms_obj = | 790 { MaybeObject* maybe_elms_obj = |
784 EnsureJSArrayWithWritableFastElements(heap, receiver, &args, 3); | 791 EnsureJSArrayWithWritableFastElements(heap, receiver, &args, 3); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 &no_gc, | 865 &no_gc, |
859 result_elms, 0, | 866 result_elms, 0, |
860 elms, actual_start, | 867 elms, actual_start, |
861 actual_delete_count); | 868 actual_delete_count); |
862 | 869 |
863 // Set elements. | 870 // Set elements. |
864 result_array->set_elements(result_elms); | 871 result_array->set_elements(result_elms); |
865 | 872 |
866 // Set the length. | 873 // Set the length. |
867 result_array->set_length(Smi::FromInt(actual_delete_count)); | 874 result_array->set_length(Smi::FromInt(actual_delete_count)); |
| 875 |
| 876 // Set the ElementsKind. |
| 877 ElementsKind elements_kind = array->GetElementsKind(); |
| 878 if (result_array->GetElementsKind() != elements_kind) { |
| 879 MaybeObject* maybe = result_array->TransitionElementsKind(elements_kind); |
| 880 if (maybe->IsFailure()) return maybe; |
| 881 } |
868 } | 882 } |
869 | 883 |
870 int item_count = (n_arguments > 1) ? (n_arguments - 2) : 0; | 884 int item_count = (n_arguments > 1) ? (n_arguments - 2) : 0; |
871 int new_length = len - actual_delete_count + item_count; | 885 int new_length = len - actual_delete_count + item_count; |
872 | 886 |
873 bool elms_changed = false; | 887 bool elms_changed = false; |
874 if (item_count < actual_delete_count) { | 888 if (item_count < actual_delete_count) { |
875 // Shrink the array. | 889 // Shrink the array. |
876 const bool trim_array = !heap->lo_space()->Contains(elms) && | 890 const bool trim_array = !heap->lo_space()->Contains(elms) && |
877 ((actual_start + item_count) < | 891 ((actual_start + item_count) < |
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1772 return Handle<Code>(code_address); \ | 1786 return Handle<Code>(code_address); \ |
1773 } | 1787 } |
1774 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 1788 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
1775 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 1789 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
1776 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 1790 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
1777 #undef DEFINE_BUILTIN_ACCESSOR_C | 1791 #undef DEFINE_BUILTIN_ACCESSOR_C |
1778 #undef DEFINE_BUILTIN_ACCESSOR_A | 1792 #undef DEFINE_BUILTIN_ACCESSOR_A |
1779 | 1793 |
1780 | 1794 |
1781 } } // namespace v8::internal | 1795 } } // namespace v8::internal |
OLD | NEW |