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

Side by Side Diff: src/array.js

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

Powered by Google App Engine
This is Rietveld 408576698