| 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 "use strict"; | 5 "use strict"; |
| 6 | 6 |
| 7 // This file relies on the fact that the following declarations have been made | 7 // This file relies on the fact that the following declarations have been made |
| 8 // in runtime.js: | 8 // in runtime.js: |
| 9 // var $Array = global.Array; | 9 // var $Array = global.Array; |
| 10 | 10 |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 array[key] = new_array[key]; | 291 array[key] = new_array[key]; |
| 292 } | 292 } |
| 293 } | 293 } |
| 294 } | 294 } |
| 295 | 295 |
| 296 | 296 |
| 297 // This is part of the old simple-minded splice. We are using it either | 297 // This is part of the old simple-minded splice. We are using it either |
| 298 // because the receiver is not an array (so we have no choice) or because we | 298 // because the receiver is not an array (so we have no choice) or because we |
| 299 // know we are not deleting or moving a lot of elements. | 299 // know we are not deleting or moving a lot of elements. |
| 300 function SimpleSlice(array, start_i, del_count, len, deleted_elements) { | 300 function SimpleSlice(array, start_i, del_count, len, deleted_elements) { |
| 301 var is_array = IS_ARRAY(array); |
| 301 for (var i = 0; i < del_count; i++) { | 302 for (var i = 0; i < del_count; i++) { |
| 302 var index = start_i + i; | 303 var index = start_i + i; |
| 303 if (index in array) { | 304 if (HAS_INDEX(array, index, is_array)) { |
| 304 var current = array[index]; | 305 var current = array[index]; |
| 305 // The spec requires [[DefineOwnProperty]] here, %AddElement is close | 306 // The spec requires [[DefineOwnProperty]] here, %AddElement is close |
| 306 // enough (in that it ignores the prototype). | 307 // enough (in that it ignores the prototype). |
| 307 %AddElement(deleted_elements, i, current, NONE); | 308 %AddElement(deleted_elements, i, current, NONE); |
| 308 } | 309 } |
| 309 } | 310 } |
| 310 } | 311 } |
| 311 | 312 |
| 312 | 313 |
| 313 function SimpleMove(array, start_i, del_count, len, num_additional_args) { | 314 function SimpleMove(array, start_i, del_count, len, num_additional_args) { |
| 315 var is_array = IS_ARRAY(array); |
| 314 if (num_additional_args !== del_count) { | 316 if (num_additional_args !== del_count) { |
| 315 // Move the existing elements after the elements to be deleted | 317 // Move the existing elements after the elements to be deleted |
| 316 // to the right position in the resulting array. | 318 // to the right position in the resulting array. |
| 317 if (num_additional_args > del_count) { | 319 if (num_additional_args > del_count) { |
| 318 for (var i = len - del_count; i > start_i; i--) { | 320 for (var i = len - del_count; i > start_i; i--) { |
| 319 var from_index = i + del_count - 1; | 321 var from_index = i + del_count - 1; |
| 320 var to_index = i + num_additional_args - 1; | 322 var to_index = i + num_additional_args - 1; |
| 321 if (from_index in array) { | 323 if (HAS_INDEX(array, from_index, is_array)) { |
| 322 array[to_index] = array[from_index]; | 324 array[to_index] = array[from_index]; |
| 323 } else { | 325 } else { |
| 324 delete array[to_index]; | 326 delete array[to_index]; |
| 325 } | 327 } |
| 326 } | 328 } |
| 327 } else { | 329 } else { |
| 328 for (var i = start_i; i < len - del_count; i++) { | 330 for (var i = start_i; i < len - del_count; i++) { |
| 329 var from_index = i + del_count; | 331 var from_index = i + del_count; |
| 330 var to_index = i + num_additional_args; | 332 var to_index = i + num_additional_args; |
| 331 if (from_index in array) { | 333 if (HAS_INDEX(array, from_index, is_array)) { |
| 332 array[to_index] = array[from_index]; | 334 array[to_index] = array[from_index]; |
| 333 } else { | 335 } else { |
| 334 delete array[to_index]; | 336 delete array[to_index]; |
| 335 } | 337 } |
| 336 } | 338 } |
| 337 for (var i = len; i > len - del_count + num_additional_args; i--) { | 339 for (var i = len; i > len - del_count + num_additional_args; i--) { |
| 338 delete array[i - 1]; | 340 delete array[i - 1]; |
| 339 } | 341 } |
| 340 } | 342 } |
| 341 } | 343 } |
| (...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1146 var needs_wrapper = false; | 1148 var needs_wrapper = false; |
| 1147 if (IS_NULL_OR_UNDEFINED(receiver)) { | 1149 if (IS_NULL_OR_UNDEFINED(receiver)) { |
| 1148 receiver = %GetDefaultReceiver(f) || receiver; | 1150 receiver = %GetDefaultReceiver(f) || receiver; |
| 1149 } else { | 1151 } else { |
| 1150 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | 1152 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
| 1151 } | 1153 } |
| 1152 | 1154 |
| 1153 var result = new $Array(); | 1155 var result = new $Array(); |
| 1154 var accumulator = new InternalArray(); | 1156 var accumulator = new InternalArray(); |
| 1155 var accumulator_length = 0; | 1157 var accumulator_length = 0; |
| 1158 var is_array = IS_ARRAY(array); |
| 1156 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1159 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
| 1157 for (var i = 0; i < length; i++) { | 1160 for (var i = 0; i < length; i++) { |
| 1158 if (i in array) { | 1161 if (HAS_INDEX(array, i, is_array)) { |
| 1159 var element = array[i]; | 1162 var element = array[i]; |
| 1160 // Prepare break slots for debugger step in. | 1163 // Prepare break slots for debugger step in. |
| 1161 if (stepping) %DebugPrepareStepInIfStepping(f); | 1164 if (stepping) %DebugPrepareStepInIfStepping(f); |
| 1162 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; | 1165 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
| 1163 if (%_CallFunction(new_receiver, element, i, array, f)) { | 1166 if (%_CallFunction(new_receiver, element, i, array, f)) { |
| 1164 accumulator[accumulator_length++] = element; | 1167 accumulator[accumulator_length++] = element; |
| 1165 } | 1168 } |
| 1166 } | 1169 } |
| 1167 } | 1170 } |
| 1168 %MoveArrayContents(accumulator, result); | 1171 %MoveArrayContents(accumulator, result); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1181 if (!IS_SPEC_FUNCTION(f)) { | 1184 if (!IS_SPEC_FUNCTION(f)) { |
| 1182 throw MakeTypeError('called_non_callable', [ f ]); | 1185 throw MakeTypeError('called_non_callable', [ f ]); |
| 1183 } | 1186 } |
| 1184 var needs_wrapper = false; | 1187 var needs_wrapper = false; |
| 1185 if (IS_NULL_OR_UNDEFINED(receiver)) { | 1188 if (IS_NULL_OR_UNDEFINED(receiver)) { |
| 1186 receiver = %GetDefaultReceiver(f) || receiver; | 1189 receiver = %GetDefaultReceiver(f) || receiver; |
| 1187 } else { | 1190 } else { |
| 1188 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | 1191 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
| 1189 } | 1192 } |
| 1190 | 1193 |
| 1194 var is_array = IS_ARRAY(array); |
| 1191 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1195 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
| 1192 for (var i = 0; i < length; i++) { | 1196 for (var i = 0; i < length; i++) { |
| 1193 if (i in array) { | 1197 if (HAS_INDEX(array, i, is_array)) { |
| 1194 var element = array[i]; | 1198 var element = array[i]; |
| 1195 // Prepare break slots for debugger step in. | 1199 // Prepare break slots for debugger step in. |
| 1196 if (stepping) %DebugPrepareStepInIfStepping(f); | 1200 if (stepping) %DebugPrepareStepInIfStepping(f); |
| 1197 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; | 1201 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
| 1198 %_CallFunction(new_receiver, element, i, array, f); | 1202 %_CallFunction(new_receiver, element, i, array, f); |
| 1199 } | 1203 } |
| 1200 } | 1204 } |
| 1201 } | 1205 } |
| 1202 | 1206 |
| 1203 | 1207 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1214 if (!IS_SPEC_FUNCTION(f)) { | 1218 if (!IS_SPEC_FUNCTION(f)) { |
| 1215 throw MakeTypeError('called_non_callable', [ f ]); | 1219 throw MakeTypeError('called_non_callable', [ f ]); |
| 1216 } | 1220 } |
| 1217 var needs_wrapper = false; | 1221 var needs_wrapper = false; |
| 1218 if (IS_NULL_OR_UNDEFINED(receiver)) { | 1222 if (IS_NULL_OR_UNDEFINED(receiver)) { |
| 1219 receiver = %GetDefaultReceiver(f) || receiver; | 1223 receiver = %GetDefaultReceiver(f) || receiver; |
| 1220 } else { | 1224 } else { |
| 1221 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | 1225 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
| 1222 } | 1226 } |
| 1223 | 1227 |
| 1228 var is_array = IS_ARRAY(array); |
| 1224 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1229 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
| 1225 for (var i = 0; i < length; i++) { | 1230 for (var i = 0; i < length; i++) { |
| 1226 if (i in array) { | 1231 if (HAS_INDEX(array, i, is_array)) { |
| 1227 var element = array[i]; | 1232 var element = array[i]; |
| 1228 // Prepare break slots for debugger step in. | 1233 // Prepare break slots for debugger step in. |
| 1229 if (stepping) %DebugPrepareStepInIfStepping(f); | 1234 if (stepping) %DebugPrepareStepInIfStepping(f); |
| 1230 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; | 1235 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
| 1231 if (%_CallFunction(new_receiver, element, i, array, f)) return true; | 1236 if (%_CallFunction(new_receiver, element, i, array, f)) return true; |
| 1232 } | 1237 } |
| 1233 } | 1238 } |
| 1234 return false; | 1239 return false; |
| 1235 } | 1240 } |
| 1236 | 1241 |
| 1237 | 1242 |
| 1238 function ArrayEvery(f, receiver) { | 1243 function ArrayEvery(f, receiver) { |
| 1239 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.every"); | 1244 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.every"); |
| 1240 | 1245 |
| 1241 // Pull out the length so that modifications to the length in the | 1246 // Pull out the length so that modifications to the length in the |
| 1242 // loop will not affect the looping and side effects are visible. | 1247 // loop will not affect the looping and side effects are visible. |
| 1243 var array = ToObject(this); | 1248 var array = ToObject(this); |
| 1244 var length = TO_UINT32(array.length); | 1249 var length = TO_UINT32(array.length); |
| 1245 | 1250 |
| 1246 if (!IS_SPEC_FUNCTION(f)) { | 1251 if (!IS_SPEC_FUNCTION(f)) { |
| 1247 throw MakeTypeError('called_non_callable', [ f ]); | 1252 throw MakeTypeError('called_non_callable', [ f ]); |
| 1248 } | 1253 } |
| 1249 var needs_wrapper = false; | 1254 var needs_wrapper = false; |
| 1250 if (IS_NULL_OR_UNDEFINED(receiver)) { | 1255 if (IS_NULL_OR_UNDEFINED(receiver)) { |
| 1251 receiver = %GetDefaultReceiver(f) || receiver; | 1256 receiver = %GetDefaultReceiver(f) || receiver; |
| 1252 } else { | 1257 } else { |
| 1253 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | 1258 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
| 1254 } | 1259 } |
| 1255 | 1260 |
| 1261 var is_array = IS_ARRAY(array); |
| 1256 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1262 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
| 1257 for (var i = 0; i < length; i++) { | 1263 for (var i = 0; i < length; i++) { |
| 1258 if (i in array) { | 1264 if (HAS_INDEX(array, i, is_array)) { |
| 1259 var element = array[i]; | 1265 var element = array[i]; |
| 1260 // Prepare break slots for debugger step in. | 1266 // Prepare break slots for debugger step in. |
| 1261 if (stepping) %DebugPrepareStepInIfStepping(f); | 1267 if (stepping) %DebugPrepareStepInIfStepping(f); |
| 1262 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; | 1268 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
| 1263 if (!%_CallFunction(new_receiver, element, i, array, f)) return false; | 1269 if (!%_CallFunction(new_receiver, element, i, array, f)) return false; |
| 1264 } | 1270 } |
| 1265 } | 1271 } |
| 1266 return true; | 1272 return true; |
| 1267 } | 1273 } |
| 1268 | 1274 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1279 } | 1285 } |
| 1280 var needs_wrapper = false; | 1286 var needs_wrapper = false; |
| 1281 if (IS_NULL_OR_UNDEFINED(receiver)) { | 1287 if (IS_NULL_OR_UNDEFINED(receiver)) { |
| 1282 receiver = %GetDefaultReceiver(f) || receiver; | 1288 receiver = %GetDefaultReceiver(f) || receiver; |
| 1283 } else { | 1289 } else { |
| 1284 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | 1290 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
| 1285 } | 1291 } |
| 1286 | 1292 |
| 1287 var result = new $Array(); | 1293 var result = new $Array(); |
| 1288 var accumulator = new InternalArray(length); | 1294 var accumulator = new InternalArray(length); |
| 1295 var is_array = IS_ARRAY(array); |
| 1289 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1296 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
| 1290 for (var i = 0; i < length; i++) { | 1297 for (var i = 0; i < length; i++) { |
| 1291 if (i in array) { | 1298 if (HAS_INDEX(array, i, is_array)) { |
| 1292 var element = array[i]; | 1299 var element = array[i]; |
| 1293 // Prepare break slots for debugger step in. | 1300 // Prepare break slots for debugger step in. |
| 1294 if (stepping) %DebugPrepareStepInIfStepping(f); | 1301 if (stepping) %DebugPrepareStepInIfStepping(f); |
| 1295 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; | 1302 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
| 1296 accumulator[i] = %_CallFunction(new_receiver, element, i, array, f); | 1303 accumulator[i] = %_CallFunction(new_receiver, element, i, array, f); |
| 1297 } | 1304 } |
| 1298 } | 1305 } |
| 1299 %MoveArrayContents(accumulator, result); | 1306 %MoveArrayContents(accumulator, result); |
| 1300 return result; | 1307 return result; |
| 1301 } | 1308 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1416 | 1423 |
| 1417 // 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 |
| 1418 // loop will not affect the looping and side effects are visible. | 1425 // loop will not affect the looping and side effects are visible. |
| 1419 var array = ToObject(this); | 1426 var array = ToObject(this); |
| 1420 var length = ToUint32(array.length); | 1427 var length = ToUint32(array.length); |
| 1421 | 1428 |
| 1422 if (!IS_SPEC_FUNCTION(callback)) { | 1429 if (!IS_SPEC_FUNCTION(callback)) { |
| 1423 throw MakeTypeError('called_non_callable', [callback]); | 1430 throw MakeTypeError('called_non_callable', [callback]); |
| 1424 } | 1431 } |
| 1425 | 1432 |
| 1433 var is_array = IS_ARRAY(array); |
| 1426 var i = 0; | 1434 var i = 0; |
| 1427 find_initial: if (%_ArgumentsLength() < 2) { | 1435 find_initial: if (%_ArgumentsLength() < 2) { |
| 1428 for (; i < length; i++) { | 1436 for (; i < length; i++) { |
| 1429 if (i in array) { | 1437 if (HAS_INDEX(array, i, is_array)) { |
| 1430 current = array[i++]; | 1438 current = array[i++]; |
| 1431 break find_initial; | 1439 break find_initial; |
| 1432 } | 1440 } |
| 1433 } | 1441 } |
| 1434 throw MakeTypeError('reduce_no_initial', []); | 1442 throw MakeTypeError('reduce_no_initial', []); |
| 1435 } | 1443 } |
| 1436 | 1444 |
| 1437 var receiver = %GetDefaultReceiver(callback); | 1445 var receiver = %GetDefaultReceiver(callback); |
| 1438 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(callback); | 1446 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(callback); |
| 1439 for (; i < length; i++) { | 1447 for (; i < length; i++) { |
| 1440 if (i in array) { | 1448 if (HAS_INDEX(array, i, is_array)) { |
| 1441 var element = array[i]; | 1449 var element = array[i]; |
| 1442 // Prepare break slots for debugger step in. | 1450 // Prepare break slots for debugger step in. |
| 1443 if (stepping) %DebugPrepareStepInIfStepping(callback); | 1451 if (stepping) %DebugPrepareStepInIfStepping(callback); |
| 1444 current = %_CallFunction(receiver, current, element, i, array, callback); | 1452 current = %_CallFunction(receiver, current, element, i, array, callback); |
| 1445 } | 1453 } |
| 1446 } | 1454 } |
| 1447 return current; | 1455 return current; |
| 1448 } | 1456 } |
| 1449 | 1457 |
| 1450 function ArrayReduceRight(callback, current) { | 1458 function ArrayReduceRight(callback, current) { |
| 1451 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduceRight"); | 1459 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduceRight"); |
| 1452 | 1460 |
| 1453 // 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 |
| 1454 // callback function is checked. | 1462 // callback function is checked. |
| 1455 var array = ToObject(this); | 1463 var array = ToObject(this); |
| 1456 var length = ToUint32(array.length); | 1464 var length = ToUint32(array.length); |
| 1457 | 1465 |
| 1458 if (!IS_SPEC_FUNCTION(callback)) { | 1466 if (!IS_SPEC_FUNCTION(callback)) { |
| 1459 throw MakeTypeError('called_non_callable', [callback]); | 1467 throw MakeTypeError('called_non_callable', [callback]); |
| 1460 } | 1468 } |
| 1461 | 1469 |
| 1470 var is_array = IS_ARRAY(array); |
| 1462 var i = length - 1; | 1471 var i = length - 1; |
| 1463 find_initial: if (%_ArgumentsLength() < 2) { | 1472 find_initial: if (%_ArgumentsLength() < 2) { |
| 1464 for (; i >= 0; i--) { | 1473 for (; i >= 0; i--) { |
| 1465 if (i in array) { | 1474 if (HAS_INDEX(array, i, is_array)) { |
| 1466 current = array[i--]; | 1475 current = array[i--]; |
| 1467 break find_initial; | 1476 break find_initial; |
| 1468 } | 1477 } |
| 1469 } | 1478 } |
| 1470 throw MakeTypeError('reduce_no_initial', []); | 1479 throw MakeTypeError('reduce_no_initial', []); |
| 1471 } | 1480 } |
| 1472 | 1481 |
| 1473 var receiver = %GetDefaultReceiver(callback); | 1482 var receiver = %GetDefaultReceiver(callback); |
| 1474 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(callback); | 1483 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(callback); |
| 1475 for (; i >= 0; i--) { | 1484 for (; i >= 0; i--) { |
| 1476 if (i in array) { | 1485 if (HAS_INDEX(array, i, is_array)) { |
| 1477 var element = array[i]; | 1486 var element = array[i]; |
| 1478 // Prepare break slots for debugger step in. | 1487 // Prepare break slots for debugger step in. |
| 1479 if (stepping) %DebugPrepareStepInIfStepping(callback); | 1488 if (stepping) %DebugPrepareStepInIfStepping(callback); |
| 1480 current = %_CallFunction(receiver, current, element, i, array, callback); | 1489 current = %_CallFunction(receiver, current, element, i, array, callback); |
| 1481 } | 1490 } |
| 1482 } | 1491 } |
| 1483 return current; | 1492 return current; |
| 1484 } | 1493 } |
| 1485 | 1494 |
| 1486 // ES5, 15.4.3.2 | 1495 // ES5, 15.4.3.2 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1572 )); | 1581 )); |
| 1573 | 1582 |
| 1574 SetUpLockedPrototype(InternalPackedArray, $Array(), $Array( | 1583 SetUpLockedPrototype(InternalPackedArray, $Array(), $Array( |
| 1575 "join", getFunction("join", ArrayJoin), | 1584 "join", getFunction("join", ArrayJoin), |
| 1576 "pop", getFunction("pop", ArrayPop), | 1585 "pop", getFunction("pop", ArrayPop), |
| 1577 "push", getFunction("push", ArrayPush) | 1586 "push", getFunction("push", ArrayPush) |
| 1578 )); | 1587 )); |
| 1579 } | 1588 } |
| 1580 | 1589 |
| 1581 SetUpArray(); | 1590 SetUpArray(); |
| OLD | NEW |