Chromium Code Reviews| 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; |
| 11 var $arraySplice; | 11 var $arraySplice; |
| 12 var $arrayUnshift; | 12 var $arrayUnshift; |
| 13 var $innerArrayForEach; | |
| 14 var $innerArrayEvery; | |
| 13 | 15 |
| 14 (function() { | 16 (function() { |
| 15 | 17 |
| 16 "use strict"; | 18 "use strict"; |
| 17 | 19 |
| 18 %CheckIsBootstrapping(); | 20 %CheckIsBootstrapping(); |
| 19 | 21 |
| 20 var GlobalArray = global.Array; | 22 var GlobalArray = global.Array; |
| 21 | 23 |
| 22 // ------------------------------------------------------------------- | 24 // ------------------------------------------------------------------- |
| (...skipping 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1172 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver; | 1174 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver; |
| 1173 if (%_CallFunction(new_receiver, element, i, array, f)) { | 1175 if (%_CallFunction(new_receiver, element, i, array, f)) { |
| 1174 accumulator[accumulator_length++] = element; | 1176 accumulator[accumulator_length++] = element; |
| 1175 } | 1177 } |
| 1176 } | 1178 } |
| 1177 } | 1179 } |
| 1178 %MoveArrayContents(accumulator, result); | 1180 %MoveArrayContents(accumulator, result); |
| 1179 return result; | 1181 return result; |
| 1180 } | 1182 } |
| 1181 | 1183 |
| 1182 | 1184 function InnerArrayForEach(f, receiver, array, length) |
| 1183 function ArrayForEach(f, receiver) { | 1185 { |
|
adamk
2015/05/11 22:39:24
I'll re-iterate arv's style nit, please put this o
| |
| 1184 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.forEach"); | |
| 1185 | |
| 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. | |
| 1188 var array = $toObject(this); | |
| 1189 var length = TO_UINT32(array.length); | |
| 1190 | |
| 1191 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); | 1186 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); |
| 1192 var needs_wrapper = false; | 1187 var needs_wrapper = false; |
| 1193 if (IS_NULL(receiver)) { | 1188 if (IS_NULL(receiver)) { |
| 1194 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; | 1189 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; |
| 1195 } else if (!IS_UNDEFINED(receiver)) { | 1190 } else if (!IS_UNDEFINED(receiver)) { |
| 1196 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | 1191 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
| 1197 } | 1192 } |
| 1198 | 1193 |
| 1199 var is_array = IS_ARRAY(array); | 1194 var is_array = IS_ARRAY(array); |
| 1200 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1195 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
| 1201 for (var i = 0; i < length; i++) { | 1196 for (var i = 0; i < length; i++) { |
| 1202 if (HAS_INDEX(array, i, is_array)) { | 1197 if (HAS_INDEX(array, i, is_array)) { |
| 1203 var element = array[i]; | 1198 var element = array[i]; |
| 1204 // Prepare break slots for debugger step in. | 1199 // Prepare break slots for debugger step in. |
| 1205 if (stepping) %DebugPrepareStepInIfStepping(f); | 1200 if (stepping) %DebugPrepareStepInIfStepping(f); |
| 1206 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver; | 1201 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver; |
| 1207 %_CallFunction(new_receiver, element, i, array, f); | 1202 %_CallFunction(new_receiver, element, i, array, f); |
| 1208 } | 1203 } |
| 1209 } | 1204 } |
| 1210 } | 1205 } |
| 1211 | 1206 |
| 1207 function ArrayForEach(f, receiver) { | |
| 1208 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.forEach"); | |
| 1209 | |
| 1210 // Pull out the length so that modifications to the length in the | |
| 1211 // loop will not affect the looping and side effects are visible. | |
| 1212 var array = $toObject(this); | |
| 1213 var length = TO_UINT32(array.length); | |
| 1214 InnerArrayForEach(f, receiver, array, length); | |
| 1215 } | |
| 1216 | |
| 1212 | 1217 |
| 1213 // Executes the function once for each element present in the | 1218 // Executes the function once for each element present in the |
| 1214 // array until it finds one where callback returns true. | 1219 // array until it finds one where callback returns true. |
| 1215 function ArraySome(f, receiver) { | 1220 function ArraySome(f, receiver) { |
| 1216 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.some"); | 1221 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.some"); |
| 1217 | 1222 |
| 1218 // Pull out the length so that modifications to the length in the | 1223 // Pull out the length so that modifications to the length in the |
| 1219 // loop will not affect the looping and side effects are visible. | 1224 // loop will not affect the looping and side effects are visible. |
| 1220 var array = $toObject(this); | 1225 var array = $toObject(this); |
| 1221 var length = TO_UINT32(array.length); | 1226 var length = TO_UINT32(array.length); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1236 // Prepare break slots for debugger step in. | 1241 // Prepare break slots for debugger step in. |
| 1237 if (stepping) %DebugPrepareStepInIfStepping(f); | 1242 if (stepping) %DebugPrepareStepInIfStepping(f); |
| 1238 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver; | 1243 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver; |
| 1239 if (%_CallFunction(new_receiver, element, i, array, f)) return true; | 1244 if (%_CallFunction(new_receiver, element, i, array, f)) return true; |
| 1240 } | 1245 } |
| 1241 } | 1246 } |
| 1242 return false; | 1247 return false; |
| 1243 } | 1248 } |
| 1244 | 1249 |
| 1245 | 1250 |
| 1246 function ArrayEvery(f, receiver) { | 1251 function InnerArrayEvery(f, receiver, array, length) { |
| 1247 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.every"); | |
| 1248 | |
| 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. | |
| 1251 var array = $toObject(this); | |
| 1252 var length = TO_UINT32(array.length); | |
| 1253 | |
| 1254 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); | 1252 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); |
| 1255 var needs_wrapper = false; | 1253 var needs_wrapper = false; |
| 1256 if (IS_NULL(receiver)) { | 1254 if (IS_NULL(receiver)) { |
| 1257 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; | 1255 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; |
| 1258 } else if (!IS_UNDEFINED(receiver)) { | 1256 } else if (!IS_UNDEFINED(receiver)) { |
| 1259 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | 1257 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
| 1260 } | 1258 } |
| 1261 | 1259 |
| 1262 var is_array = IS_ARRAY(array); | 1260 var is_array = IS_ARRAY(array); |
| 1263 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 1261 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
| 1264 for (var i = 0; i < length; i++) { | 1262 for (var i = 0; i < length; i++) { |
| 1265 if (HAS_INDEX(array, i, is_array)) { | 1263 if (HAS_INDEX(array, i, is_array)) { |
| 1266 var element = array[i]; | 1264 var element = array[i]; |
| 1267 // Prepare break slots for debugger step in. | 1265 // Prepare break slots for debugger step in. |
| 1268 if (stepping) %DebugPrepareStepInIfStepping(f); | 1266 if (stepping) %DebugPrepareStepInIfStepping(f); |
| 1269 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver; | 1267 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver; |
| 1270 if (!%_CallFunction(new_receiver, element, i, array, f)) return false; | 1268 if (!%_CallFunction(new_receiver, element, i, array, f)) return false; |
| 1271 } | 1269 } |
| 1272 } | 1270 } |
| 1273 return true; | 1271 return true; |
| 1274 } | 1272 } |
| 1275 | 1273 |
| 1274 function ArrayEvery(f, receiver) { | |
| 1275 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.every"); | |
| 1276 | |
| 1277 // Pull out the length so that modifications to the length in the | |
| 1278 // loop will not affect the looping and side effects are visible. | |
| 1279 var array = $toObject(this); | |
| 1280 var length = TO_UINT32(array.length); | |
| 1281 return InnerArrayEvery(f, receiver, array, length); | |
| 1282 } | |
| 1283 | |
| 1276 | 1284 |
| 1277 function ArrayMap(f, receiver) { | 1285 function ArrayMap(f, receiver) { |
| 1278 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.map"); | 1286 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.map"); |
| 1279 | 1287 |
| 1280 // 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 |
| 1281 // loop will not affect the looping and side effects are visible. | 1289 // loop will not affect the looping and side effects are visible. |
| 1282 var array = $toObject(this); | 1290 var array = $toObject(this); |
| 1283 var length = TO_UINT32(array.length); | 1291 var length = TO_UINT32(array.length); |
| 1284 | 1292 |
| 1285 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); | 1293 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1588 | 1596 |
| 1589 $arrayConcat = ArrayConcatJS; | 1597 $arrayConcat = ArrayConcatJS; |
| 1590 $arrayJoin = ArrayJoin; | 1598 $arrayJoin = ArrayJoin; |
| 1591 $arrayPush = ArrayPush; | 1599 $arrayPush = ArrayPush; |
| 1592 $arrayPop = ArrayPop; | 1600 $arrayPop = ArrayPop; |
| 1593 $arrayShift = ArrayShift; | 1601 $arrayShift = ArrayShift; |
| 1594 $arraySlice = ArraySlice; | 1602 $arraySlice = ArraySlice; |
| 1595 $arraySplice = ArraySplice; | 1603 $arraySplice = ArraySplice; |
| 1596 $arrayUnshift = ArrayUnshift; | 1604 $arrayUnshift = ArrayUnshift; |
| 1597 | 1605 |
| 1606 $innerArrayForEach = InnerArrayForEach; | |
| 1607 $innerArrayEvery = InnerArrayEvery; | |
| 1608 | |
| 1598 })(); | 1609 })(); |
| OLD | NEW |