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

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: minor style fix 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') | src/harmony-typedarray.js » ('J')
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 93378cfb00b1b14c0150e5b179c6de5f6a8852a2..10f4625c162d839b3fea80bbd5b5e57525346450 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;
(function(global, shared, exports) {
@@ -1320,10 +1322,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;
@@ -1377,12 +1380,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);
@@ -1430,6 +1438,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");
@@ -1609,5 +1626,7 @@ $arrayUnshift = ArrayUnshift;
$innerArrayForEach = InnerArrayForEach;
$innerArrayEvery = InnerArrayEvery;
+$innerArrayIndexOf = InnerArrayIndexOf;
+$innerArrayLastIndexOf = InnerArrayLastIndexOf;
});
« no previous file with comments | « no previous file | src/harmony-typedarray.js » ('j') | src/harmony-typedarray.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698