| 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 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 | 501 |
| 502 if (new_length > elms->length()) { | 502 if (new_length > elms->length()) { |
| 503 // New backing storage is needed. | 503 // New backing storage is needed. |
| 504 int capacity = new_length + (new_length >> 1) + 16; | 504 int capacity = new_length + (new_length >> 1) + 16; |
| 505 Object* obj; | 505 Object* obj; |
| 506 { MaybeObject* maybe_obj = heap->AllocateUninitializedFixedArray(capacity); | 506 { MaybeObject* maybe_obj = heap->AllocateUninitializedFixedArray(capacity); |
| 507 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 507 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
| 508 } | 508 } |
| 509 FixedArray* new_elms = FixedArray::cast(obj); | 509 FixedArray* new_elms = FixedArray::cast(obj); |
| 510 | 510 |
| 511 AssertNoAllocation no_gc; | 511 CopyObjectToObjectElements(elms, FAST_ELEMENTS, 0, |
| 512 CopyObjectToObjectElements(&no_gc, elms, FAST_ELEMENTS, 0, | |
| 513 new_elms, FAST_ELEMENTS, 0, len); | 512 new_elms, FAST_ELEMENTS, 0, len); |
| 514 FillWithHoles(heap, new_elms, new_length, capacity); | 513 FillWithHoles(heap, new_elms, new_length, capacity); |
| 515 | 514 |
| 516 elms = new_elms; | 515 elms = new_elms; |
| 517 } | 516 } |
| 518 | 517 |
| 519 // Add the provided values. | 518 // Add the provided values. |
| 520 AssertNoAllocation no_gc; | 519 AssertNoAllocation no_gc; |
| 521 WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc); | 520 WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc); |
| 522 for (int index = 0; index < to_add; index++) { | 521 for (int index = 0; index < to_add; index++) { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 if (maybe_object->IsFailure()) return maybe_object; | 637 if (maybe_object->IsFailure()) return maybe_object; |
| 639 | 638 |
| 640 if (new_length > elms->length()) { | 639 if (new_length > elms->length()) { |
| 641 // New backing storage is needed. | 640 // New backing storage is needed. |
| 642 int capacity = new_length + (new_length >> 1) + 16; | 641 int capacity = new_length + (new_length >> 1) + 16; |
| 643 Object* obj; | 642 Object* obj; |
| 644 { MaybeObject* maybe_obj = heap->AllocateUninitializedFixedArray(capacity); | 643 { MaybeObject* maybe_obj = heap->AllocateUninitializedFixedArray(capacity); |
| 645 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 644 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
| 646 } | 645 } |
| 647 FixedArray* new_elms = FixedArray::cast(obj); | 646 FixedArray* new_elms = FixedArray::cast(obj); |
| 648 AssertNoAllocation no_gc; | 647 CopyObjectToObjectElements(elms, FAST_ELEMENTS, 0, |
| 649 CopyObjectToObjectElements(&no_gc, elms, FAST_ELEMENTS, 0, | |
| 650 new_elms, FAST_ELEMENTS, to_add, len); | 648 new_elms, FAST_ELEMENTS, to_add, len); |
| 651 FillWithHoles(heap, new_elms, new_length, capacity); | 649 FillWithHoles(heap, new_elms, new_length, capacity); |
| 652 elms = new_elms; | 650 elms = new_elms; |
| 653 array->set_elements(elms); | 651 array->set_elements(elms); |
| 654 } else { | 652 } else { |
| 655 AssertNoAllocation no_gc; | 653 AssertNoAllocation no_gc; |
| 656 MoveElements(heap, &no_gc, elms, to_add, elms, 0, len); | 654 MoveElements(heap, &no_gc, elms, to_add, elms, 0, len); |
| 657 } | 655 } |
| 658 | 656 |
| 659 // Add the provided values. | 657 // Add the provided values. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 // Calculate the length of result array. | 748 // Calculate the length of result array. |
| 751 int result_len = Max(final - k, 0); | 749 int result_len = Max(final - k, 0); |
| 752 | 750 |
| 753 MaybeObject* maybe_array = | 751 MaybeObject* maybe_array = |
| 754 heap->AllocateJSArrayAndStorage(elements_kind, | 752 heap->AllocateJSArrayAndStorage(elements_kind, |
| 755 result_len, | 753 result_len, |
| 756 result_len); | 754 result_len); |
| 757 JSArray* result_array; | 755 JSArray* result_array; |
| 758 if (!maybe_array->To(&result_array)) return maybe_array; | 756 if (!maybe_array->To(&result_array)) return maybe_array; |
| 759 | 757 |
| 760 AssertNoAllocation no_gc; | 758 CopyObjectToObjectElements(elms, FAST_ELEMENTS, k, |
| 761 CopyObjectToObjectElements(&no_gc, elms, FAST_ELEMENTS, k, | |
| 762 FixedArray::cast(result_array->elements()), | 759 FixedArray::cast(result_array->elements()), |
| 763 FAST_ELEMENTS, 0, result_len); | 760 FAST_ELEMENTS, 0, result_len); |
| 764 | 761 |
| 765 return result_array; | 762 return result_array; |
| 766 } | 763 } |
| 767 | 764 |
| 768 | 765 |
| 769 BUILTIN(ArraySplice) { | 766 BUILTIN(ArraySplice) { |
| 770 Heap* heap = isolate->heap(); | 767 Heap* heap = isolate->heap(); |
| 771 Object* receiver = *args.receiver(); | 768 Object* receiver = *args.receiver(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 JSArray* result_array = NULL; | 821 JSArray* result_array = NULL; |
| 825 ElementsKind elements_kind = | 822 ElementsKind elements_kind = |
| 826 JSObject::cast(receiver)->GetElementsKind(); | 823 JSObject::cast(receiver)->GetElementsKind(); |
| 827 MaybeObject* maybe_array = | 824 MaybeObject* maybe_array = |
| 828 heap->AllocateJSArrayAndStorage(elements_kind, | 825 heap->AllocateJSArrayAndStorage(elements_kind, |
| 829 actual_delete_count, | 826 actual_delete_count, |
| 830 actual_delete_count); | 827 actual_delete_count); |
| 831 if (!maybe_array->To(&result_array)) return maybe_array; | 828 if (!maybe_array->To(&result_array)) return maybe_array; |
| 832 | 829 |
| 833 { | 830 { |
| 834 AssertNoAllocation no_gc; | |
| 835 // Fill newly created array. | 831 // Fill newly created array. |
| 836 CopyObjectToObjectElements(&no_gc, elms, FAST_ELEMENTS, actual_start, | 832 CopyObjectToObjectElements(elms, FAST_ELEMENTS, actual_start, |
| 837 FixedArray::cast(result_array->elements()), | 833 FixedArray::cast(result_array->elements()), |
| 838 FAST_ELEMENTS, 0, actual_delete_count); | 834 FAST_ELEMENTS, 0, actual_delete_count); |
| 839 } | 835 } |
| 840 | 836 |
| 841 int item_count = (n_arguments > 1) ? (n_arguments - 2) : 0; | 837 int item_count = (n_arguments > 1) ? (n_arguments - 2) : 0; |
| 842 int new_length = len - actual_delete_count + item_count; | 838 int new_length = len - actual_delete_count + item_count; |
| 843 | 839 |
| 844 bool elms_changed = false; | 840 bool elms_changed = false; |
| 845 if (item_count < actual_delete_count) { | 841 if (item_count < actual_delete_count) { |
| 846 // Shrink the array. | 842 // Shrink the array. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 876 // New backing storage is needed. | 872 // New backing storage is needed. |
| 877 int capacity = new_length + (new_length >> 1) + 16; | 873 int capacity = new_length + (new_length >> 1) + 16; |
| 878 Object* obj; | 874 Object* obj; |
| 879 { MaybeObject* maybe_obj = | 875 { MaybeObject* maybe_obj = |
| 880 heap->AllocateUninitializedFixedArray(capacity); | 876 heap->AllocateUninitializedFixedArray(capacity); |
| 881 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 877 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
| 882 } | 878 } |
| 883 FixedArray* new_elms = FixedArray::cast(obj); | 879 FixedArray* new_elms = FixedArray::cast(obj); |
| 884 | 880 |
| 885 { | 881 { |
| 886 AssertNoAllocation no_gc; | |
| 887 // Copy the part before actual_start as is. | 882 // Copy the part before actual_start as is. |
| 888 CopyObjectToObjectElements(&no_gc, elms, FAST_ELEMENTS, 0, | 883 CopyObjectToObjectElements(elms, FAST_ELEMENTS, 0, |
| 889 new_elms, FAST_ELEMENTS, 0, actual_start); | 884 new_elms, FAST_ELEMENTS, 0, actual_start); |
| 890 const int to_copy = len - actual_delete_count - actual_start; | 885 const int to_copy = len - actual_delete_count - actual_start; |
| 891 CopyObjectToObjectElements(&no_gc, elms, FAST_ELEMENTS, | 886 CopyObjectToObjectElements(elms, FAST_ELEMENTS, |
| 892 actual_start + actual_delete_count, | 887 actual_start + actual_delete_count, |
| 893 new_elms, FAST_ELEMENTS, | 888 new_elms, FAST_ELEMENTS, |
| 894 actual_start + item_count, to_copy); | 889 actual_start + item_count, to_copy); |
| 895 } | 890 } |
| 896 | 891 |
| 897 FillWithHoles(heap, new_elms, new_length, capacity); | 892 FillWithHoles(heap, new_elms, new_length, capacity); |
| 898 | 893 |
| 899 elms = new_elms; | 894 elms = new_elms; |
| 900 elms_changed = true; | 895 elms_changed = true; |
| 901 } else { | 896 } else { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 // Allocate result. | 961 // Allocate result. |
| 967 JSArray* result_array; | 962 JSArray* result_array; |
| 968 MaybeObject* maybe_array = | 963 MaybeObject* maybe_array = |
| 969 heap->AllocateJSArrayAndStorage(elements_kind, | 964 heap->AllocateJSArrayAndStorage(elements_kind, |
| 970 result_len, | 965 result_len, |
| 971 result_len); | 966 result_len); |
| 972 if (!maybe_array->To(&result_array)) return maybe_array; | 967 if (!maybe_array->To(&result_array)) return maybe_array; |
| 973 if (result_len == 0) return result_array; | 968 if (result_len == 0) return result_array; |
| 974 | 969 |
| 975 // Copy data. | 970 // Copy data. |
| 976 AssertNoAllocation no_gc; | |
| 977 int start_pos = 0; | 971 int start_pos = 0; |
| 978 FixedArray* result_elms(FixedArray::cast(result_array->elements())); | 972 FixedArray* result_elms(FixedArray::cast(result_array->elements())); |
| 979 for (int i = 0; i < n_arguments; i++) { | 973 for (int i = 0; i < n_arguments; i++) { |
| 980 JSArray* array = JSArray::cast(args[i]); | 974 JSArray* array = JSArray::cast(args[i]); |
| 981 int len = Smi::cast(array->length())->value(); | 975 int len = Smi::cast(array->length())->value(); |
| 982 FixedArray* elms = FixedArray::cast(array->elements()); | 976 FixedArray* elms = FixedArray::cast(array->elements()); |
| 983 CopyObjectToObjectElements(&no_gc, elms, FAST_ELEMENTS, 0, | 977 CopyObjectToObjectElements(elms, FAST_ELEMENTS, 0, |
| 984 result_elms, FAST_ELEMENTS, | 978 result_elms, FAST_ELEMENTS, |
| 985 start_pos, len); | 979 start_pos, len); |
| 986 start_pos += len; | 980 start_pos += len; |
| 987 } | 981 } |
| 988 ASSERT(start_pos == result_len); | 982 ASSERT(start_pos == result_len); |
| 989 | 983 |
| 990 return result_array; | 984 return result_array; |
| 991 } | 985 } |
| 992 | 986 |
| 993 | 987 |
| (...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1738 return Handle<Code>(code_address); \ | 1732 return Handle<Code>(code_address); \ |
| 1739 } | 1733 } |
| 1740 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 1734 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
| 1741 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 1735 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 1742 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 1736 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 1743 #undef DEFINE_BUILTIN_ACCESSOR_C | 1737 #undef DEFINE_BUILTIN_ACCESSOR_C |
| 1744 #undef DEFINE_BUILTIN_ACCESSOR_A | 1738 #undef DEFINE_BUILTIN_ACCESSOR_A |
| 1745 | 1739 |
| 1746 | 1740 |
| 1747 } } // namespace v8::internal | 1741 } } // namespace v8::internal |
| OLD | NEW |