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 (function(global, utils, extrasUtils) { | 5 (function(global, utils, extrasUtils) { |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
(...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1026 | 1026 |
1027 // Pull out the length so that modifications to the length in the | 1027 // Pull out the length so that modifications to the length in the |
1028 // loop will not affect the looping and side effects are visible. | 1028 // loop will not affect the looping and side effects are visible. |
1029 var array = TO_OBJECT(this); | 1029 var array = TO_OBJECT(this); |
1030 var length = TO_LENGTH(array.length); | 1030 var length = TO_LENGTH(array.length); |
1031 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); | 1031 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); |
1032 var result = ArraySpeciesCreate(array, 0); | 1032 var result = ArraySpeciesCreate(array, 0); |
1033 return InnerArrayFilter(f, receiver, array, length, result); | 1033 return InnerArrayFilter(f, receiver, array, length, result); |
1034 } | 1034 } |
1035 | 1035 |
1036 | 1036 function ArrayForEach(f, receiver) { |
1037 function InnerArrayForEach(f, receiver, array, length) { | 1037 // This function is implemented as a code stub builtin. |
1038 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); | 1038 // Defining the signature here makes it easier to install the builtin |
Yang
2017/03/20 15:00:24
Do we really need these here? We don't need this f
mvstanton
2017/03/21 21:15:47
Done.
| |
1039 | 1039 // in bootstrapper.cc. |
1040 if (IS_UNDEFINED(receiver)) { | |
1041 for (var i = 0; i < length; i++) { | |
1042 if (i in array) { | |
1043 var element = array[i]; | |
1044 f(element, i, array); | |
1045 } | |
1046 } | |
1047 } else { | |
1048 for (var i = 0; i < length; i++) { | |
1049 if (i in array) { | |
1050 var element = array[i]; | |
1051 %_Call(f, receiver, element, i, array); | |
1052 } | |
1053 } | |
1054 } | |
1055 } | 1040 } |
1056 | 1041 |
1057 | |
1058 function ArrayForEach(f, receiver) { | |
1059 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.forEach"); | |
1060 | |
1061 // Pull out the length so that modifications to the length in the | |
1062 // loop will not affect the looping and side effects are visible. | |
1063 var array = TO_OBJECT(this); | |
1064 var length = TO_LENGTH(array.length); | |
1065 InnerArrayForEach(f, receiver, array, length); | |
1066 } | |
1067 | |
1068 | |
1069 function InnerArraySome(f, receiver, array, length) { | |
1070 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); | |
1071 | |
1072 for (var i = 0; i < length; i++) { | |
1073 if (i in array) { | |
1074 var element = array[i]; | |
1075 if (%_Call(f, receiver, element, i, array)) return true; | |
1076 } | |
1077 } | |
1078 return false; | |
1079 } | |
1080 | |
1081 | |
1082 // Executes the function once for each element present in the | 1042 // Executes the function once for each element present in the |
1083 // array until it finds one where callback returns true. | 1043 // array until it finds one where callback returns true. |
1084 function ArraySome(f, receiver) { | 1044 function ArraySome(f, receiver) { |
1085 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.some"); | 1045 // This function is implemented as a code stub builtin. |
1046 // Defining the signature here makes it easier to install the builtin | |
1047 // in bootstrapper.cc. | |
1048 } | |
1086 | 1049 |
1087 // Pull out the length so that modifications to the length in the | 1050 function ArrayEvery(f, receiver) { |
1088 // loop will not affect the looping and side effects are visible. | 1051 // This function is implemented as a code stub builtin. |
1089 var array = TO_OBJECT(this); | 1052 // Defining the signature here makes it easier to install the builtin |
1090 var length = TO_LENGTH(array.length); | 1053 // in bootstrapper.cc. |
1091 return InnerArraySome(f, receiver, array, length); | |
1092 } | 1054 } |
1093 | 1055 |
1094 | 1056 |
1095 function InnerArrayEvery(f, receiver, array, length) { | |
1096 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); | |
1097 | |
1098 for (var i = 0; i < length; i++) { | |
1099 if (i in array) { | |
1100 var element = array[i]; | |
1101 if (!%_Call(f, receiver, element, i, array)) return false; | |
1102 } | |
1103 } | |
1104 return true; | |
1105 } | |
1106 | |
1107 function ArrayEvery(f, receiver) { | |
1108 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.every"); | |
1109 | |
1110 // Pull out the length so that modifications to the length in the | |
1111 // loop will not affect the looping and side effects are visible. | |
1112 var array = TO_OBJECT(this); | |
1113 var length = TO_LENGTH(array.length); | |
1114 return InnerArrayEvery(f, receiver, array, length); | |
1115 } | |
1116 | |
1117 | |
1118 function ArrayMap(f, receiver) { | 1057 function ArrayMap(f, receiver) { |
1119 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.map"); | 1058 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.map"); |
1120 | 1059 |
1121 // Pull out the length so that modifications to the length in the | 1060 // Pull out the length so that modifications to the length in the |
1122 // loop will not affect the looping and side effects are visible. | 1061 // loop will not affect the looping and side effects are visible. |
1123 var array = TO_OBJECT(this); | 1062 var array = TO_OBJECT(this); |
1124 var length = TO_LENGTH(array.length); | 1063 var length = TO_LENGTH(array.length); |
1125 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); | 1064 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); |
1126 var result = ArraySpeciesCreate(array, length); | 1065 var result = ArraySpeciesCreate(array, length); |
1127 for (var i = 0; i < length; i++) { | 1066 for (var i = 0; i < length; i++) { |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1604 | 1543 |
1605 // ------------------------------------------------------------------- | 1544 // ------------------------------------------------------------------- |
1606 // Exports | 1545 // Exports |
1607 | 1546 |
1608 utils.Export(function(to) { | 1547 utils.Export(function(to) { |
1609 to.ArrayFrom = ArrayFrom; | 1548 to.ArrayFrom = ArrayFrom; |
1610 to.ArrayJoin = ArrayJoin; | 1549 to.ArrayJoin = ArrayJoin; |
1611 to.ArrayPush = ArrayPush; | 1550 to.ArrayPush = ArrayPush; |
1612 to.ArrayToString = ArrayToString; | 1551 to.ArrayToString = ArrayToString; |
1613 to.ArrayValues = IteratorFunctions.values, | 1552 to.ArrayValues = IteratorFunctions.values, |
1614 to.InnerArrayEvery = InnerArrayEvery; | 1553 to.InnerArrayFill = InnerArrayFill; |
1615 to.InnerArrayFilter = InnerArrayFilter; | 1554 to.InnerArrayFilter = InnerArrayFilter; |
1616 to.InnerArrayFind = InnerArrayFind; | 1555 to.InnerArrayFind = InnerArrayFind; |
1617 to.InnerArrayFindIndex = InnerArrayFindIndex; | 1556 to.InnerArrayFindIndex = InnerArrayFindIndex; |
1618 to.InnerArrayForEach = InnerArrayForEach; | |
1619 to.InnerArrayJoin = InnerArrayJoin; | 1557 to.InnerArrayJoin = InnerArrayJoin; |
1620 to.InnerArrayReduce = InnerArrayReduce; | 1558 to.InnerArrayReduce = InnerArrayReduce; |
1621 to.InnerArrayReduceRight = InnerArrayReduceRight; | 1559 to.InnerArrayReduceRight = InnerArrayReduceRight; |
1622 to.InnerArraySome = InnerArraySome; | |
1623 to.InnerArraySort = InnerArraySort; | 1560 to.InnerArraySort = InnerArraySort; |
1624 to.InnerArrayToLocaleString = InnerArrayToLocaleString; | 1561 to.InnerArrayToLocaleString = InnerArrayToLocaleString; |
1625 to.PackedArrayReverse = PackedArrayReverse; | 1562 to.PackedArrayReverse = PackedArrayReverse; |
1626 }); | 1563 }); |
1627 | 1564 |
1628 %InstallToContext([ | 1565 %InstallToContext([ |
1629 "array_entries_iterator", IteratorFunctions.entries, | 1566 "array_entries_iterator", IteratorFunctions.entries, |
1630 "array_for_each_iterator", IteratorFunctions.forEach, | 1567 "array_for_each_iterator", IteratorFunctions.forEach, |
1631 "array_keys_iterator", IteratorFunctions.keys, | 1568 "array_keys_iterator", IteratorFunctions.keys, |
1632 "array_pop", ArrayPop, | 1569 "array_pop", ArrayPop, |
1633 "array_push", ArrayPush, | 1570 "array_push", ArrayPush, |
1634 "array_shift", ArrayShift, | 1571 "array_shift", ArrayShift, |
1635 "array_splice", ArraySplice, | 1572 "array_splice", ArraySplice, |
1636 "array_slice", ArraySlice, | 1573 "array_slice", ArraySlice, |
1637 "array_unshift", ArrayUnshift, | 1574 "array_unshift", ArrayUnshift, |
1638 "array_values_iterator", IteratorFunctions.values, | 1575 "array_values_iterator", IteratorFunctions.values, |
1639 ]); | 1576 ]); |
1640 | 1577 |
1641 }); | 1578 }); |
OLD | NEW |