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

Unified Diff: test/mjsunit/harmony/typedarray-indexing.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 | « src/harmony-typedarray.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/harmony/typedarray-indexing.js
diff --git a/test/mjsunit/harmony/typedarray-indexing.js b/test/mjsunit/harmony/typedarray-indexing.js
new file mode 100644
index 0000000000000000000000000000000000000000..bb4895fb5dd6dde763a9984e8326c4bb4291fc36
--- /dev/null
+++ b/test/mjsunit/harmony/typedarray-indexing.js
@@ -0,0 +1,73 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --harmony-arrays
+
+var typedArrayConstructors = [
+ Uint8Array,
+ Int8Array,
+ Uint16Array,
+ Int16Array,
+ Uint32Array,
+ Int32Array,
+ Uint8ClampedArray,
+ Float32Array,
+ Float64Array
+];
+
+for (var constructor of typedArrayConstructors) {
+ var array = new constructor([1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]);
+
+ // ----------------------------------------------------------------------
+ // %TypedArray%.prototype.indexOf.
+ // ----------------------------------------------------------------------
+
+ // Negative cases.
+ assertEquals(-1, new constructor([]).indexOf(1));
+ assertEquals(-1, array.indexOf(4));
+ assertEquals(-1, array.indexOf(3, array.length));
+
+ assertEquals(2, array.indexOf(3));
+ // Negative index out of range.
+ assertEquals(0, array.indexOf(1, -17));
+ // Negative index in rage.
+ assertEquals(3, array.indexOf(1, -11));
+ // Index in range.
+ assertEquals(3, array.indexOf(1, 1));
+ assertEquals(3, array.indexOf(1, 3));
+ assertEquals(6, array.indexOf(1, 4));
+
+ // Basic TypedArray function properties
+ assertEquals(1, array.indexOf.length);
+ assertThrows(function(){ array.indexOf.call([1], 1); }, TypeError);
+ Object.defineProperty(array, 'length', {value: 1});
+ assertEquals(array.indexOf(2), 1);
+
+
+ // ----------------------------------------------------------------------
+ // %TypedArray%.prototype.lastIndexOf.
+ // ----------------------------------------------------------------------
+ array = new constructor([1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]);
+
+ // Negative cases.
+ assertEquals(-1, new constructor([]).lastIndexOf(1));
+ assertEquals(-1, array.lastIndexOf(1, -17));
+
+ assertEquals(9, array.lastIndexOf(1));
+ // Index out of range.
+ assertEquals(9, array.lastIndexOf(1, array.length));
+ // Index in range.
+ assertEquals(0, array.lastIndexOf(1, 2));
+ assertEquals(3, array.lastIndexOf(1, 4));
+ assertEquals(3, array.lastIndexOf(1, 3));
+ // Negative index in range.
+ assertEquals(0, array.lastIndexOf(1, -11));
+
+ // Basic TypedArray function properties
+ assertEquals(1, array.lastIndexOf.length);
+ assertThrows(function(){ array.lastIndexOf.call([1], 1); }, TypeError);
+ Object.defineProperty(array, 'length', {value: 1});
+ assertEquals(array.lastIndexOf(2), 10);
+ delete array.length;
+}
« no previous file with comments | « src/harmony-typedarray.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698