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) { | 5 (function(global, utils) { |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
383 return Join(this, this.length, ',', ConvertToString); | 383 return Join(this, this.length, ',', ConvertToString); |
384 } | 384 } |
385 array = this; | 385 array = this; |
386 } else { | 386 } else { |
387 array = TO_OBJECT(this); | 387 array = TO_OBJECT(this); |
388 func = array.join; | 388 func = array.join; |
389 } | 389 } |
390 if (!IS_CALLABLE(func)) { | 390 if (!IS_CALLABLE(func)) { |
391 return %_CallFunction(array, ObjectToString); | 391 return %_CallFunction(array, ObjectToString); |
392 } | 392 } |
393 return %_CallFunction(array, func); | 393 return %_Call(func, array); |
394 } | 394 } |
395 | 395 |
396 | 396 |
397 function InnerArrayToLocaleString(array, length) { | 397 function InnerArrayToLocaleString(array, length) { |
398 var len = TO_UINT32(length); | 398 var len = TO_UINT32(length); |
399 if (len === 0) return ""; | 399 if (len === 0) return ""; |
400 return Join(array, len, ',', ConvertToLocaleString); | 400 return Join(array, len, ',', ConvertToLocaleString); |
401 } | 401 } |
402 | 402 |
403 | 403 |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
896 y = ToString(y); | 896 y = ToString(y); |
897 if (x == y) return 0; | 897 if (x == y) return 0; |
898 else return x < y ? -1 : 1; | 898 else return x < y ? -1 : 1; |
899 }; | 899 }; |
900 } | 900 } |
901 var InsertionSort = function InsertionSort(a, from, to) { | 901 var InsertionSort = function InsertionSort(a, from, to) { |
902 for (var i = from + 1; i < to; i++) { | 902 for (var i = from + 1; i < to; i++) { |
903 var element = a[i]; | 903 var element = a[i]; |
904 for (var j = i - 1; j >= from; j--) { | 904 for (var j = i - 1; j >= from; j--) { |
905 var tmp = a[j]; | 905 var tmp = a[j]; |
906 var order = %_CallFunction(UNDEFINED, tmp, element, comparefn); | 906 var order = comparefn(tmp, element); |
907 if (order > 0) { | 907 if (order > 0) { |
908 a[j + 1] = tmp; | 908 a[j + 1] = tmp; |
909 } else { | 909 } else { |
910 break; | 910 break; |
911 } | 911 } |
912 } | 912 } |
913 a[j + 1] = element; | 913 a[j + 1] = element; |
914 } | 914 } |
915 }; | 915 }; |
916 | 916 |
917 var GetThirdIndex = function(a, from, to) { | 917 var GetThirdIndex = function(a, from, to) { |
918 var t_array = []; | 918 var t_array = []; |
919 // Use both 'from' and 'to' to determine the pivot candidates. | 919 // Use both 'from' and 'to' to determine the pivot candidates. |
920 var increment = 200 + ((to - from) & 15); | 920 var increment = 200 + ((to - from) & 15); |
921 for (var i = from + 1, j = 0; i < to - 1; i += increment, j++) { | 921 for (var i = from + 1, j = 0; i < to - 1; i += increment, j++) { |
922 t_array[j] = [i, a[i]]; | 922 t_array[j] = [i, a[i]]; |
923 } | 923 } |
924 %_CallFunction(t_array, function(a, b) { | 924 %_CallFunction(t_array, function(a, b) { |
925 return %_CallFunction(UNDEFINED, a[1], b[1], comparefn); | 925 return comparefn(a[1], b[1]); |
Camillo Bruni
2015/09/08 12:32:58
We can rid of this %_CallFunction by using an Inte
Benedikt Meurer
2015/09/08 13:08:58
Doable, but in a separate CL.
| |
926 }, ArraySort); | 926 }, ArraySort); |
927 var third_index = t_array[t_array.length >> 1][0]; | 927 var third_index = t_array[t_array.length >> 1][0]; |
928 return third_index; | 928 return third_index; |
929 } | 929 } |
930 | 930 |
931 var QuickSort = function QuickSort(a, from, to) { | 931 var QuickSort = function QuickSort(a, from, to) { |
932 var third_index = 0; | 932 var third_index = 0; |
933 while (true) { | 933 while (true) { |
934 // Insertion sort is faster for short arrays. | 934 // Insertion sort is faster for short arrays. |
935 if (to - from <= 10) { | 935 if (to - from <= 10) { |
936 InsertionSort(a, from, to); | 936 InsertionSort(a, from, to); |
937 return; | 937 return; |
938 } | 938 } |
939 if (to - from > 1000) { | 939 if (to - from > 1000) { |
940 third_index = GetThirdIndex(a, from, to); | 940 third_index = GetThirdIndex(a, from, to); |
941 } else { | 941 } else { |
942 third_index = from + ((to - from) >> 1); | 942 third_index = from + ((to - from) >> 1); |
943 } | 943 } |
944 // Find a pivot as the median of first, last and middle element. | 944 // Find a pivot as the median of first, last and middle element. |
945 var v0 = a[from]; | 945 var v0 = a[from]; |
946 var v1 = a[to - 1]; | 946 var v1 = a[to - 1]; |
947 var v2 = a[third_index]; | 947 var v2 = a[third_index]; |
948 var c01 = %_CallFunction(UNDEFINED, v0, v1, comparefn); | 948 var c01 = comparefn(v0, v1); |
949 if (c01 > 0) { | 949 if (c01 > 0) { |
950 // v1 < v0, so swap them. | 950 // v1 < v0, so swap them. |
951 var tmp = v0; | 951 var tmp = v0; |
952 v0 = v1; | 952 v0 = v1; |
953 v1 = tmp; | 953 v1 = tmp; |
954 } // v0 <= v1. | 954 } // v0 <= v1. |
955 var c02 = %_CallFunction(UNDEFINED, v0, v2, comparefn); | 955 var c02 = comparefn(v0, v2); |
956 if (c02 >= 0) { | 956 if (c02 >= 0) { |
957 // v2 <= v0 <= v1. | 957 // v2 <= v0 <= v1. |
958 var tmp = v0; | 958 var tmp = v0; |
959 v0 = v2; | 959 v0 = v2; |
960 v2 = v1; | 960 v2 = v1; |
961 v1 = tmp; | 961 v1 = tmp; |
962 } else { | 962 } else { |
963 // v0 <= v1 && v0 < v2 | 963 // v0 <= v1 && v0 < v2 |
964 var c12 = %_CallFunction(UNDEFINED, v1, v2, comparefn); | 964 var c12 = comparefn(v1, v2); |
965 if (c12 > 0) { | 965 if (c12 > 0) { |
966 // v0 <= v2 < v1 | 966 // v0 <= v2 < v1 |
967 var tmp = v1; | 967 var tmp = v1; |
968 v1 = v2; | 968 v1 = v2; |
969 v2 = tmp; | 969 v2 = tmp; |
970 } | 970 } |
971 } | 971 } |
972 // v0 <= v1 <= v2 | 972 // v0 <= v1 <= v2 |
973 a[from] = v0; | 973 a[from] = v0; |
974 a[to - 1] = v2; | 974 a[to - 1] = v2; |
975 var pivot = v1; | 975 var pivot = v1; |
976 var low_end = from + 1; // Upper bound of elements lower than pivot. | 976 var low_end = from + 1; // Upper bound of elements lower than pivot. |
977 var high_start = to - 1; // Lower bound of elements greater than pivot. | 977 var high_start = to - 1; // Lower bound of elements greater than pivot. |
978 a[third_index] = a[low_end]; | 978 a[third_index] = a[low_end]; |
979 a[low_end] = pivot; | 979 a[low_end] = pivot; |
980 | 980 |
981 // From low_end to i are elements equal to pivot. | 981 // From low_end to i are elements equal to pivot. |
982 // From i to high_start are elements that haven't been compared yet. | 982 // From i to high_start are elements that haven't been compared yet. |
983 partition: for (var i = low_end + 1; i < high_start; i++) { | 983 partition: for (var i = low_end + 1; i < high_start; i++) { |
984 var element = a[i]; | 984 var element = a[i]; |
985 var order = %_CallFunction(UNDEFINED, element, pivot, comparefn); | 985 var order = comparefn(element, pivot); |
986 if (order < 0) { | 986 if (order < 0) { |
987 a[i] = a[low_end]; | 987 a[i] = a[low_end]; |
988 a[low_end] = element; | 988 a[low_end] = element; |
989 low_end++; | 989 low_end++; |
990 } else if (order > 0) { | 990 } else if (order > 0) { |
991 do { | 991 do { |
992 high_start--; | 992 high_start--; |
993 if (high_start == i) break partition; | 993 if (high_start == i) break partition; |
994 var top_elem = a[high_start]; | 994 var top_elem = a[high_start]; |
995 order = %_CallFunction(UNDEFINED, top_elem, pivot, comparefn); | 995 order = comparefn(top_elem, pivot); |
996 } while (order > 0); | 996 } while (order > 0); |
997 a[i] = a[high_start]; | 997 a[i] = a[high_start]; |
998 a[high_start] = element; | 998 a[high_start] = element; |
999 if (order < 0) { | 999 if (order < 0) { |
1000 element = a[i]; | 1000 element = a[i]; |
1001 a[i] = a[low_end]; | 1001 a[i] = a[low_end]; |
1002 a[low_end] = element; | 1002 a[low_end] = element; |
1003 low_end++; | 1003 low_end++; |
1004 } | 1004 } |
1005 } | 1005 } |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1172 var length = TO_UINT32(array.length); | 1172 var length = TO_UINT32(array.length); |
1173 return InnerArraySort(array, length, comparefn); | 1173 return InnerArraySort(array, length, comparefn); |
1174 } | 1174 } |
1175 | 1175 |
1176 | 1176 |
1177 // The following functions cannot be made efficient on sparse arrays while | 1177 // The following functions cannot be made efficient on sparse arrays while |
1178 // preserving the semantics, since the calls to the receiver function can add | 1178 // preserving the semantics, since the calls to the receiver function can add |
1179 // or delete elements from the array. | 1179 // or delete elements from the array. |
1180 function InnerArrayFilter(f, receiver, array, length) { | 1180 function InnerArrayFilter(f, receiver, array, length) { |
1181 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); | 1181 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); |
1182 var needs_wrapper = false; | |
1183 if (IS_NULL(receiver)) { | |
1184 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; | |
1185 } else if (!IS_UNDEFINED(receiver)) { | |
1186 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | |
1187 } | |
1188 | 1182 |
1189 var accumulator = new InternalArray(); | 1183 var accumulator = new InternalArray(); |
1190 var accumulator_length = 0; | 1184 var accumulator_length = 0; |
1191 var is_array = IS_ARRAY(array); | 1185 var is_array = IS_ARRAY(array); |
1192 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1186 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
1193 for (var i = 0; i < length; i++) { | 1187 for (var i = 0; i < length; i++) { |
1194 if (HAS_INDEX(array, i, is_array)) { | 1188 if (HAS_INDEX(array, i, is_array)) { |
1195 var element = array[i]; | 1189 var element = array[i]; |
1196 // Prepare break slots for debugger step in. | 1190 // Prepare break slots for debugger step in. |
1197 if (stepping) %DebugPrepareStepInIfStepping(f); | 1191 if (stepping) %DebugPrepareStepInIfStepping(f); |
1198 var new_receiver = needs_wrapper ? TO_OBJECT(receiver) : receiver; | 1192 if (%_Call(f, receiver, element, i, array)) { |
1199 if (%_CallFunction(new_receiver, element, i, array, f)) { | |
1200 accumulator[accumulator_length++] = element; | 1193 accumulator[accumulator_length++] = element; |
1201 } | 1194 } |
1202 } | 1195 } |
1203 } | 1196 } |
1204 return accumulator; | 1197 return accumulator; |
1205 } | 1198 } |
1206 | 1199 |
1207 function ArrayFilter(f, receiver) { | 1200 function ArrayFilter(f, receiver) { |
1208 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.filter"); | 1201 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.filter"); |
1209 | 1202 |
1210 // Pull out the length so that modifications to the length in the | 1203 // Pull out the length so that modifications to the length in the |
1211 // loop will not affect the looping and side effects are visible. | 1204 // loop will not affect the looping and side effects are visible. |
1212 var array = TO_OBJECT(this); | 1205 var array = TO_OBJECT(this); |
1213 var length = TO_UINT32(array.length); | 1206 var length = TO_UINT32(array.length); |
1214 var accumulator = InnerArrayFilter(f, receiver, array, length); | 1207 var accumulator = InnerArrayFilter(f, receiver, array, length); |
1215 var result = new GlobalArray(); | 1208 var result = new GlobalArray(); |
1216 %MoveArrayContents(accumulator, result); | 1209 %MoveArrayContents(accumulator, result); |
1217 return result; | 1210 return result; |
1218 } | 1211 } |
1219 | 1212 |
1220 function InnerArrayForEach(f, receiver, array, length) { | 1213 function InnerArrayForEach(f, receiver, array, length) { |
1221 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); | 1214 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); |
1222 var needs_wrapper = false; | |
1223 if (IS_NULL(receiver)) { | |
1224 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; | |
1225 } else if (!IS_UNDEFINED(receiver)) { | |
1226 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | |
1227 } | |
1228 | 1215 |
1229 var is_array = IS_ARRAY(array); | 1216 var is_array = IS_ARRAY(array); |
1230 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1217 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
1231 for (var i = 0; i < length; i++) { | 1218 for (var i = 0; i < length; i++) { |
1232 if (HAS_INDEX(array, i, is_array)) { | 1219 if (HAS_INDEX(array, i, is_array)) { |
1233 var element = array[i]; | 1220 var element = array[i]; |
1234 // Prepare break slots for debugger step in. | 1221 // Prepare break slots for debugger step in. |
1235 if (stepping) %DebugPrepareStepInIfStepping(f); | 1222 if (stepping) %DebugPrepareStepInIfStepping(f); |
1236 var new_receiver = needs_wrapper ? TO_OBJECT(receiver) : receiver; | 1223 %_Call(f, receiver, element, i, array); |
1237 %_CallFunction(new_receiver, element, i, array, f); | |
1238 } | 1224 } |
1239 } | 1225 } |
1240 } | 1226 } |
1241 | 1227 |
1242 function ArrayForEach(f, receiver) { | 1228 function ArrayForEach(f, receiver) { |
1243 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.forEach"); | 1229 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.forEach"); |
1244 | 1230 |
1245 // Pull out the length so that modifications to the length in the | 1231 // Pull out the length so that modifications to the length in the |
1246 // loop will not affect the looping and side effects are visible. | 1232 // loop will not affect the looping and side effects are visible. |
1247 var array = TO_OBJECT(this); | 1233 var array = TO_OBJECT(this); |
1248 var length = TO_UINT32(array.length); | 1234 var length = TO_UINT32(array.length); |
1249 InnerArrayForEach(f, receiver, array, length); | 1235 InnerArrayForEach(f, receiver, array, length); |
1250 } | 1236 } |
1251 | 1237 |
1252 | 1238 |
1253 function InnerArraySome(f, receiver, array, length) { | 1239 function InnerArraySome(f, receiver, array, length) { |
1254 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); | 1240 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); |
1255 var needs_wrapper = false; | |
1256 if (IS_NULL(receiver)) { | |
1257 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; | |
1258 } else if (!IS_UNDEFINED(receiver)) { | |
1259 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | |
1260 } | |
1261 | 1241 |
1262 var is_array = IS_ARRAY(array); | 1242 var is_array = IS_ARRAY(array); |
1263 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1243 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
1264 for (var i = 0; i < length; i++) { | 1244 for (var i = 0; i < length; i++) { |
1265 if (HAS_INDEX(array, i, is_array)) { | 1245 if (HAS_INDEX(array, i, is_array)) { |
1266 var element = array[i]; | 1246 var element = array[i]; |
1267 // Prepare break slots for debugger step in. | 1247 // Prepare break slots for debugger step in. |
1268 if (stepping) %DebugPrepareStepInIfStepping(f); | 1248 if (stepping) %DebugPrepareStepInIfStepping(f); |
1269 var new_receiver = needs_wrapper ? TO_OBJECT(receiver) : receiver; | 1249 if (%_Call(f, receiver, element, i, array)) return true; |
1270 if (%_CallFunction(new_receiver, element, i, array, f)) return true; | |
1271 } | 1250 } |
1272 } | 1251 } |
1273 return false; | 1252 return false; |
1274 } | 1253 } |
1275 | 1254 |
1276 | 1255 |
1277 // Executes the function once for each element present in the | 1256 // Executes the function once for each element present in the |
1278 // array until it finds one where callback returns true. | 1257 // array until it finds one where callback returns true. |
1279 function ArraySome(f, receiver) { | 1258 function ArraySome(f, receiver) { |
1280 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.some"); | 1259 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.some"); |
1281 | 1260 |
1282 // Pull out the length so that modifications to the length in the | 1261 // Pull out the length so that modifications to the length in the |
1283 // loop will not affect the looping and side effects are visible. | 1262 // loop will not affect the looping and side effects are visible. |
1284 var array = TO_OBJECT(this); | 1263 var array = TO_OBJECT(this); |
1285 var length = TO_UINT32(array.length); | 1264 var length = TO_UINT32(array.length); |
1286 return InnerArraySome(f, receiver, array, length); | 1265 return InnerArraySome(f, receiver, array, length); |
1287 } | 1266 } |
1288 | 1267 |
1289 | 1268 |
1290 function InnerArrayEvery(f, receiver, array, length) { | 1269 function InnerArrayEvery(f, receiver, array, length) { |
1291 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); | 1270 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); |
1292 var needs_wrapper = false; | |
1293 if (IS_NULL(receiver)) { | |
1294 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; | |
1295 } else if (!IS_UNDEFINED(receiver)) { | |
1296 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | |
1297 } | |
1298 | 1271 |
1299 var is_array = IS_ARRAY(array); | 1272 var is_array = IS_ARRAY(array); |
1300 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1273 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
1301 for (var i = 0; i < length; i++) { | 1274 for (var i = 0; i < length; i++) { |
1302 if (HAS_INDEX(array, i, is_array)) { | 1275 if (HAS_INDEX(array, i, is_array)) { |
1303 var element = array[i]; | 1276 var element = array[i]; |
1304 // Prepare break slots for debugger step in. | 1277 // Prepare break slots for debugger step in. |
1305 if (stepping) %DebugPrepareStepInIfStepping(f); | 1278 if (stepping) %DebugPrepareStepInIfStepping(f); |
1306 var new_receiver = needs_wrapper ? TO_OBJECT(receiver) : receiver; | 1279 if (!%_Call(f, receiver, element, i, array)) return false; |
1307 if (!%_CallFunction(new_receiver, element, i, array, f)) return false; | |
1308 } | 1280 } |
1309 } | 1281 } |
1310 return true; | 1282 return true; |
1311 } | 1283 } |
1312 | 1284 |
1313 function ArrayEvery(f, receiver) { | 1285 function ArrayEvery(f, receiver) { |
1314 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.every"); | 1286 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.every"); |
1315 | 1287 |
1316 // Pull out the length so that modifications to the length in the | 1288 // Pull out the length so that modifications to the length in the |
1317 // loop will not affect the looping and side effects are visible. | 1289 // loop will not affect the looping and side effects are visible. |
1318 var array = TO_OBJECT(this); | 1290 var array = TO_OBJECT(this); |
1319 var length = TO_UINT32(array.length); | 1291 var length = TO_UINT32(array.length); |
1320 return InnerArrayEvery(f, receiver, array, length); | 1292 return InnerArrayEvery(f, receiver, array, length); |
1321 } | 1293 } |
1322 | 1294 |
1323 | 1295 |
1324 function InnerArrayMap(f, receiver, array, length) { | 1296 function InnerArrayMap(f, receiver, array, length) { |
1325 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); | 1297 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); |
1326 var needs_wrapper = false; | |
1327 if (IS_NULL(receiver)) { | |
1328 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; | |
1329 } else if (!IS_UNDEFINED(receiver)) { | |
1330 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | |
1331 } | |
1332 | 1298 |
1333 var accumulator = new InternalArray(length); | 1299 var accumulator = new InternalArray(length); |
1334 var is_array = IS_ARRAY(array); | 1300 var is_array = IS_ARRAY(array); |
1335 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1301 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
1336 for (var i = 0; i < length; i++) { | 1302 for (var i = 0; i < length; i++) { |
1337 if (HAS_INDEX(array, i, is_array)) { | 1303 if (HAS_INDEX(array, i, is_array)) { |
1338 var element = array[i]; | 1304 var element = array[i]; |
1339 // Prepare break slots for debugger step in. | 1305 // Prepare break slots for debugger step in. |
1340 if (stepping) %DebugPrepareStepInIfStepping(f); | 1306 if (stepping) %DebugPrepareStepInIfStepping(f); |
1341 var new_receiver = needs_wrapper ? TO_OBJECT(receiver) : receiver; | 1307 accumulator[i] = %_Call(f, receiver, element, i, array); |
1342 accumulator[i] = %_CallFunction(new_receiver, element, i, array, f); | |
1343 } | 1308 } |
1344 } | 1309 } |
1345 return accumulator; | 1310 return accumulator; |
1346 } | 1311 } |
1347 | 1312 |
1348 | 1313 |
1349 function ArrayMap(f, receiver) { | 1314 function ArrayMap(f, receiver) { |
1350 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.map"); | 1315 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.map"); |
1351 | 1316 |
1352 // Pull out the length so that modifications to the length in the | 1317 // Pull out the length so that modifications to the length in the |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1501 } | 1466 } |
1502 throw MakeTypeError(kReduceNoInitial); | 1467 throw MakeTypeError(kReduceNoInitial); |
1503 } | 1468 } |
1504 | 1469 |
1505 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(callback); | 1470 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(callback); |
1506 for (; i < length; i++) { | 1471 for (; i < length; i++) { |
1507 if (HAS_INDEX(array, i, is_array)) { | 1472 if (HAS_INDEX(array, i, is_array)) { |
1508 var element = array[i]; | 1473 var element = array[i]; |
1509 // Prepare break slots for debugger step in. | 1474 // Prepare break slots for debugger step in. |
1510 if (stepping) %DebugPrepareStepInIfStepping(callback); | 1475 if (stepping) %DebugPrepareStepInIfStepping(callback); |
1511 current = %_CallFunction(UNDEFINED, current, element, i, array, callback); | 1476 current = callback(current, element, i, array); |
1512 } | 1477 } |
1513 } | 1478 } |
1514 return current; | 1479 return current; |
1515 } | 1480 } |
1516 | 1481 |
1517 | 1482 |
1518 function ArrayReduce(callback, current) { | 1483 function ArrayReduce(callback, current) { |
1519 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduce"); | 1484 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduce"); |
1520 | 1485 |
1521 // Pull out the length so that modifications to the length in the | 1486 // Pull out the length so that modifications to the length in the |
(...skipping 22 matching lines...) Expand all Loading... | |
1544 } | 1509 } |
1545 throw MakeTypeError(kReduceNoInitial); | 1510 throw MakeTypeError(kReduceNoInitial); |
1546 } | 1511 } |
1547 | 1512 |
1548 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(callback); | 1513 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(callback); |
1549 for (; i >= 0; i--) { | 1514 for (; i >= 0; i--) { |
1550 if (HAS_INDEX(array, i, is_array)) { | 1515 if (HAS_INDEX(array, i, is_array)) { |
1551 var element = array[i]; | 1516 var element = array[i]; |
1552 // Prepare break slots for debugger step in. | 1517 // Prepare break slots for debugger step in. |
1553 if (stepping) %DebugPrepareStepInIfStepping(callback); | 1518 if (stepping) %DebugPrepareStepInIfStepping(callback); |
1554 current = %_CallFunction(UNDEFINED, current, element, i, array, callback); | 1519 current = callback(current, element, i, array); |
1555 } | 1520 } |
1556 } | 1521 } |
1557 return current; | 1522 return current; |
1558 } | 1523 } |
1559 | 1524 |
1560 | 1525 |
1561 function ArrayReduceRight(callback, current) { | 1526 function ArrayReduceRight(callback, current) { |
1562 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduceRight"); | 1527 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduceRight"); |
1563 | 1528 |
1564 // Pull out the length so that side effects are visible before the | 1529 // Pull out the length so that side effects are visible before the |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1689 %InstallToContext([ | 1654 %InstallToContext([ |
1690 "array_pop", ArrayPop, | 1655 "array_pop", ArrayPop, |
1691 "array_push", ArrayPush, | 1656 "array_push", ArrayPush, |
1692 "array_shift", ArrayShift, | 1657 "array_shift", ArrayShift, |
1693 "array_splice", ArraySplice, | 1658 "array_splice", ArraySplice, |
1694 "array_slice", ArraySlice, | 1659 "array_slice", ArraySlice, |
1695 "array_unshift", ArrayUnshift, | 1660 "array_unshift", ArrayUnshift, |
1696 ]); | 1661 ]); |
1697 | 1662 |
1698 }); | 1663 }); |
OLD | NEW |