Chromium Code Reviews| 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 "use strict"; | 5 "use strict"; |
| 6 | 6 |
| 7 // This file relies on the fact that the following declarations have been made | 7 // This file relies on the fact that the following declarations have been made |
| 8 // in runtime.js: | 8 // in runtime.js: |
| 9 // var $Array = global.Array; | 9 // var $Array = global.Array; |
| 10 | 10 |
| (...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 717 return del_count; | 717 return del_count; |
| 718 } | 718 } |
| 719 | 719 |
| 720 | 720 |
| 721 function ObservedArraySplice(start, delete_count) { | 721 function ObservedArraySplice(start, delete_count) { |
| 722 var num_arguments = %_ArgumentsLength(); | 722 var num_arguments = %_ArgumentsLength(); |
| 723 var len = TO_UINT32(this.length); | 723 var len = TO_UINT32(this.length); |
| 724 var start_i = ComputeSpliceStartIndex(TO_INTEGER(start), len); | 724 var start_i = ComputeSpliceStartIndex(TO_INTEGER(start), len); |
| 725 var del_count = ComputeSpliceDeleteCount(delete_count, num_arguments, len, | 725 var del_count = ComputeSpliceDeleteCount(delete_count, num_arguments, len, |
| 726 start_i); | 726 start_i); |
| 727 var deleted_elements = []; | 727 var deleted_elements = new InternalArray(del_count); |
| 728 deleted_elements.length = del_count; | |
| 729 var num_elements_to_add = num_arguments > 2 ? num_arguments - 2 : 0; | 728 var num_elements_to_add = num_arguments > 2 ? num_arguments - 2 : 0; |
| 730 | 729 |
| 731 try { | 730 try { |
| 732 BeginPerformSplice(this); | 731 BeginPerformSplice(this); |
| 733 | 732 |
| 734 SimpleSlice(this, start_i, del_count, len, deleted_elements); | 733 SimpleSlice(this, start_i, del_count, len, deleted_elements); |
| 735 SimpleMove(this, start_i, del_count, len, num_elements_to_add); | 734 SimpleMove(this, start_i, del_count, len, num_elements_to_add); |
| 736 | 735 |
| 737 // Insert the arguments into the resulting array in | 736 // Insert the arguments into the resulting array in |
| 738 // place of the deleted elements. | 737 // place of the deleted elements. |
| 739 var i = start_i; | 738 var i = start_i; |
| 740 var arguments_index = 2; | 739 var arguments_index = 2; |
| 741 var arguments_length = %_ArgumentsLength(); | 740 var arguments_length = %_ArgumentsLength(); |
| 742 while (arguments_index < arguments_length) { | 741 while (arguments_index < arguments_length) { |
| 743 this[i++] = %_Arguments(arguments_index++); | 742 this[i++] = %_Arguments(arguments_index++); |
| 744 } | 743 } |
| 745 this.length = len - del_count + num_elements_to_add; | 744 this.length = len - del_count + num_elements_to_add; |
| 746 | 745 |
| 747 } finally { | 746 } finally { |
| 748 EndPerformSplice(this); | 747 EndPerformSplice(this); |
| 749 if (deleted_elements.length || num_elements_to_add) { | 748 if (deleted_elements.length || num_elements_to_add) { |
| 750 EnqueueSpliceRecord(this, | 749 var deleted_array = []; |
| 751 start_i, | 750 %MoveArrayContents(deleted_elements, deleted_array); |
| 752 deleted_elements.slice(), | 751 EnqueueSpliceRecord(this, start_i, deleted_array, num_elements_to_add); |
| 753 num_elements_to_add); | |
| 754 } | 752 } |
| 755 } | 753 } |
| 756 | 754 |
| 757 // Return the deleted elements. | 755 // Return the deleted elements. |
| 758 return deleted_elements; | 756 return deleted_elements; |
| 759 } | 757 } |
| 760 | 758 |
| 761 | 759 |
| 762 function ArraySplice(start, delete_count) { | 760 function ArraySplice(start, delete_count) { |
| 763 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.splice"); | 761 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.splice"); |
| 764 | 762 |
| 765 if (%IsObserved(this)) | 763 if (%IsObserved(this)) |
| 766 return ObservedArraySplice.apply(this, arguments); | 764 return ObservedArraySplice.apply(this, arguments); |
| 767 | 765 |
| 768 var num_arguments = %_ArgumentsLength(); | 766 var num_arguments = %_ArgumentsLength(); |
| 769 var array = TO_OBJECT_INLINE(this); | 767 var array = TO_OBJECT_INLINE(this); |
| 770 var len = TO_UINT32(array.length); | 768 var len = TO_UINT32(array.length); |
| 771 var start_i = ComputeSpliceStartIndex(TO_INTEGER(start), len); | 769 var start_i = ComputeSpliceStartIndex(TO_INTEGER(start), len); |
| 772 var del_count = ComputeSpliceDeleteCount(delete_count, num_arguments, len, | 770 var del_count = ComputeSpliceDeleteCount(delete_count, num_arguments, len, |
| 773 start_i); | 771 start_i); |
| 774 var deleted_elements = []; | 772 var deleted_elements = []; |
|
Toon Verwaest
2014/06/02 09:31:15
Now that you are fixing this above, can you also f
rafaelw
2014/06/02 20:32:56
So I tried doing this, but array-natives-elements.
| |
| 775 deleted_elements.length = del_count; | 773 deleted_elements.length = del_count; |
| 776 var num_elements_to_add = num_arguments > 2 ? num_arguments - 2 : 0; | 774 var num_elements_to_add = num_arguments > 2 ? num_arguments - 2 : 0; |
| 777 | 775 |
| 778 if (del_count != num_elements_to_add && ObjectIsSealed(array)) { | 776 if (del_count != num_elements_to_add && ObjectIsSealed(array)) { |
| 779 throw MakeTypeError("array_functions_change_sealed", | 777 throw MakeTypeError("array_functions_change_sealed", |
| 780 ["Array.prototype.splice"]); | 778 ["Array.prototype.splice"]); |
| 781 } else if (del_count > 0 && ObjectIsFrozen(array)) { | 779 } else if (del_count > 0 && ObjectIsFrozen(array)) { |
| 782 throw MakeTypeError("array_functions_on_frozen", | 780 throw MakeTypeError("array_functions_on_frozen", |
| 783 ["Array.prototype.splice"]); | 781 ["Array.prototype.splice"]); |
| 784 } | 782 } |
| (...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1525 )); | 1523 )); |
| 1526 | 1524 |
| 1527 SetUpLockedPrototype(InternalPackedArray, $Array(), $Array( | 1525 SetUpLockedPrototype(InternalPackedArray, $Array(), $Array( |
| 1528 "join", getFunction("join", ArrayJoin), | 1526 "join", getFunction("join", ArrayJoin), |
| 1529 "pop", getFunction("pop", ArrayPop), | 1527 "pop", getFunction("pop", ArrayPop), |
| 1530 "push", getFunction("push", ArrayPush) | 1528 "push", getFunction("push", ArrayPush) |
| 1531 )); | 1529 )); |
| 1532 } | 1530 } |
| 1533 | 1531 |
| 1534 SetUpArray(); | 1532 SetUpArray(); |
| OLD | NEW |