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 // 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 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 434 ["Array.prototype.pop"]); | 434 ["Array.prototype.pop"]); |
| 435 } | 435 } |
| 436 | 436 |
| 437 var n = TO_UINT32(this.length); | 437 var n = TO_UINT32(this.length); |
| 438 if (n == 0) { | 438 if (n == 0) { |
| 439 this.length = n; | 439 this.length = n; |
| 440 return; | 440 return; |
| 441 } | 441 } |
| 442 n--; | 442 n--; |
| 443 var value = this[n]; | 443 var value = this[n]; |
| 444 delete this[n]; | |
|
adamk
2012/11/09 12:06:30
This change is required for proper operation, and
| |
| 444 this.length = n; | 445 this.length = n; |
| 445 delete this[n]; | |
| 446 return value; | 446 return value; |
| 447 } | 447 } |
| 448 | 448 |
| 449 | 449 |
| 450 // Appends the arguments to the end of the array and returns the new | 450 // Appends the arguments to the end of the array and returns the new |
| 451 // length of the array. See ECMA-262, section 15.4.4.7. | 451 // length of the array. See ECMA-262, section 15.4.4.7. |
| 452 function ArrayPush() { | 452 function ArrayPush() { |
| 453 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 453 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 454 throw MakeTypeError("called_on_null_or_undefined", | 454 throw MakeTypeError("called_on_null_or_undefined", |
| 455 ["Array.prototype.push"]); | 455 ["Array.prototype.push"]); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 574 | 574 |
| 575 var len = TO_UINT32(this.length); | 575 var len = TO_UINT32(this.length); |
| 576 | 576 |
| 577 if (len === 0) { | 577 if (len === 0) { |
| 578 this.length = 0; | 578 this.length = 0; |
| 579 return; | 579 return; |
| 580 } | 580 } |
| 581 | 581 |
| 582 var first = this[0]; | 582 var first = this[0]; |
| 583 | 583 |
| 584 if (IS_ARRAY(this)) { | 584 if (IS_ARRAY(this) && !%IsObserved(this)) { |
| 585 SmartMove(this, 0, 1, len, 0); | 585 SmartMove(this, 0, 1, len, 0); |
| 586 } else { | 586 } else { |
| 587 SimpleMove(this, 0, 1, len, 0); | 587 SimpleMove(this, 0, 1, len, 0); |
| 588 } | 588 } |
| 589 | 589 |
| 590 this.length = len - 1; | 590 this.length = len - 1; |
| 591 | 591 |
| 592 return first; | 592 return first; |
| 593 } | 593 } |
| 594 | 594 |
| 595 | 595 |
| 596 function ArrayUnshift(arg1) { // length == 1 | 596 function ArrayUnshift(arg1) { // length == 1 |
| 597 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 597 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 598 throw MakeTypeError("called_on_null_or_undefined", | 598 throw MakeTypeError("called_on_null_or_undefined", |
| 599 ["Array.prototype.unshift"]); | 599 ["Array.prototype.unshift"]); |
| 600 } | 600 } |
| 601 | 601 |
| 602 var len = TO_UINT32(this.length); | 602 var len = TO_UINT32(this.length); |
| 603 var num_arguments = %_ArgumentsLength(); | 603 var num_arguments = %_ArgumentsLength(); |
| 604 | 604 |
| 605 if (IS_ARRAY(this)) { | 605 if (IS_ARRAY(this) && !%IsObserved(this)) { |
| 606 SmartMove(this, 0, 0, len, num_arguments); | 606 SmartMove(this, 0, 0, len, num_arguments); |
| 607 } else { | 607 } else { |
| 608 SimpleMove(this, 0, 0, len, num_arguments); | 608 SimpleMove(this, 0, 0, len, num_arguments); |
| 609 } | 609 } |
| 610 | 610 |
| 611 for (var i = 0; i < num_arguments; i++) { | 611 for (var i = 0; i < num_arguments; i++) { |
| 612 this[i] = %_Arguments(i); | 612 this[i] = %_Arguments(i); |
| 613 } | 613 } |
| 614 | 614 |
| 615 this.length = len + num_arguments; | 615 this.length = len + num_arguments; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 642 if (end_i < 0) end_i = 0; | 642 if (end_i < 0) end_i = 0; |
| 643 } else { | 643 } else { |
| 644 if (end_i > len) end_i = len; | 644 if (end_i > len) end_i = len; |
| 645 } | 645 } |
| 646 | 646 |
| 647 var result = []; | 647 var result = []; |
| 648 | 648 |
| 649 if (end_i < start_i) return result; | 649 if (end_i < start_i) return result; |
| 650 | 650 |
| 651 if (IS_ARRAY(this) && | 651 if (IS_ARRAY(this) && |
| 652 !%IsObserved(this) && | |
| 652 (end_i > 1000) && | 653 (end_i > 1000) && |
| 653 (%EstimateNumberOfElements(this) < end_i)) { | 654 (%EstimateNumberOfElements(this) < end_i)) { |
| 654 SmartSlice(this, start_i, end_i - start_i, len, result); | 655 SmartSlice(this, start_i, end_i - start_i, len, result); |
| 655 } else { | 656 } else { |
| 656 SimpleSlice(this, start_i, end_i - start_i, len, result); | 657 SimpleSlice(this, start_i, end_i - start_i, len, result); |
| 657 } | 658 } |
| 658 | 659 |
| 659 result.length = end_i - start_i; | 660 result.length = end_i - start_i; |
| 660 | 661 |
| 661 return result; | 662 return result; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 698 deleted_elements.length = del_count; | 699 deleted_elements.length = del_count; |
| 699 | 700 |
| 700 // Number of elements to add. | 701 // Number of elements to add. |
| 701 var num_additional_args = 0; | 702 var num_additional_args = 0; |
| 702 if (num_arguments > 2) { | 703 if (num_arguments > 2) { |
| 703 num_additional_args = num_arguments - 2; | 704 num_additional_args = num_arguments - 2; |
| 704 } | 705 } |
| 705 | 706 |
| 706 var use_simple_splice = true; | 707 var use_simple_splice = true; |
| 707 | 708 |
| 708 if (IS_ARRAY(this) && num_additional_args !== del_count) { | 709 if (IS_ARRAY(this) && |
| 710 !%IsObserved(this) && | |
| 711 num_additional_args !== del_count) { | |
| 709 // If we are only deleting/moving a few things near the end of the | 712 // If we are only deleting/moving a few things near the end of the |
| 710 // array then the simple version is going to be faster, because it | 713 // array then the simple version is going to be faster, because it |
| 711 // doesn't touch most of the array. | 714 // doesn't touch most of the array. |
| 712 var estimated_non_hole_elements = %EstimateNumberOfElements(this); | 715 var estimated_non_hole_elements = %EstimateNumberOfElements(this); |
| 713 if (len > 20 && (estimated_non_hole_elements >> 2) < (len - start_i)) { | 716 if (len > 20 && (estimated_non_hole_elements >> 2) < (len - start_i)) { |
| 714 use_simple_splice = false; | 717 use_simple_splice = false; |
| 715 } | 718 } |
| 716 } | 719 } |
| 717 | 720 |
| 718 if (use_simple_splice) { | 721 if (use_simple_splice) { |
| (...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1551 SetUpLockedPrototype(InternalArray, $Array(), $Array( | 1554 SetUpLockedPrototype(InternalArray, $Array(), $Array( |
| 1552 "indexOf", getFunction("indexOf", ArrayIndexOf), | 1555 "indexOf", getFunction("indexOf", ArrayIndexOf), |
| 1553 "join", getFunction("join", ArrayJoin), | 1556 "join", getFunction("join", ArrayJoin), |
| 1554 "pop", getFunction("pop", ArrayPop), | 1557 "pop", getFunction("pop", ArrayPop), |
| 1555 "push", getFunction("push", ArrayPush), | 1558 "push", getFunction("push", ArrayPush), |
| 1556 "splice", getFunction("splice", ArraySplice) | 1559 "splice", getFunction("splice", ArraySplice) |
| 1557 )); | 1560 )); |
| 1558 } | 1561 } |
| 1559 | 1562 |
| 1560 SetUpArray(); | 1563 SetUpArray(); |
| OLD | NEW |