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

Unified Diff: src/harmony-typedarray.js

Issue 728973005: Implement .indexOf() and .lastIndexOf() on typed arrays Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 years, 1 month 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 | test/mjsunit/harmony/typedarrays-indexof.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/harmony-typedarray.js
diff --git a/src/harmony-typedarray.js b/src/harmony-typedarray.js
index 014206c4cba8400cf745b9295d5cb223695ad6cb..0d02615428f60ac99f700b6f9539a9ae16e8d0f6 100644
--- a/src/harmony-typedarray.js
+++ b/src/harmony-typedarray.js
@@ -59,6 +59,59 @@ function NAMEForEach(f /* thisArg */) { // length == 1
}
}
+// ES6 draft 11-14-14, section 22.2.3.13
+function NAMEIndexOf(element /* fromIndex */) { // length == 1
+ if (!%IsTypedArray(this)) {
+ throw MakeTypeError('not_typed_array', []);
+ }
+
+ // Typed arrays cannot contain undefined elements.
+ if (IS_UNDEFINED(element)) {
+ return -1;
+ }
+
+ var length = %_TypedArrayGetLength(this);
+ if (length == 0) return -1;
+
+ var n = (%_ArgumentsLength() > 1) ? ToInteger(%_Arguments(1)) : 0;
+ if (n < 0) {
+ n += length;
+ if (n < 0) n = 0;
+ }
+
+ for (; n < length; n++) {
+ if (this[n] === element) return n;
+ }
+ return -1;
+}
+
+// ES6 draft 11-14-14, section 22.2.3.16
+function NAMELastIndexOf(element /* fromIndex */){ // length == 1
+ if (!%IsTypedArray(this)) {
+ throw MakeTypeError('not_typed_array', []);
+ }
+
+ // Typed arrays cannot contain undefined elements.
+ if (IS_UNDEFINED(element)) {
+ return -1;
+ }
+
+ var length = %_TypedArrayGetLength(this);
+ if (length == 0) return -1;
+
+ var n = (%_ArgumentsLength() > 1) ? ToInteger(%_Arguments(1)) : length - 1;
+ if (n < 0) {
+ n += length;
+ } else if (n >= length) {
+ n = length - 1;
+ }
+
+ for (; n >= 0; n--) {
+ if (this[n] === element) return n;
+ }
+ return -1;
+}
+
// ES6 draft 08-24-14, section 22.2.2.2
function NAMEOf() { // length == 0
var length = %_ArgumentsLength();
@@ -84,8 +137,10 @@ macro EXTEND_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE)
));
// Set up non-enumerable functions on the prototype object.
- InstallFunctions(global.NAME.prototype, DONT_ENUM, $Array(
- "forEach", NAMEForEach
+ InstallFunctions(global.NAME.prototype, DONT_ENUM | DONT_DELETE | READ_ONLY, $Array(
+ "forEach", NAMEForEach,
+ "indexOf", NAMEIndexOf,
+ "lastIndexOf", NAMELastIndexOf
));
endmacro
« no previous file with comments | « no previous file | test/mjsunit/harmony/typedarrays-indexof.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698