| 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 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 | 400 |
| 401 return Join(array, length, separator, ConvertToString); | 401 return Join(array, length, separator, ConvertToString); |
| 402 } | 402 } |
| 403 | 403 |
| 404 | 404 |
| 405 function ObservedArrayPop(n) { | 405 function ObservedArrayPop(n) { |
| 406 n--; | 406 n--; |
| 407 var value = this[n]; | 407 var value = this[n]; |
| 408 | 408 |
| 409 try { | 409 try { |
| 410 BeginPerformSplice(this); | 410 $observeBeginPerformSplice(this); |
| 411 delete this[n]; | 411 delete this[n]; |
| 412 this.length = n; | 412 this.length = n; |
| 413 } finally { | 413 } finally { |
| 414 EndPerformSplice(this); | 414 $observeEndPerformSplice(this); |
| 415 EnqueueSpliceRecord(this, n, [value], 0); | 415 $observeEnqueueSpliceRecord(this, n, [value], 0); |
| 416 } | 416 } |
| 417 | 417 |
| 418 return value; | 418 return value; |
| 419 } | 419 } |
| 420 | 420 |
| 421 // Removes the last element from the array and returns it. See | 421 // Removes the last element from the array and returns it. See |
| 422 // ECMA-262, section 15.4.4.6. | 422 // ECMA-262, section 15.4.4.6. |
| 423 function ArrayPop() { | 423 function ArrayPop() { |
| 424 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.pop"); | 424 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.pop"); |
| 425 | 425 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 439 array.length = n; | 439 array.length = n; |
| 440 return value; | 440 return value; |
| 441 } | 441 } |
| 442 | 442 |
| 443 | 443 |
| 444 function ObservedArrayPush() { | 444 function ObservedArrayPush() { |
| 445 var n = TO_UINT32(this.length); | 445 var n = TO_UINT32(this.length); |
| 446 var m = %_ArgumentsLength(); | 446 var m = %_ArgumentsLength(); |
| 447 | 447 |
| 448 try { | 448 try { |
| 449 BeginPerformSplice(this); | 449 $observeBeginPerformSplice(this); |
| 450 for (var i = 0; i < m; i++) { | 450 for (var i = 0; i < m; i++) { |
| 451 this[i+n] = %_Arguments(i); | 451 this[i+n] = %_Arguments(i); |
| 452 } | 452 } |
| 453 var new_length = n + m; | 453 var new_length = n + m; |
| 454 this.length = new_length; | 454 this.length = new_length; |
| 455 } finally { | 455 } finally { |
| 456 EndPerformSplice(this); | 456 $observeEndPerformSplice(this); |
| 457 EnqueueSpliceRecord(this, n, [], m); | 457 $observeEnqueueSpliceRecord(this, n, [], m); |
| 458 } | 458 } |
| 459 | 459 |
| 460 return new_length; | 460 return new_length; |
| 461 } | 461 } |
| 462 | 462 |
| 463 // Appends the arguments to the end of the array and returns the new | 463 // Appends the arguments to the end of the array and returns the new |
| 464 // length of the array. See ECMA-262, section 15.4.4.7. | 464 // length of the array. See ECMA-262, section 15.4.4.7. |
| 465 function ArrayPush() { | 465 function ArrayPush() { |
| 466 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.push"); | 466 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.push"); |
| 467 | 467 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 } | 577 } |
| 578 } | 578 } |
| 579 return array; | 579 return array; |
| 580 } | 580 } |
| 581 | 581 |
| 582 | 582 |
| 583 function ObservedArrayShift(len) { | 583 function ObservedArrayShift(len) { |
| 584 var first = this[0]; | 584 var first = this[0]; |
| 585 | 585 |
| 586 try { | 586 try { |
| 587 BeginPerformSplice(this); | 587 $observeBeginPerformSplice(this); |
| 588 SimpleMove(this, 0, 1, len, 0); | 588 SimpleMove(this, 0, 1, len, 0); |
| 589 this.length = len - 1; | 589 this.length = len - 1; |
| 590 } finally { | 590 } finally { |
| 591 EndPerformSplice(this); | 591 $observeEndPerformSplice(this); |
| 592 EnqueueSpliceRecord(this, 0, [first], 0); | 592 $observeEnqueueSpliceRecord(this, 0, [first], 0); |
| 593 } | 593 } |
| 594 | 594 |
| 595 return first; | 595 return first; |
| 596 } | 596 } |
| 597 | 597 |
| 598 function ArrayShift() { | 598 function ArrayShift() { |
| 599 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.shift"); | 599 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.shift"); |
| 600 | 600 |
| 601 var array = TO_OBJECT_INLINE(this); | 601 var array = TO_OBJECT_INLINE(this); |
| 602 var len = TO_UINT32(array.length); | 602 var len = TO_UINT32(array.length); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 625 array.length = len - 1; | 625 array.length = len - 1; |
| 626 | 626 |
| 627 return first; | 627 return first; |
| 628 } | 628 } |
| 629 | 629 |
| 630 function ObservedArrayUnshift() { | 630 function ObservedArrayUnshift() { |
| 631 var len = TO_UINT32(this.length); | 631 var len = TO_UINT32(this.length); |
| 632 var num_arguments = %_ArgumentsLength(); | 632 var num_arguments = %_ArgumentsLength(); |
| 633 | 633 |
| 634 try { | 634 try { |
| 635 BeginPerformSplice(this); | 635 $observeBeginPerformSplice(this); |
| 636 SimpleMove(this, 0, 0, len, num_arguments); | 636 SimpleMove(this, 0, 0, len, num_arguments); |
| 637 for (var i = 0; i < num_arguments; i++) { | 637 for (var i = 0; i < num_arguments; i++) { |
| 638 this[i] = %_Arguments(i); | 638 this[i] = %_Arguments(i); |
| 639 } | 639 } |
| 640 var new_length = len + num_arguments; | 640 var new_length = len + num_arguments; |
| 641 this.length = new_length; | 641 this.length = new_length; |
| 642 } finally { | 642 } finally { |
| 643 EndPerformSplice(this); | 643 $observeEndPerformSplice(this); |
| 644 EnqueueSpliceRecord(this, 0, [], num_arguments); | 644 $observeEnqueueSpliceRecord(this, 0, [], num_arguments); |
| 645 } | 645 } |
| 646 | 646 |
| 647 return new_length; | 647 return new_length; |
| 648 } | 648 } |
| 649 | 649 |
| 650 function ArrayUnshift(arg1) { // length == 1 | 650 function ArrayUnshift(arg1) { // length == 1 |
| 651 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.unshift"); | 651 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.unshift"); |
| 652 | 652 |
| 653 if (%IsObserved(this)) | 653 if (%IsObserved(this)) |
| 654 return ObservedArrayUnshift.apply(this, arguments); | 654 return ObservedArrayUnshift.apply(this, arguments); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 var num_arguments = %_ArgumentsLength(); | 751 var num_arguments = %_ArgumentsLength(); |
| 752 var len = TO_UINT32(this.length); | 752 var len = TO_UINT32(this.length); |
| 753 var start_i = ComputeSpliceStartIndex(TO_INTEGER(start), len); | 753 var start_i = ComputeSpliceStartIndex(TO_INTEGER(start), len); |
| 754 var del_count = ComputeSpliceDeleteCount(delete_count, num_arguments, len, | 754 var del_count = ComputeSpliceDeleteCount(delete_count, num_arguments, len, |
| 755 start_i); | 755 start_i); |
| 756 var deleted_elements = []; | 756 var deleted_elements = []; |
| 757 deleted_elements.length = del_count; | 757 deleted_elements.length = del_count; |
| 758 var num_elements_to_add = num_arguments > 2 ? num_arguments - 2 : 0; | 758 var num_elements_to_add = num_arguments > 2 ? num_arguments - 2 : 0; |
| 759 | 759 |
| 760 try { | 760 try { |
| 761 BeginPerformSplice(this); | 761 $observeBeginPerformSplice(this); |
| 762 | 762 |
| 763 SimpleSlice(this, start_i, del_count, len, deleted_elements); | 763 SimpleSlice(this, start_i, del_count, len, deleted_elements); |
| 764 SimpleMove(this, start_i, del_count, len, num_elements_to_add); | 764 SimpleMove(this, start_i, del_count, len, num_elements_to_add); |
| 765 | 765 |
| 766 // Insert the arguments into the resulting array in | 766 // Insert the arguments into the resulting array in |
| 767 // place of the deleted elements. | 767 // place of the deleted elements. |
| 768 var i = start_i; | 768 var i = start_i; |
| 769 var arguments_index = 2; | 769 var arguments_index = 2; |
| 770 var arguments_length = %_ArgumentsLength(); | 770 var arguments_length = %_ArgumentsLength(); |
| 771 while (arguments_index < arguments_length) { | 771 while (arguments_index < arguments_length) { |
| 772 this[i++] = %_Arguments(arguments_index++); | 772 this[i++] = %_Arguments(arguments_index++); |
| 773 } | 773 } |
| 774 this.length = len - del_count + num_elements_to_add; | 774 this.length = len - del_count + num_elements_to_add; |
| 775 | 775 |
| 776 } finally { | 776 } finally { |
| 777 EndPerformSplice(this); | 777 $observeEndPerformSplice(this); |
| 778 if (deleted_elements.length || num_elements_to_add) { | 778 if (deleted_elements.length || num_elements_to_add) { |
| 779 EnqueueSpliceRecord(this, | 779 $observeEnqueueSpliceRecord(this, |
| 780 start_i, | 780 start_i, |
| 781 deleted_elements.slice(), | 781 deleted_elements.slice(), |
| 782 num_elements_to_add); | 782 num_elements_to_add); |
| 783 } | 783 } |
| 784 } | 784 } |
| 785 | 785 |
| 786 // Return the deleted elements. | 786 // Return the deleted elements. |
| 787 return deleted_elements; | 787 return deleted_elements; |
| 788 } | 788 } |
| 789 | 789 |
| 790 | 790 |
| 791 function ArraySplice(start, delete_count) { | 791 function ArraySplice(start, delete_count) { |
| 792 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.splice"); | 792 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.splice"); |
| (...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1571 ]); | 1571 ]); |
| 1572 | 1572 |
| 1573 SetUpLockedPrototype(InternalPackedArray, $Array(), [ | 1573 SetUpLockedPrototype(InternalPackedArray, $Array(), [ |
| 1574 "join", getFunction("join", ArrayJoin), | 1574 "join", getFunction("join", ArrayJoin), |
| 1575 "pop", getFunction("pop", ArrayPop), | 1575 "pop", getFunction("pop", ArrayPop), |
| 1576 "push", getFunction("push", ArrayPush) | 1576 "push", getFunction("push", ArrayPush) |
| 1577 ]); | 1577 ]); |
| 1578 } | 1578 } |
| 1579 | 1579 |
| 1580 SetUpArray(); | 1580 SetUpArray(); |
| OLD | NEW |