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

Side by Side Diff: src/array.js

Issue 1083083004: Reland "Migrate error messages, part 2." (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix for layout test Created 5 years, 8 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/array-iterator.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 "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 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 // preserving the semantics, since the calls to the receiver function can add 1135 // preserving the semantics, since the calls to the receiver function can add
1136 // or delete elements from the array. 1136 // or delete elements from the array.
1137 function ArrayFilter(f, receiver) { 1137 function ArrayFilter(f, receiver) {
1138 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.filter"); 1138 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.filter");
1139 1139
1140 // Pull out the length so that modifications to the length in the 1140 // Pull out the length so that modifications to the length in the
1141 // loop will not affect the looping and side effects are visible. 1141 // loop will not affect the looping and side effects are visible.
1142 var array = ToObject(this); 1142 var array = ToObject(this);
1143 var length = ToUint32(array.length); 1143 var length = ToUint32(array.length);
1144 1144
1145 if (!IS_SPEC_FUNCTION(f)) { 1145 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
1146 throw MakeTypeError('called_non_callable', [ f ]);
1147 }
1148 var needs_wrapper = false; 1146 var needs_wrapper = false;
1149 if (IS_NULL_OR_UNDEFINED(receiver)) { 1147 if (IS_NULL_OR_UNDEFINED(receiver)) {
1150 receiver = %GetDefaultReceiver(f) || receiver; 1148 receiver = %GetDefaultReceiver(f) || receiver;
1151 } else { 1149 } else {
1152 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); 1150 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver);
1153 } 1151 }
1154 1152
1155 var result = new $Array(); 1153 var result = new $Array();
1156 var accumulator = new InternalArray(); 1154 var accumulator = new InternalArray();
1157 var accumulator_length = 0; 1155 var accumulator_length = 0;
(...skipping 16 matching lines...) Expand all
1174 1172
1175 1173
1176 function ArrayForEach(f, receiver) { 1174 function ArrayForEach(f, receiver) {
1177 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.forEach"); 1175 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.forEach");
1178 1176
1179 // Pull out the length so that modifications to the length in the 1177 // Pull out the length so that modifications to the length in the
1180 // loop will not affect the looping and side effects are visible. 1178 // loop will not affect the looping and side effects are visible.
1181 var array = ToObject(this); 1179 var array = ToObject(this);
1182 var length = TO_UINT32(array.length); 1180 var length = TO_UINT32(array.length);
1183 1181
1184 if (!IS_SPEC_FUNCTION(f)) { 1182 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
1185 throw MakeTypeError('called_non_callable', [ f ]);
1186 }
1187 var needs_wrapper = false; 1183 var needs_wrapper = false;
1188 if (IS_NULL_OR_UNDEFINED(receiver)) { 1184 if (IS_NULL_OR_UNDEFINED(receiver)) {
1189 receiver = %GetDefaultReceiver(f) || receiver; 1185 receiver = %GetDefaultReceiver(f) || receiver;
1190 } else { 1186 } else {
1191 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); 1187 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver);
1192 } 1188 }
1193 1189
1194 var is_array = IS_ARRAY(array); 1190 var is_array = IS_ARRAY(array);
1195 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); 1191 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f);
1196 for (var i = 0; i < length; i++) { 1192 for (var i = 0; i < length; i++) {
(...skipping 11 matching lines...) Expand all
1208 // Executes the function once for each element present in the 1204 // Executes the function once for each element present in the
1209 // array until it finds one where callback returns true. 1205 // array until it finds one where callback returns true.
1210 function ArraySome(f, receiver) { 1206 function ArraySome(f, receiver) {
1211 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.some"); 1207 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.some");
1212 1208
1213 // Pull out the length so that modifications to the length in the 1209 // Pull out the length so that modifications to the length in the
1214 // loop will not affect the looping and side effects are visible. 1210 // loop will not affect the looping and side effects are visible.
1215 var array = ToObject(this); 1211 var array = ToObject(this);
1216 var length = TO_UINT32(array.length); 1212 var length = TO_UINT32(array.length);
1217 1213
1218 if (!IS_SPEC_FUNCTION(f)) { 1214 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
1219 throw MakeTypeError('called_non_callable', [ f ]);
1220 }
1221 var needs_wrapper = false; 1215 var needs_wrapper = false;
1222 if (IS_NULL_OR_UNDEFINED(receiver)) { 1216 if (IS_NULL_OR_UNDEFINED(receiver)) {
1223 receiver = %GetDefaultReceiver(f) || receiver; 1217 receiver = %GetDefaultReceiver(f) || receiver;
1224 } else { 1218 } else {
1225 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); 1219 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver);
1226 } 1220 }
1227 1221
1228 var is_array = IS_ARRAY(array); 1222 var is_array = IS_ARRAY(array);
1229 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); 1223 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f);
1230 for (var i = 0; i < length; i++) { 1224 for (var i = 0; i < length; i++) {
(...skipping 10 matching lines...) Expand all
1241 1235
1242 1236
1243 function ArrayEvery(f, receiver) { 1237 function ArrayEvery(f, receiver) {
1244 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.every"); 1238 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.every");
1245 1239
1246 // Pull out the length so that modifications to the length in the 1240 // Pull out the length so that modifications to the length in the
1247 // loop will not affect the looping and side effects are visible. 1241 // loop will not affect the looping and side effects are visible.
1248 var array = ToObject(this); 1242 var array = ToObject(this);
1249 var length = TO_UINT32(array.length); 1243 var length = TO_UINT32(array.length);
1250 1244
1251 if (!IS_SPEC_FUNCTION(f)) { 1245 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
1252 throw MakeTypeError('called_non_callable', [ f ]);
1253 }
1254 var needs_wrapper = false; 1246 var needs_wrapper = false;
1255 if (IS_NULL_OR_UNDEFINED(receiver)) { 1247 if (IS_NULL_OR_UNDEFINED(receiver)) {
1256 receiver = %GetDefaultReceiver(f) || receiver; 1248 receiver = %GetDefaultReceiver(f) || receiver;
1257 } else { 1249 } else {
1258 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); 1250 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver);
1259 } 1251 }
1260 1252
1261 var is_array = IS_ARRAY(array); 1253 var is_array = IS_ARRAY(array);
1262 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); 1254 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f);
1263 for (var i = 0; i < length; i++) { 1255 for (var i = 0; i < length; i++) {
1264 if (HAS_INDEX(array, i, is_array)) { 1256 if (HAS_INDEX(array, i, is_array)) {
1265 var element = array[i]; 1257 var element = array[i];
1266 // Prepare break slots for debugger step in. 1258 // Prepare break slots for debugger step in.
1267 if (stepping) %DebugPrepareStepInIfStepping(f); 1259 if (stepping) %DebugPrepareStepInIfStepping(f);
1268 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; 1260 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver;
1269 if (!%_CallFunction(new_receiver, element, i, array, f)) return false; 1261 if (!%_CallFunction(new_receiver, element, i, array, f)) return false;
1270 } 1262 }
1271 } 1263 }
1272 return true; 1264 return true;
1273 } 1265 }
1274 1266
1275 function ArrayMap(f, receiver) { 1267 function ArrayMap(f, receiver) {
1276 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.map"); 1268 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.map");
1277 1269
1278 // Pull out the length so that modifications to the length in the 1270 // Pull out the length so that modifications to the length in the
1279 // loop will not affect the looping and side effects are visible. 1271 // loop will not affect the looping and side effects are visible.
1280 var array = ToObject(this); 1272 var array = ToObject(this);
1281 var length = TO_UINT32(array.length); 1273 var length = TO_UINT32(array.length);
1282 1274
1283 if (!IS_SPEC_FUNCTION(f)) { 1275 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
1284 throw MakeTypeError('called_non_callable', [ f ]);
1285 }
1286 var needs_wrapper = false; 1276 var needs_wrapper = false;
1287 if (IS_NULL_OR_UNDEFINED(receiver)) { 1277 if (IS_NULL_OR_UNDEFINED(receiver)) {
1288 receiver = %GetDefaultReceiver(f) || receiver; 1278 receiver = %GetDefaultReceiver(f) || receiver;
1289 } else { 1279 } else {
1290 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); 1280 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver);
1291 } 1281 }
1292 1282
1293 var result = new $Array(); 1283 var result = new $Array();
1294 var accumulator = new InternalArray(length); 1284 var accumulator = new InternalArray(length);
1295 var is_array = IS_ARRAY(array); 1285 var is_array = IS_ARRAY(array);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1420 1410
1421 function ArrayReduce(callback, current) { 1411 function ArrayReduce(callback, current) {
1422 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduce"); 1412 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduce");
1423 1413
1424 // Pull out the length so that modifications to the length in the 1414 // Pull out the length so that modifications to the length in the
1425 // loop will not affect the looping and side effects are visible. 1415 // loop will not affect the looping and side effects are visible.
1426 var array = ToObject(this); 1416 var array = ToObject(this);
1427 var length = ToUint32(array.length); 1417 var length = ToUint32(array.length);
1428 1418
1429 if (!IS_SPEC_FUNCTION(callback)) { 1419 if (!IS_SPEC_FUNCTION(callback)) {
1430 throw MakeTypeError('called_non_callable', [callback]); 1420 throw MakeTypeError(kCalledNonCallable, callback);
1431 } 1421 }
1432 1422
1433 var is_array = IS_ARRAY(array); 1423 var is_array = IS_ARRAY(array);
1434 var i = 0; 1424 var i = 0;
1435 find_initial: if (%_ArgumentsLength() < 2) { 1425 find_initial: if (%_ArgumentsLength() < 2) {
1436 for (; i < length; i++) { 1426 for (; i < length; i++) {
1437 if (HAS_INDEX(array, i, is_array)) { 1427 if (HAS_INDEX(array, i, is_array)) {
1438 current = array[i++]; 1428 current = array[i++];
1439 break find_initial; 1429 break find_initial;
1440 } 1430 }
(...skipping 16 matching lines...) Expand all
1457 1447
1458 function ArrayReduceRight(callback, current) { 1448 function ArrayReduceRight(callback, current) {
1459 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduceRight"); 1449 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduceRight");
1460 1450
1461 // Pull out the length so that side effects are visible before the 1451 // Pull out the length so that side effects are visible before the
1462 // callback function is checked. 1452 // callback function is checked.
1463 var array = ToObject(this); 1453 var array = ToObject(this);
1464 var length = ToUint32(array.length); 1454 var length = ToUint32(array.length);
1465 1455
1466 if (!IS_SPEC_FUNCTION(callback)) { 1456 if (!IS_SPEC_FUNCTION(callback)) {
1467 throw MakeTypeError('called_non_callable', [callback]); 1457 throw MakeTypeError(kCalledNonCallable, callback);
1468 } 1458 }
1469 1459
1470 var is_array = IS_ARRAY(array); 1460 var is_array = IS_ARRAY(array);
1471 var i = length - 1; 1461 var i = length - 1;
1472 find_initial: if (%_ArgumentsLength() < 2) { 1462 find_initial: if (%_ArgumentsLength() < 2) {
1473 for (; i >= 0; i--) { 1463 for (; i >= 0; i--) {
1474 if (HAS_INDEX(array, i, is_array)) { 1464 if (HAS_INDEX(array, i, is_array)) {
1475 current = array[i--]; 1465 current = array[i--];
1476 break find_initial; 1466 break find_initial;
1477 } 1467 }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1581 ]); 1571 ]);
1582 1572
1583 SetUpLockedPrototype(InternalPackedArray, $Array(), [ 1573 SetUpLockedPrototype(InternalPackedArray, $Array(), [
1584 "join", getFunction("join", ArrayJoin), 1574 "join", getFunction("join", ArrayJoin),
1585 "pop", getFunction("pop", ArrayPop), 1575 "pop", getFunction("pop", ArrayPop),
1586 "push", getFunction("push", ArrayPush) 1576 "push", getFunction("push", ArrayPush)
1587 ]); 1577 ]);
1588 } 1578 }
1589 1579
1590 SetUpArray(); 1580 SetUpArray();
OLDNEW
« no previous file with comments | « no previous file | src/array-iterator.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698