Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(653)

Side by Side Diff: src/array.js

Issue 1133503003: Factor out core of Array.forEach and .every, for use in TypedArrays (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/harmony-typedarray.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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(global, shared, exports) { 16 (function(global, shared, exports) {
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
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) {
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); 1185 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
1192 var needs_wrapper = false; 1186 var needs_wrapper = false;
1193 if (IS_NULL(receiver)) { 1187 if (IS_NULL(receiver)) {
1194 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; 1188 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED;
1195 } else if (!IS_UNDEFINED(receiver)) { 1189 } else if (!IS_UNDEFINED(receiver)) {
1196 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); 1190 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver);
1197 } 1191 }
1198 1192
1199 var is_array = IS_ARRAY(array); 1193 var is_array = IS_ARRAY(array);
1200 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); 1194 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f);
1201 for (var i = 0; i < length; i++) { 1195 for (var i = 0; i < length; i++) {
1202 if (HAS_INDEX(array, i, is_array)) { 1196 if (HAS_INDEX(array, i, is_array)) {
1203 var element = array[i]; 1197 var element = array[i];
1204 // Prepare break slots for debugger step in. 1198 // Prepare break slots for debugger step in.
1205 if (stepping) %DebugPrepareStepInIfStepping(f); 1199 if (stepping) %DebugPrepareStepInIfStepping(f);
1206 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver; 1200 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver;
1207 %_CallFunction(new_receiver, element, i, array, f); 1201 %_CallFunction(new_receiver, element, i, array, f);
1208 } 1202 }
1209 } 1203 }
1210 } 1204 }
1211 1205
1206 function ArrayForEach(f, receiver) {
1207 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.forEach");
1208
1209 // Pull out the length so that modifications to the length in the
1210 // loop will not affect the looping and side effects are visible.
1211 var array = $toObject(this);
1212 var length = TO_UINT32(array.length);
1213 InnerArrayForEach(f, receiver, array, length);
1214 }
1215
1212 1216
1213 // Executes the function once for each element present in the 1217 // Executes the function once for each element present in the
1214 // array until it finds one where callback returns true. 1218 // array until it finds one where callback returns true.
1215 function ArraySome(f, receiver) { 1219 function ArraySome(f, receiver) {
1216 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.some"); 1220 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.some");
1217 1221
1218 // Pull out the length so that modifications to the length in the 1222 // Pull out the length so that modifications to the length in the
1219 // loop will not affect the looping and side effects are visible. 1223 // loop will not affect the looping and side effects are visible.
1220 var array = $toObject(this); 1224 var array = $toObject(this);
1221 var length = TO_UINT32(array.length); 1225 var length = TO_UINT32(array.length);
(...skipping 14 matching lines...) Expand all
1236 // Prepare break slots for debugger step in. 1240 // Prepare break slots for debugger step in.
1237 if (stepping) %DebugPrepareStepInIfStepping(f); 1241 if (stepping) %DebugPrepareStepInIfStepping(f);
1238 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver; 1242 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver;
1239 if (%_CallFunction(new_receiver, element, i, array, f)) return true; 1243 if (%_CallFunction(new_receiver, element, i, array, f)) return true;
1240 } 1244 }
1241 } 1245 }
1242 return false; 1246 return false;
1243 } 1247 }
1244 1248
1245 1249
1246 function ArrayEvery(f, receiver) { 1250 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); 1251 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
1255 var needs_wrapper = false; 1252 var needs_wrapper = false;
1256 if (IS_NULL(receiver)) { 1253 if (IS_NULL(receiver)) {
1257 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED; 1254 if (%IsSloppyModeFunction(f)) receiver = UNDEFINED;
1258 } else if (!IS_UNDEFINED(receiver)) { 1255 } else if (!IS_UNDEFINED(receiver)) {
1259 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); 1256 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver);
1260 } 1257 }
1261 1258
1262 var is_array = IS_ARRAY(array); 1259 var is_array = IS_ARRAY(array);
1263 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); 1260 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f);
1264 for (var i = 0; i < length; i++) { 1261 for (var i = 0; i < length; i++) {
1265 if (HAS_INDEX(array, i, is_array)) { 1262 if (HAS_INDEX(array, i, is_array)) {
1266 var element = array[i]; 1263 var element = array[i];
1267 // Prepare break slots for debugger step in. 1264 // Prepare break slots for debugger step in.
1268 if (stepping) %DebugPrepareStepInIfStepping(f); 1265 if (stepping) %DebugPrepareStepInIfStepping(f);
1269 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver; 1266 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver;
1270 if (!%_CallFunction(new_receiver, element, i, array, f)) return false; 1267 if (!%_CallFunction(new_receiver, element, i, array, f)) return false;
1271 } 1268 }
1272 } 1269 }
1273 return true; 1270 return true;
1274 } 1271 }
1275 1272
1273 function ArrayEvery(f, receiver) {
1274 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.every");
1275
1276 // Pull out the length so that modifications to the length in the
1277 // loop will not affect the looping and side effects are visible.
1278 var array = $toObject(this);
1279 var length = TO_UINT32(array.length);
1280 return InnerArrayEvery(f, receiver, array, length);
1281 }
1282
1276 1283
1277 function ArrayMap(f, receiver) { 1284 function ArrayMap(f, receiver) {
1278 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.map"); 1285 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.map");
1279 1286
1280 // Pull out the length so that modifications to the length in the 1287 // Pull out the length so that modifications to the length in the
1281 // loop will not affect the looping and side effects are visible. 1288 // loop will not affect the looping and side effects are visible.
1282 var array = $toObject(this); 1289 var array = $toObject(this);
1283 var length = TO_UINT32(array.length); 1290 var length = TO_UINT32(array.length);
1284 1291
1285 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); 1292 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
1588 1595
1589 $arrayConcat = ArrayConcatJS; 1596 $arrayConcat = ArrayConcatJS;
1590 $arrayJoin = ArrayJoin; 1597 $arrayJoin = ArrayJoin;
1591 $arrayPush = ArrayPush; 1598 $arrayPush = ArrayPush;
1592 $arrayPop = ArrayPop; 1599 $arrayPop = ArrayPop;
1593 $arrayShift = ArrayShift; 1600 $arrayShift = ArrayShift;
1594 $arraySlice = ArraySlice; 1601 $arraySlice = ArraySlice;
1595 $arraySplice = ArraySplice; 1602 $arraySplice = ArraySplice;
1596 $arrayUnshift = ArrayUnshift; 1603 $arrayUnshift = ArrayUnshift;
1597 1604
1598 }) 1605 $innerArrayForEach = InnerArrayForEach;
1606 $innerArrayEvery = InnerArrayEvery;
1607
1608 });
OLDNEW
« no previous file with comments | « no previous file | src/harmony-typedarray.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698