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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/harmony-typedarray.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/array.js
diff --git a/src/array.js b/src/array.js
index 573b729984b9450751d21bf1b9d6d958c512cb08..71f86c80f3a90518181c2bc0941ebeb7988a899d 100644
--- a/src/array.js
+++ b/src/array.js
@@ -12,6 +12,8 @@ var $arraySplice;
var $arrayUnshift;
var $innerArrayForEach;
var $innerArrayEvery;
+var $innerArrayIndexOf;
+var $innerArrayLastIndexOf;
var $innerArrayReverse;
var $innerArraySort;
@@ -1332,10 +1334,11 @@ function ArrayMap(f, receiver) {
}
-function ArrayIndexOf(element, index) {
- CHECK_OBJECT_COERCIBLE(this, "Array.prototype.indexOf");
-
- var length = TO_UINT32(this.length);
+// For .indexOf, we don't need to pass in the number of arguments
+// at the callsite since ToInteger(undefined) == 0; however, for
+// .lastIndexOf, we need to pass it, since the behavior for passing
+// undefined is 0 but for not including the argument is length-1.
+function InnerArrayIndexOf(element, index, length) {
if (length == 0) return -1;
if (IS_UNDEFINED(index)) {
index = 0;
@@ -1389,12 +1392,17 @@ function ArrayIndexOf(element, index) {
}
-function ArrayLastIndexOf(element, index) {
- CHECK_OBJECT_COERCIBLE(this, "Array.prototype.lastIndexOf");
+function ArrayIndexOf(element, index) {
+ CHECK_OBJECT_COERCIBLE(this, "Array.prototype.indexOf");
var length = TO_UINT32(this.length);
+ return %_CallFunction(this, element, index, length, InnerArrayIndexOf);
+}
+
+
+function InnerArrayLastIndexOf(element, index, length, argumentsLength) {
if (length == 0) return -1;
- if (%_ArgumentsLength() < 2) {
+ if (argumentsLength < 2) {
index = length - 1;
} else {
index = TO_INTEGER(index);
@@ -1442,6 +1450,15 @@ function ArrayLastIndexOf(element, index) {
}
+function ArrayLastIndexOf(element, index) {
+ CHECK_OBJECT_COERCIBLE(this, "Array.prototype.lastIndexOf");
+
+ var length = TO_UINT32(this.length);
+ return %_CallFunction(this, element, index, length,
+ %_ArgumentsLength(), InnerArrayLastIndexOf);
+}
+
+
function ArrayReduce(callback, current) {
CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduce");
@@ -1621,6 +1638,8 @@ $arrayUnshift = ArrayUnshift;
$innerArrayForEach = InnerArrayForEach;
$innerArrayEvery = InnerArrayEvery;
+$innerArrayIndexOf = InnerArrayIndexOf;
+$innerArrayLastIndexOf = InnerArrayLastIndexOf;
$innerArrayReverse = InnerArrayReverse;
$innerArraySort = InnerArraySort;
« 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