Bug 1078975 - %TypedArray%.prototype.{find, findIndex} Test. r=till
☠☠ backed out by 1e3f2dfbff62 ☠ ☠
authorziyunfei <446240525@qq.com>
Fri, 19 Dec 2014 16:51:41 +0100
changeset 220612 70d9f3f8aaf178c02bf1540a1fecdf78be7eb7ef
parent 220611 f078e3258ffd1e002ea444900fcda3d7655dcbdf
child 220613 5c191da183d62d1d52275537b200b1d6435d9165
push id10503
push userryanvm@gmail.com
push dateFri, 19 Dec 2014 20:13:42 +0000
treeherderfx-team@98ee95ac6be5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstill
bugs1078975
milestone37.0a1
Bug 1078975 - %TypedArray%.prototype.{find, findIndex} Test. r=till
js/src/tests/ecma_6/TypedArray/find-and-findIndex.js
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_6/TypedArray/find-and-findIndex.js
@@ -0,0 +1,70 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * https://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+var BUGNUMBER = 1078975;
+var summary = "Implement %TypedArray%.prototype.{find, findIndex}";
+print(BUGNUMBER + ": " + summary);
+
+const constructors = [
+  Int8Array,
+  Uint8Array,
+  Uint8ClampedArray,
+  Int16Array,
+  Uint16Array,
+  Int32Array,
+  Uint32Array,
+  Float32Array,
+  Float64Array
+];
+
+const methods = ["find", "findIndex"];
+
+constructors.forEach(constructor => {
+    methods.forEach(method => {
+        var arr = new constructor([0, 1, 2, 3, 4, 5]);
+        // test that this.length is never called
+        Object.defineProperty(arr, "length", {
+            get() {
+                throw new Error("length accessor called");
+            }
+        });
+        assertEq(arr[method].length, 1);
+        assertEq(arr[method](v => v === 3), 3);
+        assertEq(arr[method](v => v === 6), method === "find" ? undefined : -1);
+
+        var thisValues = [undefined, null, true, 1, "foo", [], {}];
+        if (typeof Symbol == "function")
+            thisValues.push(Symbol());
+
+        thisValues.forEach(thisArg =>
+            assertThrowsInstanceOf(() => arr[method].call(thisArg, () => true), TypeError)
+        );
+
+        assertThrowsInstanceOf(() => arr[method](), TypeError);
+        assertThrowsInstanceOf(() => arr[method](1), TypeError);
+
+        // ToDo neutering
+        arr = new constructor([1, 2, 3]);
+        assertEq(arr[method](v => v === 2), method === "find" ? 2 : 1);
+        neuter(arr.buffer, "change-data");
+        assertEq(arr[method](v => v === 2), method === "find" ? undefined : -1);
+    });
+});
+
+[Float32Array, Float64Array].forEach(constructor => {
+    var arr = new constructor([-0, 0, 1, 5, NaN, 6]);
+    assertEq(arr.find(v => Number.isNaN(v)), NaN);
+    assertEq(arr.findIndex(v => Number.isNaN(v)), 4);
+
+    assertEq(arr.find(v => Object.is(v, 0)), 0);
+    assertEq(arr.findIndex(v => Object.is(v, 0)), 1);
+
+    assertEq(arr.find(v => Object.is(v, -0)), -0);
+    assertEq(arr.findIndex(v => Object.is(v, -0)), 0);
+})
+
+
+if (typeof reportCompare === "function")
+    reportCompare(true, true);