| 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 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 if (IS_ARRAY(this)) { | 379 if (IS_ARRAY(this)) { |
| 380 func = this.join; | 380 func = this.join; |
| 381 if (func === ArrayJoin) { | 381 if (func === ArrayJoin) { |
| 382 return Join(this, this.length, ',', ConvertToString); | 382 return Join(this, this.length, ',', ConvertToString); |
| 383 } | 383 } |
| 384 array = this; | 384 array = this; |
| 385 } else { | 385 } else { |
| 386 array = TO_OBJECT(this); | 386 array = TO_OBJECT(this); |
| 387 func = array.join; | 387 func = array.join; |
| 388 } | 388 } |
| 389 if (!IS_SPEC_FUNCTION(func)) { | 389 if (!IS_CALLABLE(func)) { |
| 390 return %_CallFunction(array, ObjectToString); | 390 return %_CallFunction(array, ObjectToString); |
| 391 } | 391 } |
| 392 return %_CallFunction(array, func); | 392 return %_CallFunction(array, func); |
| 393 } | 393 } |
| 394 | 394 |
| 395 | 395 |
| 396 function InnerArrayToLocaleString(array, length) { | 396 function InnerArrayToLocaleString(array, length) { |
| 397 var len = TO_UINT32(length); | 397 var len = TO_UINT32(length); |
| 398 if (len === 0) return ""; | 398 if (len === 0) return ""; |
| 399 return Join(array, len, ',', ConvertToLocaleString); | 399 return Join(array, len, ',', ConvertToLocaleString); |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 896 | 896 |
| 897 // Return the deleted elements. | 897 // Return the deleted elements. |
| 898 return deleted_elements; | 898 return deleted_elements; |
| 899 } | 899 } |
| 900 | 900 |
| 901 | 901 |
| 902 function InnerArraySort(length, comparefn) { | 902 function InnerArraySort(length, comparefn) { |
| 903 // In-place QuickSort algorithm. | 903 // In-place QuickSort algorithm. |
| 904 // For short (length <= 22) arrays, insertion sort is used for efficiency. | 904 // For short (length <= 22) arrays, insertion sort is used for efficiency. |
| 905 | 905 |
| 906 if (!IS_SPEC_FUNCTION(comparefn)) { | 906 if (!IS_CALLABLE(comparefn)) { |
| 907 comparefn = function (x, y) { | 907 comparefn = function (x, y) { |
| 908 if (x === y) return 0; | 908 if (x === y) return 0; |
| 909 if (%_IsSmi(x) && %_IsSmi(y)) { | 909 if (%_IsSmi(x) && %_IsSmi(y)) { |
| 910 return %SmiLexicographicCompare(x, y); | 910 return %SmiLexicographicCompare(x, y); |
| 911 } | 911 } |
| 912 x = ToString(x); | 912 x = ToString(x); |
| 913 y = ToString(y); | 913 y = ToString(y); |
| 914 if (x == y) return 0; | 914 if (x == y) return 0; |
| 915 else return x < y ? -1 : 1; | 915 else return x < y ? -1 : 1; |
| 916 }; | 916 }; |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1188 var array = TO_OBJECT(this); | 1188 var array = TO_OBJECT(this); |
| 1189 var length = TO_UINT32(array.length); | 1189 var length = TO_UINT32(array.length); |
| 1190 return %_CallFunction(array, length, comparefn, InnerArraySort); | 1190 return %_CallFunction(array, length, comparefn, InnerArraySort); |
| 1191 } | 1191 } |
| 1192 | 1192 |
| 1193 | 1193 |
| 1194 // The following functions cannot be made efficient on sparse arrays while | 1194 // The following functions cannot be made efficient on sparse arrays while |
| 1195 // preserving the semantics, since the calls to the receiver function can add | 1195 // preserving the semantics, since the calls to the receiver function can add |
| 1196 // or delete elements from the array. | 1196 // or delete elements from the array. |
| 1197 function InnerArrayFilter(f, receiver, array, length) { | 1197 function InnerArrayFilter(f, receiver, array, length) { |
| 1198 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); | 1198 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); |
| 1199 var needs_wrapper = false; | 1199 var needs_wrapper = false; |
| 1200 if (IS_NULL(receiver)) { | 1200 if (IS_NULL(receiver)) { |
| 1201 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; | 1201 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; |
| 1202 } else if (!IS_UNDEFINED(receiver)) { | 1202 } else if (!IS_UNDEFINED(receiver)) { |
| 1203 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | 1203 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
| 1204 } | 1204 } |
| 1205 | 1205 |
| 1206 var accumulator = new InternalArray(); | 1206 var accumulator = new InternalArray(); |
| 1207 var accumulator_length = 0; | 1207 var accumulator_length = 0; |
| 1208 var is_array = IS_ARRAY(array); | 1208 var is_array = IS_ARRAY(array); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1228 // loop will not affect the looping and side effects are visible. | 1228 // loop will not affect the looping and side effects are visible. |
| 1229 var array = TO_OBJECT(this); | 1229 var array = TO_OBJECT(this); |
| 1230 var length = TO_UINT32(array.length); | 1230 var length = TO_UINT32(array.length); |
| 1231 var accumulator = InnerArrayFilter(f, receiver, array, length); | 1231 var accumulator = InnerArrayFilter(f, receiver, array, length); |
| 1232 var result = new GlobalArray(); | 1232 var result = new GlobalArray(); |
| 1233 %MoveArrayContents(accumulator, result); | 1233 %MoveArrayContents(accumulator, result); |
| 1234 return result; | 1234 return result; |
| 1235 } | 1235 } |
| 1236 | 1236 |
| 1237 function InnerArrayForEach(f, receiver, array, length) { | 1237 function InnerArrayForEach(f, receiver, array, length) { |
| 1238 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); | 1238 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); |
| 1239 var needs_wrapper = false; | 1239 var needs_wrapper = false; |
| 1240 if (IS_NULL(receiver)) { | 1240 if (IS_NULL(receiver)) { |
| 1241 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; | 1241 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; |
| 1242 } else if (!IS_UNDEFINED(receiver)) { | 1242 } else if (!IS_UNDEFINED(receiver)) { |
| 1243 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | 1243 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
| 1244 } | 1244 } |
| 1245 | 1245 |
| 1246 var is_array = IS_ARRAY(array); | 1246 var is_array = IS_ARRAY(array); |
| 1247 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1247 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
| 1248 for (var i = 0; i < length; i++) { | 1248 for (var i = 0; i < length; i++) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1261 | 1261 |
| 1262 // Pull out the length so that modifications to the length in the | 1262 // Pull out the length so that modifications to the length in the |
| 1263 // loop will not affect the looping and side effects are visible. | 1263 // loop will not affect the looping and side effects are visible. |
| 1264 var array = TO_OBJECT(this); | 1264 var array = TO_OBJECT(this); |
| 1265 var length = TO_UINT32(array.length); | 1265 var length = TO_UINT32(array.length); |
| 1266 InnerArrayForEach(f, receiver, array, length); | 1266 InnerArrayForEach(f, receiver, array, length); |
| 1267 } | 1267 } |
| 1268 | 1268 |
| 1269 | 1269 |
| 1270 function InnerArraySome(f, receiver, array, length) { | 1270 function InnerArraySome(f, receiver, array, length) { |
| 1271 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); | 1271 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); |
| 1272 var needs_wrapper = false; | 1272 var needs_wrapper = false; |
| 1273 if (IS_NULL(receiver)) { | 1273 if (IS_NULL(receiver)) { |
| 1274 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; | 1274 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; |
| 1275 } else if (!IS_UNDEFINED(receiver)) { | 1275 } else if (!IS_UNDEFINED(receiver)) { |
| 1276 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | 1276 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
| 1277 } | 1277 } |
| 1278 | 1278 |
| 1279 var is_array = IS_ARRAY(array); | 1279 var is_array = IS_ARRAY(array); |
| 1280 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1280 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
| 1281 for (var i = 0; i < length; i++) { | 1281 for (var i = 0; i < length; i++) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1298 | 1298 |
| 1299 // Pull out the length so that modifications to the length in the | 1299 // Pull out the length so that modifications to the length in the |
| 1300 // loop will not affect the looping and side effects are visible. | 1300 // loop will not affect the looping and side effects are visible. |
| 1301 var array = TO_OBJECT(this); | 1301 var array = TO_OBJECT(this); |
| 1302 var length = TO_UINT32(array.length); | 1302 var length = TO_UINT32(array.length); |
| 1303 return InnerArraySome(f, receiver, array, length); | 1303 return InnerArraySome(f, receiver, array, length); |
| 1304 } | 1304 } |
| 1305 | 1305 |
| 1306 | 1306 |
| 1307 function InnerArrayEvery(f, receiver, array, length) { | 1307 function InnerArrayEvery(f, receiver, array, length) { |
| 1308 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); | 1308 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); |
| 1309 var needs_wrapper = false; | 1309 var needs_wrapper = false; |
| 1310 if (IS_NULL(receiver)) { | 1310 if (IS_NULL(receiver)) { |
| 1311 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; | 1311 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; |
| 1312 } else if (!IS_UNDEFINED(receiver)) { | 1312 } else if (!IS_UNDEFINED(receiver)) { |
| 1313 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | 1313 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
| 1314 } | 1314 } |
| 1315 | 1315 |
| 1316 var is_array = IS_ARRAY(array); | 1316 var is_array = IS_ARRAY(array); |
| 1317 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1317 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
| 1318 for (var i = 0; i < length; i++) { | 1318 for (var i = 0; i < length; i++) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1332 | 1332 |
| 1333 // Pull out the length so that modifications to the length in the | 1333 // Pull out the length so that modifications to the length in the |
| 1334 // loop will not affect the looping and side effects are visible. | 1334 // loop will not affect the looping and side effects are visible. |
| 1335 var array = TO_OBJECT(this); | 1335 var array = TO_OBJECT(this); |
| 1336 var length = TO_UINT32(array.length); | 1336 var length = TO_UINT32(array.length); |
| 1337 return InnerArrayEvery(f, receiver, array, length); | 1337 return InnerArrayEvery(f, receiver, array, length); |
| 1338 } | 1338 } |
| 1339 | 1339 |
| 1340 | 1340 |
| 1341 function InnerArrayMap(f, receiver, array, length) { | 1341 function InnerArrayMap(f, receiver, array, length) { |
| 1342 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); | 1342 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); |
| 1343 var needs_wrapper = false; | 1343 var needs_wrapper = false; |
| 1344 if (IS_NULL(receiver)) { | 1344 if (IS_NULL(receiver)) { |
| 1345 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; | 1345 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; |
| 1346 } else if (!IS_UNDEFINED(receiver)) { | 1346 } else if (!IS_UNDEFINED(receiver)) { |
| 1347 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | 1347 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
| 1348 } | 1348 } |
| 1349 | 1349 |
| 1350 var accumulator = new InternalArray(length); | 1350 var accumulator = new InternalArray(length); |
| 1351 var is_array = IS_ARRAY(array); | 1351 var is_array = IS_ARRAY(array); |
| 1352 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1352 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1496 function ArrayLastIndexOf(element, index) { | 1496 function ArrayLastIndexOf(element, index) { |
| 1497 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.lastIndexOf"); | 1497 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.lastIndexOf"); |
| 1498 | 1498 |
| 1499 var length = TO_UINT32(this.length); | 1499 var length = TO_UINT32(this.length); |
| 1500 return %_CallFunction(this, element, index, length, | 1500 return %_CallFunction(this, element, index, length, |
| 1501 %_ArgumentsLength(), InnerArrayLastIndexOf); | 1501 %_ArgumentsLength(), InnerArrayLastIndexOf); |
| 1502 } | 1502 } |
| 1503 | 1503 |
| 1504 | 1504 |
| 1505 function InnerArrayReduce(callback, current, array, length, argumentsLength) { | 1505 function InnerArrayReduce(callback, current, array, length, argumentsLength) { |
| 1506 if (!IS_SPEC_FUNCTION(callback)) { | 1506 if (!IS_CALLABLE(callback)) { |
| 1507 throw MakeTypeError(kCalledNonCallable, callback); | 1507 throw MakeTypeError(kCalledNonCallable, callback); |
| 1508 } | 1508 } |
| 1509 | 1509 |
| 1510 var is_array = IS_ARRAY(array); | 1510 var is_array = IS_ARRAY(array); |
| 1511 var i = 0; | 1511 var i = 0; |
| 1512 find_initial: if (argumentsLength < 2) { | 1512 find_initial: if (argumentsLength < 2) { |
| 1513 for (; i < length; i++) { | 1513 for (; i < length; i++) { |
| 1514 if (HAS_INDEX(array, i, is_array)) { | 1514 if (HAS_INDEX(array, i, is_array)) { |
| 1515 current = array[i++]; | 1515 current = array[i++]; |
| 1516 break find_initial; | 1516 break find_initial; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1539 // loop will not affect the looping and side effects are visible. | 1539 // loop will not affect the looping and side effects are visible. |
| 1540 var array = TO_OBJECT(this); | 1540 var array = TO_OBJECT(this); |
| 1541 var length = TO_UINT32(array.length); | 1541 var length = TO_UINT32(array.length); |
| 1542 return InnerArrayReduce(callback, current, array, length, | 1542 return InnerArrayReduce(callback, current, array, length, |
| 1543 %_ArgumentsLength()); | 1543 %_ArgumentsLength()); |
| 1544 } | 1544 } |
| 1545 | 1545 |
| 1546 | 1546 |
| 1547 function InnerArrayReduceRight(callback, current, array, length, | 1547 function InnerArrayReduceRight(callback, current, array, length, |
| 1548 argumentsLength) { | 1548 argumentsLength) { |
| 1549 if (!IS_SPEC_FUNCTION(callback)) { | 1549 if (!IS_CALLABLE(callback)) { |
| 1550 throw MakeTypeError(kCalledNonCallable, callback); | 1550 throw MakeTypeError(kCalledNonCallable, callback); |
| 1551 } | 1551 } |
| 1552 | 1552 |
| 1553 var is_array = IS_ARRAY(array); | 1553 var is_array = IS_ARRAY(array); |
| 1554 var i = length - 1; | 1554 var i = length - 1; |
| 1555 find_initial: if (argumentsLength < 2) { | 1555 find_initial: if (argumentsLength < 2) { |
| 1556 for (; i >= 0; i--) { | 1556 for (; i >= 0; i--) { |
| 1557 if (HAS_INDEX(array, i, is_array)) { | 1557 if (HAS_INDEX(array, i, is_array)) { |
| 1558 current = array[i--]; | 1558 current = array[i--]; |
| 1559 break find_initial; | 1559 break find_initial; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1708 "array_concat", ArrayConcatJS, | 1708 "array_concat", ArrayConcatJS, |
| 1709 "array_pop", ArrayPop, | 1709 "array_pop", ArrayPop, |
| 1710 "array_push", ArrayPush, | 1710 "array_push", ArrayPush, |
| 1711 "array_shift", ArrayShift, | 1711 "array_shift", ArrayShift, |
| 1712 "array_splice", ArraySplice, | 1712 "array_splice", ArraySplice, |
| 1713 "array_slice", ArraySlice, | 1713 "array_slice", ArraySlice, |
| 1714 "array_unshift", ArrayUnshift, | 1714 "array_unshift", ArrayUnshift, |
| 1715 ]); | 1715 ]); |
| 1716 | 1716 |
| 1717 }); | 1717 }); |
| OLD | NEW |