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

Side by Side Diff: src/array.js

Issue 1132723008: Implement %TypedArray%.reverse (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 5 years, 7 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 $arrayJoin; 6 var $arrayJoin;
7 var $arrayPush; 7 var $arrayPush;
8 var $arrayPop; 8 var $arrayPop;
9 var $arrayShift; 9 var $arrayShift;
10 var $arraySlice; 10 var $arraySlice;
11 var $arraySplice; 11 var $arraySplice;
12 var $arrayUnshift; 12 var $arrayUnshift;
13 var $innerArrayForEach; 13 var $innerArrayForEach;
14 var $innerArrayEvery; 14 var $innerArrayEvery;
15 var $innerArrayReverse;
15 16
16 (function(global, shared, exports) { 17 (function(global, shared, exports) {
17 18
18 "use strict"; 19 "use strict";
19 20
20 %CheckIsBootstrapping(); 21 %CheckIsBootstrapping();
21 22
22 // ------------------------------------------------------------------- 23 // -------------------------------------------------------------------
23 // Imports 24 // Imports
24 25
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 var current_j = array[high]; 558 var current_j = array[high];
558 if (!IS_UNDEFINED(current_j) || high in array) { 559 if (!IS_UNDEFINED(current_j) || high in array) {
559 array[low] = current_j; 560 array[low] = current_j;
560 delete array[high]; 561 delete array[high];
561 } 562 }
562 } 563 }
563 } 564 }
564 } 565 }
565 566
566 567
567 function ArrayReverse() { 568 function InnerArrayReverse(array, len) {
568 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reverse");
569
570 var array = TO_OBJECT_INLINE(this);
571 var len = TO_UINT32(array.length);
572
573 if (UseSparseVariant(array, len, IS_ARRAY(array), len)) {
574 %NormalizeElements(array);
575 SparseReverse(array, len);
576 return array;
577 }
578
579 var j = len - 1; 569 var j = len - 1;
580 for (var i = 0; i < j; i++, j--) { 570 for (var i = 0; i < j; i++, j--) {
581 var current_i = array[i]; 571 var current_i = array[i];
582 if (!IS_UNDEFINED(current_i) || i in array) { 572 if (!IS_UNDEFINED(current_i) || i in array) {
583 var current_j = array[j]; 573 var current_j = array[j];
584 if (!IS_UNDEFINED(current_j) || j in array) { 574 if (!IS_UNDEFINED(current_j) || j in array) {
585 array[i] = current_j; 575 array[i] = current_j;
586 array[j] = current_i; 576 array[j] = current_i;
587 } else { 577 } else {
588 array[j] = current_i; 578 array[j] = current_i;
589 delete array[i]; 579 delete array[i];
590 } 580 }
591 } else { 581 } else {
592 var current_j = array[j]; 582 var current_j = array[j];
593 if (!IS_UNDEFINED(current_j) || j in array) { 583 if (!IS_UNDEFINED(current_j) || j in array) {
594 array[i] = current_j; 584 array[i] = current_j;
595 delete array[j]; 585 delete array[j];
596 } 586 }
597 } 587 }
598 } 588 }
599 return array; 589 return array;
600 } 590 }
601 591
602 592
593 function ArrayReverse() {
594 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reverse");
595
596 var array = TO_OBJECT_INLINE(this);
597 var len = TO_UINT32(array.length);
598
599 if (UseSparseVariant(array, len, IS_ARRAY(array), len)) {
600 %NormalizeElements(array);
601 SparseReverse(array, len);
602 return array;
603 }
604
605 return InnerArrayReverse(array, len);
606 }
607
608
603 function ObservedArrayShift(len) { 609 function ObservedArrayShift(len) {
604 var first = this[0]; 610 var first = this[0];
605 611
606 try { 612 try {
607 $observeBeginPerformSplice(this); 613 $observeBeginPerformSplice(this);
608 SimpleMove(this, 0, 1, len, 0); 614 SimpleMove(this, 0, 1, len, 0);
609 this.length = len - 1; 615 this.length = len - 1;
610 } finally { 616 } finally {
611 $observeEndPerformSplice(this); 617 $observeEndPerformSplice(this);
612 $observeEnqueueSpliceRecord(this, 0, [first], 0); 618 $observeEnqueueSpliceRecord(this, 0, [first], 0);
(...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after
1602 $arrayJoin = ArrayJoin; 1608 $arrayJoin = ArrayJoin;
1603 $arrayPush = ArrayPush; 1609 $arrayPush = ArrayPush;
1604 $arrayPop = ArrayPop; 1610 $arrayPop = ArrayPop;
1605 $arrayShift = ArrayShift; 1611 $arrayShift = ArrayShift;
1606 $arraySlice = ArraySlice; 1612 $arraySlice = ArraySlice;
1607 $arraySplice = ArraySplice; 1613 $arraySplice = ArraySplice;
1608 $arrayUnshift = ArrayUnshift; 1614 $arrayUnshift = ArrayUnshift;
1609 1615
1610 $innerArrayForEach = InnerArrayForEach; 1616 $innerArrayForEach = InnerArrayForEach;
1611 $innerArrayEvery = InnerArrayEvery; 1617 $innerArrayEvery = InnerArrayEvery;
1618 $innerArrayReverse = InnerArrayReverse;
1612 1619
1613 }); 1620 });
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