Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(503)

Side by Side Diff: src/array.js

Issue 1238593003: Array.prototype.reverse should call [[HasProperty]] on elements before [[Get]] (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Changes from code review Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/harmony-typedarray.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 var $arrayConcat; 5 var $arrayConcat;
6 var $arrayPush; 6 var $arrayPush;
7 var $arrayPop; 7 var $arrayPop;
8 var $arrayShift; 8 var $arrayShift;
9 var $arraySlice; 9 var $arraySlice;
10 var $arraySplice; 10 var $arraySplice;
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 } else { 580 } else {
581 var current_j = array[high]; 581 var current_j = array[high];
582 if (!IS_UNDEFINED(current_j) || high in array) { 582 if (!IS_UNDEFINED(current_j) || high in array) {
583 array[low] = current_j; 583 array[low] = current_j;
584 delete array[high]; 584 delete array[high];
585 } 585 }
586 } 586 }
587 } 587 }
588 } 588 }
589 589
590 590 function PackedArrayReverse(array, len) {
591 function InnerArrayReverse(array, len) {
592 var j = len - 1; 591 var j = len - 1;
593 for (var i = 0; i < j; i++, j--) { 592 for (var i = 0; i < j; i++, j--) {
594 var current_i = array[i]; 593 var current_i = array[i];
595 if (!IS_UNDEFINED(current_i) || i in array) { 594 var current_j = array[j];
596 var current_j = array[j]; 595 array[i] = current_j;
597 if (!IS_UNDEFINED(current_j) || j in array) { 596 array[j] = current_i;
597 }
598 return array;
599 }
600
601
602 function GenericArrayReverse(array, len) {
603 var j = len - 1;
604 for (var i = 0; i < j; i++, j--) {
605 if (i in array) {
606 var current_i = array[i];
607 if (j in array) {
608 var current_j = array[j];
598 array[i] = current_j; 609 array[i] = current_j;
599 array[j] = current_i; 610 array[j] = current_i;
600 } else { 611 } else {
601 array[j] = current_i; 612 array[j] = current_i;
602 delete array[i]; 613 delete array[i];
603 } 614 }
604 } else { 615 } else {
605 var current_j = array[j]; 616 if (j in array) {
606 if (!IS_UNDEFINED(current_j) || j in array) { 617 var current_j = array[j];
607 array[i] = current_j; 618 array[i] = current_j;
608 delete array[j]; 619 delete array[j];
609 } 620 }
610 } 621 }
611 } 622 }
612 return array; 623 return array;
613 } 624 }
614 625
615 626
616 function ArrayReverse() { 627 function ArrayReverse() {
617 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reverse"); 628 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reverse");
618 629
619 var array = TO_OBJECT_INLINE(this); 630 var array = TO_OBJECT_INLINE(this);
620 var len = TO_UINT32(array.length); 631 var len = TO_UINT32(array.length);
632 var isArray = IS_ARRAY(array);
621 633
622 if (UseSparseVariant(array, len, IS_ARRAY(array), len)) { 634 if (UseSparseVariant(array, len, isArray, len)) {
623 %NormalizeElements(array); 635 %NormalizeElements(array);
624 SparseReverse(array, len); 636 SparseReverse(array, len);
625 return array; 637 return array;
638 } else if (isArray && %_HasFastPackedElements(array)) {
639 return PackedArrayReverse(array, len);
640 } else {
641 return GenericArrayReverse(array, len);
626 } 642 }
627
628 return InnerArrayReverse(array, len);
629 } 643 }
630 644
631 645
632 function ObservedArrayShift(len) { 646 function ObservedArrayShift(len) {
633 var first = this[0]; 647 var first = this[0];
634 648
635 try { 649 try {
636 $observeBeginPerformSplice(this); 650 $observeBeginPerformSplice(this);
637 SimpleMove(this, 0, 1, len, 0); 651 SimpleMove(this, 0, 1, len, 0);
638 this.length = len - 1; 652 this.length = len - 1;
(...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after
1681 to.ArrayToString = ArrayToString; 1695 to.ArrayToString = ArrayToString;
1682 to.InnerArrayEvery = InnerArrayEvery; 1696 to.InnerArrayEvery = InnerArrayEvery;
1683 to.InnerArrayFilter = InnerArrayFilter; 1697 to.InnerArrayFilter = InnerArrayFilter;
1684 to.InnerArrayForEach = InnerArrayForEach; 1698 to.InnerArrayForEach = InnerArrayForEach;
1685 to.InnerArrayIndexOf = InnerArrayIndexOf; 1699 to.InnerArrayIndexOf = InnerArrayIndexOf;
1686 to.InnerArrayJoin = InnerArrayJoin; 1700 to.InnerArrayJoin = InnerArrayJoin;
1687 to.InnerArrayLastIndexOf = InnerArrayLastIndexOf; 1701 to.InnerArrayLastIndexOf = InnerArrayLastIndexOf;
1688 to.InnerArrayMap = InnerArrayMap; 1702 to.InnerArrayMap = InnerArrayMap;
1689 to.InnerArrayReduce = InnerArrayReduce; 1703 to.InnerArrayReduce = InnerArrayReduce;
1690 to.InnerArrayReduceRight = InnerArrayReduceRight; 1704 to.InnerArrayReduceRight = InnerArrayReduceRight;
1691 to.InnerArrayReverse = InnerArrayReverse;
1692 to.InnerArraySome = InnerArraySome; 1705 to.InnerArraySome = InnerArraySome;
1693 to.InnerArraySort = InnerArraySort; 1706 to.InnerArraySort = InnerArraySort;
1694 to.InnerArrayToLocaleString = InnerArrayToLocaleString; 1707 to.InnerArrayToLocaleString = InnerArrayToLocaleString;
1708 to.PackedArrayReverse = PackedArrayReverse;
1695 }); 1709 });
1696 1710
1697 $arrayConcat = ArrayConcatJS; 1711 $arrayConcat = ArrayConcatJS;
1698 $arrayPush = ArrayPush; 1712 $arrayPush = ArrayPush;
1699 $arrayPop = ArrayPop; 1713 $arrayPop = ArrayPop;
1700 $arrayShift = ArrayShift; 1714 $arrayShift = ArrayShift;
1701 $arraySlice = ArraySlice; 1715 $arraySlice = ArraySlice;
1702 $arraySplice = ArraySplice; 1716 $arraySplice = ArraySplice;
1703 $arrayUnshift = ArrayUnshift; 1717 $arrayUnshift = ArrayUnshift;
1704 1718
1705 }); 1719 });
OLDNEW
« no previous file with comments | « no previous file | src/harmony-typedarray.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698