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 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; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 // matter what happens. | 189 // matter what happens. |
190 if (is_array) visited_arrays.length = visited_arrays.length - 1; | 190 if (is_array) visited_arrays.length = visited_arrays.length - 1; |
191 } | 191 } |
192 } | 192 } |
193 | 193 |
194 | 194 |
195 function ConvertToString(x) { | 195 function ConvertToString(x) { |
196 // Assumes x is a non-string. | 196 // Assumes x is a non-string. |
197 if (IS_NUMBER(x)) return %_NumberToString(x); | 197 if (IS_NUMBER(x)) return %_NumberToString(x); |
198 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; | 198 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; |
199 return (IS_NULL_OR_UNDEFINED(x)) ? '' : $toString($defaultString(x)); | 199 return (IS_NULL_OR_UNDEFINED(x)) ? '' : %ToString(%DefaultString(x)); |
200 } | 200 } |
201 | 201 |
202 | 202 |
203 function ConvertToLocaleString(e) { | 203 function ConvertToLocaleString(e) { |
204 if (IS_NULL_OR_UNDEFINED(e)) { | 204 if (IS_NULL_OR_UNDEFINED(e)) { |
205 return ''; | 205 return ''; |
206 } else { | 206 } else { |
207 // According to ES5, section 15.4.4.3, the toLocaleString conversion | 207 // According to ES5, section 15.4.4.3, the toLocaleString conversion |
208 // must throw a TypeError if ToObject(e).toLocaleString isn't | 208 // must throw a TypeError if ToObject(e).toLocaleString isn't |
209 // callable. | 209 // callable. |
210 var e_obj = $toObject(e); | 210 var e_obj = ToObject(e); |
211 return $toString(e_obj.toLocaleString()); | 211 return %ToString(e_obj.toLocaleString()); |
212 } | 212 } |
213 } | 213 } |
214 | 214 |
215 | 215 |
216 // This function implements the optimized splice implementation that can use | 216 // This function implements the optimized splice implementation that can use |
217 // special array operations to handle sparse arrays in a sensible fashion. | 217 // special array operations to handle sparse arrays in a sensible fashion. |
218 function SparseSlice(array, start_i, del_count, len, deleted_elements) { | 218 function SparseSlice(array, start_i, del_count, len, deleted_elements) { |
219 // Move deleted elements to a new array (the return value from splice). | 219 // Move deleted elements to a new array (the return value from splice). |
220 var indices = %GetArrayKeys(array, start_i + del_count); | 220 var indices = %GetArrayKeys(array, start_i + del_count); |
221 if (IS_NUMBER(indices)) { | 221 if (IS_NUMBER(indices)) { |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 function ArrayToString() { | 361 function ArrayToString() { |
362 var array; | 362 var array; |
363 var func; | 363 var func; |
364 if (IS_ARRAY(this)) { | 364 if (IS_ARRAY(this)) { |
365 func = this.join; | 365 func = this.join; |
366 if (func === ArrayJoin) { | 366 if (func === ArrayJoin) { |
367 return Join(this, this.length, ',', ConvertToString); | 367 return Join(this, this.length, ',', ConvertToString); |
368 } | 368 } |
369 array = this; | 369 array = this; |
370 } else { | 370 } else { |
371 array = $toObject(this); | 371 array = ToObject(this); |
372 func = array.join; | 372 func = array.join; |
373 } | 373 } |
374 if (!IS_SPEC_FUNCTION(func)) { | 374 if (!IS_SPEC_FUNCTION(func)) { |
375 return %_CallFunction(array, $objectToString); | 375 return %_CallFunction(array, $objectToString); |
376 } | 376 } |
377 return %_CallFunction(array, func); | 377 return %_CallFunction(array, func); |
378 } | 378 } |
379 | 379 |
380 | 380 |
381 function ArrayToLocaleString() { | 381 function ArrayToLocaleString() { |
382 var array = $toObject(this); | 382 var array = ToObject(this); |
383 var arrayLen = array.length; | 383 var arrayLen = array.length; |
384 var len = TO_UINT32(arrayLen); | 384 var len = TO_UINT32(arrayLen); |
385 if (len === 0) return ""; | 385 if (len === 0) return ""; |
386 return Join(array, len, ',', ConvertToLocaleString); | 386 return Join(array, len, ',', ConvertToLocaleString); |
387 } | 387 } |
388 | 388 |
389 | 389 |
390 function ArrayJoin(separator) { | 390 function ArrayJoin(separator) { |
391 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.join"); | 391 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.join"); |
392 | 392 |
393 var array = TO_OBJECT_INLINE(this); | 393 var array = TO_OBJECT_INLINE(this); |
394 var length = TO_UINT32(array.length); | 394 var length = TO_UINT32(array.length); |
395 if (IS_UNDEFINED(separator)) { | 395 if (IS_UNDEFINED(separator)) { |
396 separator = ','; | 396 separator = ','; |
397 } else if (!IS_STRING(separator)) { | 397 } else if (!IS_STRING(separator)) { |
398 separator = $nonStringToString(separator); | 398 separator = NonStringToString(separator); |
399 } | 399 } |
400 | 400 |
401 var result = %_FastOneByteArrayJoin(array, separator); | 401 var result = %_FastOneByteArrayJoin(array, separator); |
402 if (!IS_UNDEFINED(result)) return result; | 402 if (!IS_UNDEFINED(result)) return result; |
403 | 403 |
404 // Fast case for one-element arrays. | 404 // Fast case for one-element arrays. |
405 if (length === 1) { | 405 if (length === 1) { |
406 var e = array[0]; | 406 var e = array[0]; |
407 if (IS_STRING(e)) return e; | 407 if (IS_STRING(e)) return e; |
408 if (IS_NULL_OR_UNDEFINED(e)) return ''; | 408 if (IS_NULL_OR_UNDEFINED(e)) return ''; |
409 return $nonStringToString(e); | 409 return NonStringToString(e); |
410 } | 410 } |
411 | 411 |
412 return Join(array, length, separator, ConvertToString); | 412 return Join(array, length, separator, ConvertToString); |
413 } | 413 } |
414 | 414 |
415 | 415 |
416 function ObservedArrayPop(n) { | 416 function ObservedArrayPop(n) { |
417 n--; | 417 n--; |
418 var value = this[n]; | 418 var value = this[n]; |
419 | 419 |
(...skipping 20 matching lines...) Expand all Loading... |
440 if (n == 0) { | 440 if (n == 0) { |
441 array.length = n; | 441 array.length = n; |
442 return; | 442 return; |
443 } | 443 } |
444 | 444 |
445 if (%IsObserved(array)) | 445 if (%IsObserved(array)) |
446 return ObservedArrayPop.call(array, n); | 446 return ObservedArrayPop.call(array, n); |
447 | 447 |
448 n--; | 448 n--; |
449 var value = array[n]; | 449 var value = array[n]; |
450 $delete(array, $toName(n), true); | 450 $delete(array, ToName(n), true); |
451 array.length = n; | 451 array.length = n; |
452 return value; | 452 return value; |
453 } | 453 } |
454 | 454 |
455 | 455 |
456 function ObservedArrayPush() { | 456 function ObservedArrayPush() { |
457 var n = TO_UINT32(this.length); | 457 var n = TO_UINT32(this.length); |
458 var m = %_ArgumentsLength(); | 458 var m = %_ArgumentsLength(); |
459 | 459 |
460 try { | 460 try { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 return new_length; | 494 return new_length; |
495 } | 495 } |
496 | 496 |
497 | 497 |
498 // Returns an array containing the array elements of the object followed | 498 // Returns an array containing the array elements of the object followed |
499 // by the array elements of each argument in order. See ECMA-262, | 499 // by the array elements of each argument in order. See ECMA-262, |
500 // section 15.4.4.7. | 500 // section 15.4.4.7. |
501 function ArrayConcatJS(arg1) { // length == 1 | 501 function ArrayConcatJS(arg1) { // length == 1 |
502 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.concat"); | 502 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.concat"); |
503 | 503 |
504 var array = $toObject(this); | 504 var array = ToObject(this); |
505 var arg_count = %_ArgumentsLength(); | 505 var arg_count = %_ArgumentsLength(); |
506 var arrays = new InternalArray(1 + arg_count); | 506 var arrays = new InternalArray(1 + arg_count); |
507 arrays[0] = array; | 507 arrays[0] = array; |
508 for (var i = 0; i < arg_count; i++) { | 508 for (var i = 0; i < arg_count; i++) { |
509 arrays[i + 1] = %_Arguments(i); | 509 arrays[i + 1] = %_Arguments(i); |
510 } | 510 } |
511 | 511 |
512 return %ArrayConcat(arrays); | 512 return %ArrayConcat(arrays); |
513 } | 513 } |
514 | 514 |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 | 859 |
860 // In-place QuickSort algorithm. | 860 // In-place QuickSort algorithm. |
861 // For short (length <= 22) arrays, insertion sort is used for efficiency. | 861 // For short (length <= 22) arrays, insertion sort is used for efficiency. |
862 | 862 |
863 if (!IS_SPEC_FUNCTION(comparefn)) { | 863 if (!IS_SPEC_FUNCTION(comparefn)) { |
864 comparefn = function (x, y) { | 864 comparefn = function (x, y) { |
865 if (x === y) return 0; | 865 if (x === y) return 0; |
866 if (%_IsSmi(x) && %_IsSmi(y)) { | 866 if (%_IsSmi(x) && %_IsSmi(y)) { |
867 return %SmiLexicographicCompare(x, y); | 867 return %SmiLexicographicCompare(x, y); |
868 } | 868 } |
869 x = $toString(x); | 869 x = ToString(x); |
870 y = $toString(y); | 870 y = ToString(y); |
871 if (x == y) return 0; | 871 if (x == y) return 0; |
872 else return x < y ? -1 : 1; | 872 else return x < y ? -1 : 1; |
873 }; | 873 }; |
874 } | 874 } |
875 var InsertionSort = function InsertionSort(a, from, to) { | 875 var InsertionSort = function InsertionSort(a, from, to) { |
876 for (var i = from + 1; i < to; i++) { | 876 for (var i = from + 1; i < to; i++) { |
877 var element = a[i]; | 877 var element = a[i]; |
878 for (var j = i - 1; j >= from; j--) { | 878 for (var j = i - 1; j >= from; j--) { |
879 var tmp = a[j]; | 879 var tmp = a[j]; |
880 var order = %_CallFunction(UNDEFINED, tmp, element, comparefn); | 880 var order = %_CallFunction(UNDEFINED, tmp, element, comparefn); |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1141 | 1141 |
1142 | 1142 |
1143 // The following functions cannot be made efficient on sparse arrays while | 1143 // The following functions cannot be made efficient on sparse arrays while |
1144 // preserving the semantics, since the calls to the receiver function can add | 1144 // preserving the semantics, since the calls to the receiver function can add |
1145 // or delete elements from the array. | 1145 // or delete elements from the array. |
1146 function ArrayFilter(f, receiver) { | 1146 function ArrayFilter(f, receiver) { |
1147 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.filter"); | 1147 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.filter"); |
1148 | 1148 |
1149 // Pull out the length so that modifications to the length in the | 1149 // Pull out the length so that modifications to the length in the |
1150 // loop will not affect the looping and side effects are visible. | 1150 // loop will not affect the looping and side effects are visible. |
1151 var array = $toObject(this); | 1151 var array = ToObject(this); |
1152 var length = $toUint32(array.length); | 1152 var length = ToUint32(array.length); |
1153 | 1153 |
1154 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); | 1154 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); |
1155 var needs_wrapper = false; | 1155 var needs_wrapper = false; |
1156 if (IS_NULL(receiver)) { | 1156 if (IS_NULL(receiver)) { |
1157 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; | 1157 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; |
1158 } else if (!IS_UNDEFINED(receiver)) { | 1158 } else if (!IS_UNDEFINED(receiver)) { |
1159 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | 1159 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
1160 } | 1160 } |
1161 | 1161 |
1162 var result = new GlobalArray(); | 1162 var result = new GlobalArray(); |
1163 var accumulator = new InternalArray(); | 1163 var accumulator = new InternalArray(); |
1164 var accumulator_length = 0; | 1164 var accumulator_length = 0; |
1165 var is_array = IS_ARRAY(array); | 1165 var is_array = IS_ARRAY(array); |
1166 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1166 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
1167 for (var i = 0; i < length; i++) { | 1167 for (var i = 0; i < length; i++) { |
1168 if (HAS_INDEX(array, i, is_array)) { | 1168 if (HAS_INDEX(array, i, is_array)) { |
1169 var element = array[i]; | 1169 var element = array[i]; |
1170 // Prepare break slots for debugger step in. | 1170 // Prepare break slots for debugger step in. |
1171 if (stepping) %DebugPrepareStepInIfStepping(f); | 1171 if (stepping) %DebugPrepareStepInIfStepping(f); |
1172 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver; | 1172 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
1173 if (%_CallFunction(new_receiver, element, i, array, f)) { | 1173 if (%_CallFunction(new_receiver, element, i, array, f)) { |
1174 accumulator[accumulator_length++] = element; | 1174 accumulator[accumulator_length++] = element; |
1175 } | 1175 } |
1176 } | 1176 } |
1177 } | 1177 } |
1178 %MoveArrayContents(accumulator, result); | 1178 %MoveArrayContents(accumulator, result); |
1179 return result; | 1179 return result; |
1180 } | 1180 } |
1181 | 1181 |
1182 | 1182 |
1183 function ArrayForEach(f, receiver) { | 1183 function ArrayForEach(f, receiver) { |
1184 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.forEach"); | 1184 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.forEach"); |
1185 | 1185 |
1186 // Pull out the length so that modifications to the length in the | 1186 // Pull out the length so that modifications to the length in the |
1187 // loop will not affect the looping and side effects are visible. | 1187 // loop will not affect the looping and side effects are visible. |
1188 var array = $toObject(this); | 1188 var array = ToObject(this); |
1189 var length = TO_UINT32(array.length); | 1189 var length = TO_UINT32(array.length); |
1190 | 1190 |
1191 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); | 1191 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); |
1192 var needs_wrapper = false; | 1192 var needs_wrapper = false; |
1193 if (IS_NULL(receiver)) { | 1193 if (IS_NULL(receiver)) { |
1194 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; | 1194 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; |
1195 } else if (!IS_UNDEFINED(receiver)) { | 1195 } else if (!IS_UNDEFINED(receiver)) { |
1196 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | 1196 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
1197 } | 1197 } |
1198 | 1198 |
1199 var is_array = IS_ARRAY(array); | 1199 var is_array = IS_ARRAY(array); |
1200 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1200 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
1201 for (var i = 0; i < length; i++) { | 1201 for (var i = 0; i < length; i++) { |
1202 if (HAS_INDEX(array, i, is_array)) { | 1202 if (HAS_INDEX(array, i, is_array)) { |
1203 var element = array[i]; | 1203 var element = array[i]; |
1204 // Prepare break slots for debugger step in. | 1204 // Prepare break slots for debugger step in. |
1205 if (stepping) %DebugPrepareStepInIfStepping(f); | 1205 if (stepping) %DebugPrepareStepInIfStepping(f); |
1206 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver; | 1206 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
1207 %_CallFunction(new_receiver, element, i, array, f); | 1207 %_CallFunction(new_receiver, element, i, array, f); |
1208 } | 1208 } |
1209 } | 1209 } |
1210 } | 1210 } |
1211 | 1211 |
1212 | 1212 |
1213 // Executes the function once for each element present in the | 1213 // Executes the function once for each element present in the |
1214 // array until it finds one where callback returns true. | 1214 // array until it finds one where callback returns true. |
1215 function ArraySome(f, receiver) { | 1215 function ArraySome(f, receiver) { |
1216 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.some"); | 1216 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.some"); |
1217 | 1217 |
1218 // Pull out the length so that modifications to the length in the | 1218 // Pull out the length so that modifications to the length in the |
1219 // loop will not affect the looping and side effects are visible. | 1219 // loop will not affect the looping and side effects are visible. |
1220 var array = $toObject(this); | 1220 var array = ToObject(this); |
1221 var length = TO_UINT32(array.length); | 1221 var length = TO_UINT32(array.length); |
1222 | 1222 |
1223 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); | 1223 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); |
1224 var needs_wrapper = false; | 1224 var needs_wrapper = false; |
1225 if (IS_NULL(receiver)) { | 1225 if (IS_NULL(receiver)) { |
1226 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; | 1226 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; |
1227 } else if (!IS_UNDEFINED(receiver)) { | 1227 } else if (!IS_UNDEFINED(receiver)) { |
1228 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | 1228 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
1229 } | 1229 } |
1230 | 1230 |
1231 var is_array = IS_ARRAY(array); | 1231 var is_array = IS_ARRAY(array); |
1232 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1232 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
1233 for (var i = 0; i < length; i++) { | 1233 for (var i = 0; i < length; i++) { |
1234 if (HAS_INDEX(array, i, is_array)) { | 1234 if (HAS_INDEX(array, i, is_array)) { |
1235 var element = array[i]; | 1235 var element = array[i]; |
1236 // Prepare break slots for debugger step in. | 1236 // Prepare break slots for debugger step in. |
1237 if (stepping) %DebugPrepareStepInIfStepping(f); | 1237 if (stepping) %DebugPrepareStepInIfStepping(f); |
1238 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver; | 1238 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
1239 if (%_CallFunction(new_receiver, element, i, array, f)) return true; | 1239 if (%_CallFunction(new_receiver, element, i, array, f)) return true; |
1240 } | 1240 } |
1241 } | 1241 } |
1242 return false; | 1242 return false; |
1243 } | 1243 } |
1244 | 1244 |
1245 | 1245 |
1246 function ArrayEvery(f, receiver) { | 1246 function ArrayEvery(f, receiver) { |
1247 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.every"); | 1247 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.every"); |
1248 | 1248 |
1249 // Pull out the length so that modifications to the length in the | 1249 // Pull out the length so that modifications to the length in the |
1250 // loop will not affect the looping and side effects are visible. | 1250 // loop will not affect the looping and side effects are visible. |
1251 var array = $toObject(this); | 1251 var array = ToObject(this); |
1252 var length = TO_UINT32(array.length); | 1252 var length = TO_UINT32(array.length); |
1253 | 1253 |
1254 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); | 1254 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); |
1255 var needs_wrapper = false; | 1255 var needs_wrapper = false; |
1256 if (IS_NULL(receiver)) { | 1256 if (IS_NULL(receiver)) { |
1257 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; | 1257 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; |
1258 } else if (!IS_UNDEFINED(receiver)) { | 1258 } else if (!IS_UNDEFINED(receiver)) { |
1259 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | 1259 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
1260 } | 1260 } |
1261 | 1261 |
1262 var is_array = IS_ARRAY(array); | 1262 var is_array = IS_ARRAY(array); |
1263 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1263 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
1264 for (var i = 0; i < length; i++) { | 1264 for (var i = 0; i < length; i++) { |
1265 if (HAS_INDEX(array, i, is_array)) { | 1265 if (HAS_INDEX(array, i, is_array)) { |
1266 var element = array[i]; | 1266 var element = array[i]; |
1267 // Prepare break slots for debugger step in. | 1267 // Prepare break slots for debugger step in. |
1268 if (stepping) %DebugPrepareStepInIfStepping(f); | 1268 if (stepping) %DebugPrepareStepInIfStepping(f); |
1269 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver; | 1269 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
1270 if (!%_CallFunction(new_receiver, element, i, array, f)) return false; | 1270 if (!%_CallFunction(new_receiver, element, i, array, f)) return false; |
1271 } | 1271 } |
1272 } | 1272 } |
1273 return true; | 1273 return true; |
1274 } | 1274 } |
1275 | 1275 |
1276 | 1276 |
1277 function ArrayMap(f, receiver) { | 1277 function ArrayMap(f, receiver) { |
1278 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.map"); | 1278 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.map"); |
1279 | 1279 |
1280 // Pull out the length so that modifications to the length in the | 1280 // Pull out the length so that modifications to the length in the |
1281 // loop will not affect the looping and side effects are visible. | 1281 // loop will not affect the looping and side effects are visible. |
1282 var array = $toObject(this); | 1282 var array = ToObject(this); |
1283 var length = TO_UINT32(array.length); | 1283 var length = TO_UINT32(array.length); |
1284 | 1284 |
1285 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); | 1285 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); |
1286 var needs_wrapper = false; | 1286 var needs_wrapper = false; |
1287 if (IS_NULL(receiver)) { | 1287 if (IS_NULL(receiver)) { |
1288 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; | 1288 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; |
1289 } else if (!IS_UNDEFINED(receiver)) { | 1289 } else if (!IS_UNDEFINED(receiver)) { |
1290 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | 1290 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
1291 } | 1291 } |
1292 | 1292 |
1293 var result = new GlobalArray(); | 1293 var result = new GlobalArray(); |
1294 var accumulator = new InternalArray(length); | 1294 var accumulator = new InternalArray(length); |
1295 var is_array = IS_ARRAY(array); | 1295 var is_array = IS_ARRAY(array); |
1296 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1296 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
1297 for (var i = 0; i < length; i++) { | 1297 for (var i = 0; i < length; i++) { |
1298 if (HAS_INDEX(array, i, is_array)) { | 1298 if (HAS_INDEX(array, i, is_array)) { |
1299 var element = array[i]; | 1299 var element = array[i]; |
1300 // Prepare break slots for debugger step in. | 1300 // Prepare break slots for debugger step in. |
1301 if (stepping) %DebugPrepareStepInIfStepping(f); | 1301 if (stepping) %DebugPrepareStepInIfStepping(f); |
1302 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver; | 1302 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
1303 accumulator[i] = %_CallFunction(new_receiver, element, i, array, f); | 1303 accumulator[i] = %_CallFunction(new_receiver, element, i, array, f); |
1304 } | 1304 } |
1305 } | 1305 } |
1306 %MoveArrayContents(accumulator, result); | 1306 %MoveArrayContents(accumulator, result); |
1307 return result; | 1307 return result; |
1308 } | 1308 } |
1309 | 1309 |
1310 | 1310 |
1311 function ArrayIndexOf(element, index) { | 1311 function ArrayIndexOf(element, index) { |
1312 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.indexOf"); | 1312 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.indexOf"); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1416 } | 1416 } |
1417 return -1; | 1417 return -1; |
1418 } | 1418 } |
1419 | 1419 |
1420 | 1420 |
1421 function ArrayReduce(callback, current) { | 1421 function ArrayReduce(callback, current) { |
1422 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduce"); | 1422 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduce"); |
1423 | 1423 |
1424 // Pull out the length so that modifications to the length in the | 1424 // Pull out the length so that modifications to the length in the |
1425 // loop will not affect the looping and side effects are visible. | 1425 // loop will not affect the looping and side effects are visible. |
1426 var array = $toObject(this); | 1426 var array = ToObject(this); |
1427 var length = $toUint32(array.length); | 1427 var length = ToUint32(array.length); |
1428 | 1428 |
1429 if (!IS_SPEC_FUNCTION(callback)) { | 1429 if (!IS_SPEC_FUNCTION(callback)) { |
1430 throw MakeTypeError(kCalledNonCallable, callback); | 1430 throw MakeTypeError(kCalledNonCallable, callback); |
1431 } | 1431 } |
1432 | 1432 |
1433 var is_array = IS_ARRAY(array); | 1433 var is_array = IS_ARRAY(array); |
1434 var i = 0; | 1434 var i = 0; |
1435 find_initial: if (%_ArgumentsLength() < 2) { | 1435 find_initial: if (%_ArgumentsLength() < 2) { |
1436 for (; i < length; i++) { | 1436 for (; i < length; i++) { |
1437 if (HAS_INDEX(array, i, is_array)) { | 1437 if (HAS_INDEX(array, i, is_array)) { |
(...skipping 15 matching lines...) Expand all Loading... |
1453 } | 1453 } |
1454 return current; | 1454 return current; |
1455 } | 1455 } |
1456 | 1456 |
1457 | 1457 |
1458 function ArrayReduceRight(callback, current) { | 1458 function ArrayReduceRight(callback, current) { |
1459 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduceRight"); | 1459 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduceRight"); |
1460 | 1460 |
1461 // Pull out the length so that side effects are visible before the | 1461 // Pull out the length so that side effects are visible before the |
1462 // callback function is checked. | 1462 // callback function is checked. |
1463 var array = $toObject(this); | 1463 var array = ToObject(this); |
1464 var length = $toUint32(array.length); | 1464 var length = ToUint32(array.length); |
1465 | 1465 |
1466 if (!IS_SPEC_FUNCTION(callback)) { | 1466 if (!IS_SPEC_FUNCTION(callback)) { |
1467 throw MakeTypeError(kCalledNonCallable, callback); | 1467 throw MakeTypeError(kCalledNonCallable, callback); |
1468 } | 1468 } |
1469 | 1469 |
1470 var is_array = IS_ARRAY(array); | 1470 var is_array = IS_ARRAY(array); |
1471 var i = length - 1; | 1471 var i = length - 1; |
1472 find_initial: if (%_ArgumentsLength() < 2) { | 1472 find_initial: if (%_ArgumentsLength() < 2) { |
1473 for (; i >= 0; i--) { | 1473 for (; i >= 0; i--) { |
1474 if (HAS_INDEX(array, i, is_array)) { | 1474 if (HAS_INDEX(array, i, is_array)) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1589 $arrayConcat = ArrayConcatJS; | 1589 $arrayConcat = ArrayConcatJS; |
1590 $arrayJoin = ArrayJoin; | 1590 $arrayJoin = ArrayJoin; |
1591 $arrayPush = ArrayPush; | 1591 $arrayPush = ArrayPush; |
1592 $arrayPop = ArrayPop; | 1592 $arrayPop = ArrayPop; |
1593 $arrayShift = ArrayShift; | 1593 $arrayShift = ArrayShift; |
1594 $arraySlice = ArraySlice; | 1594 $arraySlice = ArraySlice; |
1595 $arraySplice = ArraySplice; | 1595 $arraySplice = ArraySplice; |
1596 $arrayUnshift = ArrayUnshift; | 1596 $arrayUnshift = ArrayUnshift; |
1597 | 1597 |
1598 })(); | 1598 })(); |
OLD | NEW |