| 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 (function(global, utils, extrasUtils) { | 5 (function(global, utils, extrasUtils) { |
| 6 | 6 |
| 7 "use strict"; | 7 "use strict"; |
| 8 | 8 |
| 9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
| 10 | 10 |
| 11 // ------------------------------------------------------------------- | 11 // ------------------------------------------------------------------- |
| 12 // Imports | 12 // Imports |
| 13 | 13 |
| 14 var Delete; | 14 var Delete; |
| 15 var GlobalArray = global.Array; | 15 var GlobalArray = global.Array; |
| 16 var InternalArray = utils.InternalArray; | 16 var InternalArray = utils.InternalArray; |
| 17 var InternalPackedArray = utils.InternalPackedArray; | 17 var InternalPackedArray = utils.InternalPackedArray; |
| 18 var MathMin; | 18 var MathMin; |
| 19 var ObjectHasOwnProperty; | 19 var ObjectHasOwnProperty; |
| 20 var ObjectIsFrozen; | 20 var ObjectIsFrozen; |
| 21 var ObjectIsSealed; | 21 var ObjectIsSealed; |
| 22 var ObjectToString; | 22 var ObjectToString; |
| 23 var ObserveBeginPerformSplice; |
| 24 var ObserveEndPerformSplice; |
| 25 var ObserveEnqueueSpliceRecord; |
| 23 var unscopablesSymbol = utils.ImportNow("unscopables_symbol"); | 26 var unscopablesSymbol = utils.ImportNow("unscopables_symbol"); |
| 24 | 27 |
| 25 utils.Import(function(from) { | 28 utils.Import(function(from) { |
| 26 Delete = from.Delete; | 29 Delete = from.Delete; |
| 27 MathMin = from.MathMin; | 30 MathMin = from.MathMin; |
| 28 ObjectHasOwnProperty = from.ObjectHasOwnProperty; | 31 ObjectHasOwnProperty = from.ObjectHasOwnProperty; |
| 29 ObjectIsFrozen = from.ObjectIsFrozen; | 32 ObjectIsFrozen = from.ObjectIsFrozen; |
| 30 ObjectIsSealed = from.ObjectIsSealed; | 33 ObjectIsSealed = from.ObjectIsSealed; |
| 31 ObjectToString = from.ObjectToString; | 34 ObjectToString = from.ObjectToString; |
| 35 ObserveBeginPerformSplice = from.ObserveBeginPerformSplice; |
| 36 ObserveEndPerformSplice = from.ObserveEndPerformSplice; |
| 37 ObserveEnqueueSpliceRecord = from.ObserveEnqueueSpliceRecord; |
| 32 }); | 38 }); |
| 33 | 39 |
| 34 // ------------------------------------------------------------------- | 40 // ------------------------------------------------------------------- |
| 35 | 41 |
| 36 // Global list of arrays visited during toString, toLocaleString and | 42 // Global list of arrays visited during toString, toLocaleString and |
| 37 // join invocations. | 43 // join invocations. |
| 38 var visited_arrays = new InternalArray(); | 44 var visited_arrays = new InternalArray(); |
| 39 | 45 |
| 40 | 46 |
| 41 // Gets a sorted array of array keys. Useful for operations on sparse | 47 // Gets a sorted array of array keys. Useful for operations on sparse |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 | 436 |
| 431 return InnerArrayJoin(separator, array, length); | 437 return InnerArrayJoin(separator, array, length); |
| 432 } | 438 } |
| 433 | 439 |
| 434 | 440 |
| 435 function ObservedArrayPop(n) { | 441 function ObservedArrayPop(n) { |
| 436 n--; | 442 n--; |
| 437 var value = this[n]; | 443 var value = this[n]; |
| 438 | 444 |
| 439 try { | 445 try { |
| 440 $observeBeginPerformSplice(this); | 446 ObserveBeginPerformSplice(this); |
| 441 delete this[n]; | 447 delete this[n]; |
| 442 this.length = n; | 448 this.length = n; |
| 443 } finally { | 449 } finally { |
| 444 $observeEndPerformSplice(this); | 450 ObserveEndPerformSplice(this); |
| 445 $observeEnqueueSpliceRecord(this, n, [value], 0); | 451 ObserveEnqueueSpliceRecord(this, n, [value], 0); |
| 446 } | 452 } |
| 447 | 453 |
| 448 return value; | 454 return value; |
| 449 } | 455 } |
| 450 | 456 |
| 451 | 457 |
| 452 // Removes the last element from the array and returns it. See | 458 // Removes the last element from the array and returns it. See |
| 453 // ECMA-262, section 15.4.4.6. | 459 // ECMA-262, section 15.4.4.6. |
| 454 function ArrayPop() { | 460 function ArrayPop() { |
| 455 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.pop"); | 461 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.pop"); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 470 array.length = n; | 476 array.length = n; |
| 471 return value; | 477 return value; |
| 472 } | 478 } |
| 473 | 479 |
| 474 | 480 |
| 475 function ObservedArrayPush() { | 481 function ObservedArrayPush() { |
| 476 var n = TO_LENGTH_OR_UINT32(this.length); | 482 var n = TO_LENGTH_OR_UINT32(this.length); |
| 477 var m = %_ArgumentsLength(); | 483 var m = %_ArgumentsLength(); |
| 478 | 484 |
| 479 try { | 485 try { |
| 480 $observeBeginPerformSplice(this); | 486 ObserveBeginPerformSplice(this); |
| 481 for (var i = 0; i < m; i++) { | 487 for (var i = 0; i < m; i++) { |
| 482 this[i+n] = %_Arguments(i); | 488 this[i+n] = %_Arguments(i); |
| 483 } | 489 } |
| 484 var new_length = n + m; | 490 var new_length = n + m; |
| 485 this.length = new_length; | 491 this.length = new_length; |
| 486 } finally { | 492 } finally { |
| 487 $observeEndPerformSplice(this); | 493 ObserveEndPerformSplice(this); |
| 488 $observeEnqueueSpliceRecord(this, n, [], m); | 494 ObserveEnqueueSpliceRecord(this, n, [], m); |
| 489 } | 495 } |
| 490 | 496 |
| 491 return new_length; | 497 return new_length; |
| 492 } | 498 } |
| 493 | 499 |
| 494 | 500 |
| 495 // Appends the arguments to the end of the array and returns the new | 501 // Appends the arguments to the end of the array and returns the new |
| 496 // length of the array. See ECMA-262, section 15.4.4.7. | 502 // length of the array. See ECMA-262, section 15.4.4.7. |
| 497 function ArrayPush() { | 503 function ArrayPush() { |
| 498 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.push"); | 504 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.push"); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 } else { | 616 } else { |
| 611 return GenericArrayReverse(array, len); | 617 return GenericArrayReverse(array, len); |
| 612 } | 618 } |
| 613 } | 619 } |
| 614 | 620 |
| 615 | 621 |
| 616 function ObservedArrayShift(len) { | 622 function ObservedArrayShift(len) { |
| 617 var first = this[0]; | 623 var first = this[0]; |
| 618 | 624 |
| 619 try { | 625 try { |
| 620 $observeBeginPerformSplice(this); | 626 ObserveBeginPerformSplice(this); |
| 621 SimpleMove(this, 0, 1, len, 0); | 627 SimpleMove(this, 0, 1, len, 0); |
| 622 this.length = len - 1; | 628 this.length = len - 1; |
| 623 } finally { | 629 } finally { |
| 624 $observeEndPerformSplice(this); | 630 ObserveEndPerformSplice(this); |
| 625 $observeEnqueueSpliceRecord(this, 0, [first], 0); | 631 ObserveEnqueueSpliceRecord(this, 0, [first], 0); |
| 626 } | 632 } |
| 627 | 633 |
| 628 return first; | 634 return first; |
| 629 } | 635 } |
| 630 | 636 |
| 631 | 637 |
| 632 function ArrayShift() { | 638 function ArrayShift() { |
| 633 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.shift"); | 639 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.shift"); |
| 634 | 640 |
| 635 var array = TO_OBJECT(this); | 641 var array = TO_OBJECT(this); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 657 | 663 |
| 658 return first; | 664 return first; |
| 659 } | 665 } |
| 660 | 666 |
| 661 | 667 |
| 662 function ObservedArrayUnshift() { | 668 function ObservedArrayUnshift() { |
| 663 var len = TO_LENGTH_OR_UINT32(this.length); | 669 var len = TO_LENGTH_OR_UINT32(this.length); |
| 664 var num_arguments = %_ArgumentsLength(); | 670 var num_arguments = %_ArgumentsLength(); |
| 665 | 671 |
| 666 try { | 672 try { |
| 667 $observeBeginPerformSplice(this); | 673 ObserveBeginPerformSplice(this); |
| 668 SimpleMove(this, 0, 0, len, num_arguments); | 674 SimpleMove(this, 0, 0, len, num_arguments); |
| 669 for (var i = 0; i < num_arguments; i++) { | 675 for (var i = 0; i < num_arguments; i++) { |
| 670 this[i] = %_Arguments(i); | 676 this[i] = %_Arguments(i); |
| 671 } | 677 } |
| 672 var new_length = len + num_arguments; | 678 var new_length = len + num_arguments; |
| 673 this.length = new_length; | 679 this.length = new_length; |
| 674 } finally { | 680 } finally { |
| 675 $observeEndPerformSplice(this); | 681 ObserveEndPerformSplice(this); |
| 676 $observeEnqueueSpliceRecord(this, 0, [], num_arguments); | 682 ObserveEnqueueSpliceRecord(this, 0, [], num_arguments); |
| 677 } | 683 } |
| 678 | 684 |
| 679 return new_length; | 685 return new_length; |
| 680 } | 686 } |
| 681 | 687 |
| 682 | 688 |
| 683 function ArrayUnshift(arg1) { // length == 1 | 689 function ArrayUnshift(arg1) { // length == 1 |
| 684 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.unshift"); | 690 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.unshift"); |
| 685 | 691 |
| 686 if (%IsObserved(this)) | 692 if (%IsObserved(this)) |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 var num_arguments = %_ArgumentsLength(); | 790 var num_arguments = %_ArgumentsLength(); |
| 785 var len = TO_LENGTH_OR_UINT32(this.length); | 791 var len = TO_LENGTH_OR_UINT32(this.length); |
| 786 var start_i = ComputeSpliceStartIndex(TO_INTEGER(start), len); | 792 var start_i = ComputeSpliceStartIndex(TO_INTEGER(start), len); |
| 787 var del_count = ComputeSpliceDeleteCount(delete_count, num_arguments, len, | 793 var del_count = ComputeSpliceDeleteCount(delete_count, num_arguments, len, |
| 788 start_i); | 794 start_i); |
| 789 var deleted_elements = []; | 795 var deleted_elements = []; |
| 790 deleted_elements.length = del_count; | 796 deleted_elements.length = del_count; |
| 791 var num_elements_to_add = num_arguments > 2 ? num_arguments - 2 : 0; | 797 var num_elements_to_add = num_arguments > 2 ? num_arguments - 2 : 0; |
| 792 | 798 |
| 793 try { | 799 try { |
| 794 $observeBeginPerformSplice(this); | 800 ObserveBeginPerformSplice(this); |
| 795 | 801 |
| 796 SimpleSlice(this, start_i, del_count, len, deleted_elements); | 802 SimpleSlice(this, start_i, del_count, len, deleted_elements); |
| 797 SimpleMove(this, start_i, del_count, len, num_elements_to_add); | 803 SimpleMove(this, start_i, del_count, len, num_elements_to_add); |
| 798 | 804 |
| 799 // Insert the arguments into the resulting array in | 805 // Insert the arguments into the resulting array in |
| 800 // place of the deleted elements. | 806 // place of the deleted elements. |
| 801 var i = start_i; | 807 var i = start_i; |
| 802 var arguments_index = 2; | 808 var arguments_index = 2; |
| 803 var arguments_length = %_ArgumentsLength(); | 809 var arguments_length = %_ArgumentsLength(); |
| 804 while (arguments_index < arguments_length) { | 810 while (arguments_index < arguments_length) { |
| 805 this[i++] = %_Arguments(arguments_index++); | 811 this[i++] = %_Arguments(arguments_index++); |
| 806 } | 812 } |
| 807 this.length = len - del_count + num_elements_to_add; | 813 this.length = len - del_count + num_elements_to_add; |
| 808 | 814 |
| 809 } finally { | 815 } finally { |
| 810 $observeEndPerformSplice(this); | 816 ObserveEndPerformSplice(this); |
| 811 if (deleted_elements.length || num_elements_to_add) { | 817 if (deleted_elements.length || num_elements_to_add) { |
| 812 $observeEnqueueSpliceRecord(this, | 818 ObserveEnqueueSpliceRecord(this, |
| 813 start_i, | 819 start_i, |
| 814 deleted_elements.slice(), | 820 deleted_elements.slice(), |
| 815 num_elements_to_add); | 821 num_elements_to_add); |
| 816 } | 822 } |
| 817 } | 823 } |
| 818 | 824 |
| 819 // Return the deleted elements. | 825 // Return the deleted elements. |
| 820 return deleted_elements; | 826 return deleted_elements; |
| 821 } | 827 } |
| 822 | 828 |
| 823 | 829 |
| 824 function ArraySplice(start, delete_count) { | 830 function ArraySplice(start, delete_count) { |
| 825 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.splice"); | 831 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.splice"); |
| (...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1661 %InstallToContext([ | 1667 %InstallToContext([ |
| 1662 "array_pop", ArrayPop, | 1668 "array_pop", ArrayPop, |
| 1663 "array_push", ArrayPush, | 1669 "array_push", ArrayPush, |
| 1664 "array_shift", ArrayShift, | 1670 "array_shift", ArrayShift, |
| 1665 "array_splice", ArraySplice, | 1671 "array_splice", ArraySplice, |
| 1666 "array_slice", ArraySlice, | 1672 "array_slice", ArraySlice, |
| 1667 "array_unshift", ArrayUnshift, | 1673 "array_unshift", ArrayUnshift, |
| 1668 ]); | 1674 ]); |
| 1669 | 1675 |
| 1670 }); | 1676 }); |
| OLD | NEW |