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

Side by Side Diff: src/array.js

Issue 1162043008: Revert of Implement %TypedArray%.prototype.{reduce,reduceRight} (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 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 1474 matching lines...) Expand 10 before | Expand all | Expand 10 after
1485 1485
1486 function ArrayLastIndexOf(element, index) { 1486 function ArrayLastIndexOf(element, index) {
1487 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.lastIndexOf"); 1487 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.lastIndexOf");
1488 1488
1489 var length = TO_UINT32(this.length); 1489 var length = TO_UINT32(this.length);
1490 return %_CallFunction(this, element, index, length, 1490 return %_CallFunction(this, element, index, length,
1491 %_ArgumentsLength(), InnerArrayLastIndexOf); 1491 %_ArgumentsLength(), InnerArrayLastIndexOf);
1492 } 1492 }
1493 1493
1494 1494
1495 function InnerArrayReduce(callback, current, array, length, argumentsLength) { 1495 function ArrayReduce(callback, current) {
1496 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduce");
1497
1498 // Pull out the length so that modifications to the length in the
1499 // loop will not affect the looping and side effects are visible.
1500 var array = $toObject(this);
1501 var length = $toUint32(array.length);
1502
1496 if (!IS_SPEC_FUNCTION(callback)) { 1503 if (!IS_SPEC_FUNCTION(callback)) {
1497 throw MakeTypeError(kCalledNonCallable, callback); 1504 throw MakeTypeError(kCalledNonCallable, callback);
1498 } 1505 }
1499 1506
1500 var is_array = IS_ARRAY(array); 1507 var is_array = IS_ARRAY(array);
1501 var i = 0; 1508 var i = 0;
1502 find_initial: if (argumentsLength < 2) { 1509 find_initial: if (%_ArgumentsLength() < 2) {
1503 for (; i < length; i++) { 1510 for (; i < length; i++) {
1504 if (HAS_INDEX(array, i, is_array)) { 1511 if (HAS_INDEX(array, i, is_array)) {
1505 current = array[i++]; 1512 current = array[i++];
1506 break find_initial; 1513 break find_initial;
1507 } 1514 }
1508 } 1515 }
1509 throw MakeTypeError(kReduceNoInitial); 1516 throw MakeTypeError(kReduceNoInitial);
1510 } 1517 }
1511 1518
1512 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(callback); 1519 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(callback);
1513 for (; i < length; i++) { 1520 for (; i < length; i++) {
1514 if (HAS_INDEX(array, i, is_array)) { 1521 if (HAS_INDEX(array, i, is_array)) {
1515 var element = array[i]; 1522 var element = array[i];
1516 // Prepare break slots for debugger step in. 1523 // Prepare break slots for debugger step in.
1517 if (stepping) %DebugPrepareStepInIfStepping(callback); 1524 if (stepping) %DebugPrepareStepInIfStepping(callback);
1518 current = %_CallFunction(UNDEFINED, current, element, i, array, callback); 1525 current = %_CallFunction(UNDEFINED, current, element, i, array, callback);
1519 } 1526 }
1520 } 1527 }
1521 return current; 1528 return current;
1522 } 1529 }
1523 1530
1524 1531
1525 function ArrayReduce(callback, current) { 1532 function ArrayReduceRight(callback, current) {
1526 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduce"); 1533 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduceRight");
1527 1534
1528 // Pull out the length so that modifications to the length in the 1535 // Pull out the length so that side effects are visible before the
1529 // loop will not affect the looping and side effects are visible. 1536 // callback function is checked.
1530 var array = $toObject(this); 1537 var array = $toObject(this);
1531 var length = $toUint32(array.length); 1538 var length = $toUint32(array.length);
1532 return InnerArrayReduce(callback, current, array, length,
1533 %_ArgumentsLength());
1534 }
1535 1539
1536
1537 function InnerArrayReduceRight(callback, current, array, length,
1538 argumentsLength) {
1539 if (!IS_SPEC_FUNCTION(callback)) { 1540 if (!IS_SPEC_FUNCTION(callback)) {
1540 throw MakeTypeError(kCalledNonCallable, callback); 1541 throw MakeTypeError(kCalledNonCallable, callback);
1541 } 1542 }
1542 1543
1543 var is_array = IS_ARRAY(array); 1544 var is_array = IS_ARRAY(array);
1544 var i = length - 1; 1545 var i = length - 1;
1545 find_initial: if (argumentsLength < 2) { 1546 find_initial: if (%_ArgumentsLength() < 2) {
1546 for (; i >= 0; i--) { 1547 for (; i >= 0; i--) {
1547 if (HAS_INDEX(array, i, is_array)) { 1548 if (HAS_INDEX(array, i, is_array)) {
1548 current = array[i--]; 1549 current = array[i--];
1549 break find_initial; 1550 break find_initial;
1550 } 1551 }
1551 } 1552 }
1552 throw MakeTypeError(kReduceNoInitial); 1553 throw MakeTypeError(kReduceNoInitial);
1553 } 1554 }
1554 1555
1555 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(callback); 1556 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(callback);
1556 for (; i >= 0; i--) { 1557 for (; i >= 0; i--) {
1557 if (HAS_INDEX(array, i, is_array)) { 1558 if (HAS_INDEX(array, i, is_array)) {
1558 var element = array[i]; 1559 var element = array[i];
1559 // Prepare break slots for debugger step in. 1560 // Prepare break slots for debugger step in.
1560 if (stepping) %DebugPrepareStepInIfStepping(callback); 1561 if (stepping) %DebugPrepareStepInIfStepping(callback);
1561 current = %_CallFunction(UNDEFINED, current, element, i, array, callback); 1562 current = %_CallFunction(UNDEFINED, current, element, i, array, callback);
1562 } 1563 }
1563 } 1564 }
1564 return current; 1565 return current;
1565 } 1566 }
1566 1567
1567
1568 function ArrayReduceRight(callback, current) {
1569 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduceRight");
1570
1571 // Pull out the length so that side effects are visible before the
1572 // callback function is checked.
1573 var array = $toObject(this);
1574 var length = $toUint32(array.length);
1575 return InnerArrayReduceRight(callback, current, array, length,
1576 %_ArgumentsLength());
1577 }
1578
1579 // ES5, 15.4.3.2 1568 // ES5, 15.4.3.2
1580 function ArrayIsArray(obj) { 1569 function ArrayIsArray(obj) {
1581 return IS_ARRAY(obj); 1570 return IS_ARRAY(obj);
1582 } 1571 }
1583 1572
1584 1573
1585 // ------------------------------------------------------------------- 1574 // -------------------------------------------------------------------
1586 1575
1587 // Set up non-enumerable constructor property on the Array.prototype 1576 // Set up non-enumerable constructor property on the Array.prototype
1588 // object. 1577 // object.
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 utils.Export(function(to) { 1666 utils.Export(function(to) {
1678 to.ArrayJoin = ArrayJoin; 1667 to.ArrayJoin = ArrayJoin;
1679 to.ArrayToString = ArrayToString; 1668 to.ArrayToString = ArrayToString;
1680 to.InnerArrayEvery = InnerArrayEvery; 1669 to.InnerArrayEvery = InnerArrayEvery;
1681 to.InnerArrayFilter = InnerArrayFilter; 1670 to.InnerArrayFilter = InnerArrayFilter;
1682 to.InnerArrayForEach = InnerArrayForEach; 1671 to.InnerArrayForEach = InnerArrayForEach;
1683 to.InnerArrayIndexOf = InnerArrayIndexOf; 1672 to.InnerArrayIndexOf = InnerArrayIndexOf;
1684 to.InnerArrayJoin = InnerArrayJoin; 1673 to.InnerArrayJoin = InnerArrayJoin;
1685 to.InnerArrayLastIndexOf = InnerArrayLastIndexOf; 1674 to.InnerArrayLastIndexOf = InnerArrayLastIndexOf;
1686 to.InnerArrayMap = InnerArrayMap; 1675 to.InnerArrayMap = InnerArrayMap;
1687 to.InnerArrayReduce = InnerArrayReduce;
1688 to.InnerArrayReduceRight = InnerArrayReduceRight;
1689 to.InnerArrayReverse = InnerArrayReverse; 1676 to.InnerArrayReverse = InnerArrayReverse;
1690 to.InnerArraySome = InnerArraySome; 1677 to.InnerArraySome = InnerArraySome;
1691 to.InnerArraySort = InnerArraySort; 1678 to.InnerArraySort = InnerArraySort;
1692 to.InnerArrayToLocaleString = InnerArrayToLocaleString; 1679 to.InnerArrayToLocaleString = InnerArrayToLocaleString;
1693 }); 1680 });
1694 1681
1695 $arrayConcat = ArrayConcatJS; 1682 $arrayConcat = ArrayConcatJS;
1696 $arrayPush = ArrayPush; 1683 $arrayPush = ArrayPush;
1697 $arrayPop = ArrayPop; 1684 $arrayPop = ArrayPop;
1698 $arrayShift = ArrayShift; 1685 $arrayShift = ArrayShift;
1699 $arraySlice = ArraySlice; 1686 $arraySlice = ArraySlice;
1700 $arraySplice = ArraySplice; 1687 $arraySplice = ArraySplice;
1701 $arrayUnshift = ArrayUnshift; 1688 $arrayUnshift = ArrayUnshift;
1702 1689
1703 }); 1690 });
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