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

Side by Side Diff: src/array.js

Issue 1141763004: Implement %TypedArray%.{lastI,i}ndexOf (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; 13 var $innerArrayForEach;
14 var $innerArrayEvery; 14 var $innerArrayEvery;
15 var $innerArrayIndexOf;
16 var $innerArrayLastIndexOf;
15 var $innerArrayReverse; 17 var $innerArrayReverse;
16 var $innerArraySort; 18 var $innerArraySort;
17 19
18 (function(global, shared, exports) { 20 (function(global, shared, exports) {
19 21
20 "use strict"; 22 "use strict";
21 23
22 %CheckIsBootstrapping(); 24 %CheckIsBootstrapping();
23 25
24 // ------------------------------------------------------------------- 26 // -------------------------------------------------------------------
(...skipping 1300 matching lines...) Expand 10 before | Expand all | Expand 10 after
1325 if (stepping) %DebugPrepareStepInIfStepping(f); 1327 if (stepping) %DebugPrepareStepInIfStepping(f);
1326 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver; 1328 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver;
1327 accumulator[i] = %_CallFunction(new_receiver, element, i, array, f); 1329 accumulator[i] = %_CallFunction(new_receiver, element, i, array, f);
1328 } 1330 }
1329 } 1331 }
1330 %MoveArrayContents(accumulator, result); 1332 %MoveArrayContents(accumulator, result);
1331 return result; 1333 return result;
1332 } 1334 }
1333 1335
1334 1336
1335 function ArrayIndexOf(element, index) { 1337 // For .indexOf, we don't need to pass in the number of arguments
1336 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.indexOf"); 1338 // at the callsite since ToInteger(undefined) == 0; however, for
1337 1339 // .lastIndexOf, we need to pass it, since the behavior for passing
1338 var length = TO_UINT32(this.length); 1340 // undefined is 0 but for not including the argument is length-1.
1341 function InnerArrayIndexOf(element, index, length) {
1339 if (length == 0) return -1; 1342 if (length == 0) return -1;
1340 if (IS_UNDEFINED(index)) { 1343 if (IS_UNDEFINED(index)) {
1341 index = 0; 1344 index = 0;
1342 } else { 1345 } else {
1343 index = TO_INTEGER(index); 1346 index = TO_INTEGER(index);
1344 // If index is negative, index from the end of the array. 1347 // If index is negative, index from the end of the array.
1345 if (index < 0) { 1348 if (index < 0) {
1346 index = length + index; 1349 index = length + index;
1347 // If index is still negative, search the entire array. 1350 // If index is still negative, search the entire array.
1348 if (index < 0) index = 0; 1351 if (index < 0) index = 0;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 // Lookup through the array. 1385 // Lookup through the array.
1383 for (var i = min; i < max; i++) { 1386 for (var i = min; i < max; i++) {
1384 if (IS_UNDEFINED(this[i]) && i in this) { 1387 if (IS_UNDEFINED(this[i]) && i in this) {
1385 return i; 1388 return i;
1386 } 1389 }
1387 } 1390 }
1388 return -1; 1391 return -1;
1389 } 1392 }
1390 1393
1391 1394
1392 function ArrayLastIndexOf(element, index) { 1395 function ArrayIndexOf(element, index) {
1393 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.lastIndexOf"); 1396 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.indexOf");
1394 1397
1395 var length = TO_UINT32(this.length); 1398 var length = TO_UINT32(this.length);
1399 return %_CallFunction(this, element, index, length, InnerArrayIndexOf);
1400 }
1401
1402
1403 function InnerArrayLastIndexOf(element, index, length, argumentsLength) {
1396 if (length == 0) return -1; 1404 if (length == 0) return -1;
1397 if (%_ArgumentsLength() < 2) { 1405 if (argumentsLength < 2) {
1398 index = length - 1; 1406 index = length - 1;
1399 } else { 1407 } else {
1400 index = TO_INTEGER(index); 1408 index = TO_INTEGER(index);
1401 // If index is negative, index from end of the array. 1409 // If index is negative, index from end of the array.
1402 if (index < 0) index += length; 1410 if (index < 0) index += length;
1403 // If index is still negative, do not search the array. 1411 // If index is still negative, do not search the array.
1404 if (index < 0) return -1; 1412 if (index < 0) return -1;
1405 else if (index >= length) index = length - 1; 1413 else if (index >= length) index = length - 1;
1406 } 1414 }
1407 var min = 0; 1415 var min = 0;
(...skipping 27 matching lines...) Expand all
1435 } 1443 }
1436 for (var i = max; i >= min; i--) { 1444 for (var i = max; i >= min; i--) {
1437 if (IS_UNDEFINED(this[i]) && i in this) { 1445 if (IS_UNDEFINED(this[i]) && i in this) {
1438 return i; 1446 return i;
1439 } 1447 }
1440 } 1448 }
1441 return -1; 1449 return -1;
1442 } 1450 }
1443 1451
1444 1452
1453 function ArrayLastIndexOf(element, index) {
1454 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.lastIndexOf");
1455
1456 var length = TO_UINT32(this.length);
1457 return %_CallFunction(this, element, index, length,
1458 %_ArgumentsLength(), InnerArrayLastIndexOf);
1459 }
1460
1461
1445 function ArrayReduce(callback, current) { 1462 function ArrayReduce(callback, current) {
1446 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduce"); 1463 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduce");
1447 1464
1448 // Pull out the length so that modifications to the length in the 1465 // Pull out the length so that modifications to the length in the
1449 // loop will not affect the looping and side effects are visible. 1466 // loop will not affect the looping and side effects are visible.
1450 var array = $toObject(this); 1467 var array = $toObject(this);
1451 var length = $toUint32(array.length); 1468 var length = $toUint32(array.length);
1452 1469
1453 if (!IS_SPEC_FUNCTION(callback)) { 1470 if (!IS_SPEC_FUNCTION(callback)) {
1454 throw MakeTypeError(kCalledNonCallable, callback); 1471 throw MakeTypeError(kCalledNonCallable, callback);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1614 $arrayJoin = ArrayJoin; 1631 $arrayJoin = ArrayJoin;
1615 $arrayPush = ArrayPush; 1632 $arrayPush = ArrayPush;
1616 $arrayPop = ArrayPop; 1633 $arrayPop = ArrayPop;
1617 $arrayShift = ArrayShift; 1634 $arrayShift = ArrayShift;
1618 $arraySlice = ArraySlice; 1635 $arraySlice = ArraySlice;
1619 $arraySplice = ArraySplice; 1636 $arraySplice = ArraySplice;
1620 $arrayUnshift = ArrayUnshift; 1637 $arrayUnshift = ArrayUnshift;
1621 1638
1622 $innerArrayForEach = InnerArrayForEach; 1639 $innerArrayForEach = InnerArrayForEach;
1623 $innerArrayEvery = InnerArrayEvery; 1640 $innerArrayEvery = InnerArrayEvery;
1641 $innerArrayIndexOf = InnerArrayIndexOf;
1642 $innerArrayLastIndexOf = InnerArrayLastIndexOf;
1624 $innerArrayReverse = InnerArrayReverse; 1643 $innerArrayReverse = InnerArrayReverse;
1625 $innerArraySort = InnerArraySort; 1644 $innerArraySort = InnerArraySort;
1626 1645
1627 }); 1646 });
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