summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Array/prototype/findIndex
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /js/src/tests/test262/built-ins/Array/prototype/findIndex
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Array/prototype/findIndex')
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/findIndex/array-altered-during-loop.js49
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/findIndex/browser.js0
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/findIndex/call-with-boolean.js20
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/findIndex/callbackfn-resize-arraybuffer.js76
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/findIndex/length.js20
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/findIndex/name.js24
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/findIndex/not-a-constructor.js35
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/findIndex/predicate-call-parameters.js47
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/findIndex/predicate-call-this-non-strict.js34
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/findIndex/predicate-call-this-strict-strict.js35
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/findIndex/predicate-called-for-each-array-property.js28
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/findIndex/predicate-is-not-callable-throws.js51
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/findIndex/predicate-not-called-on-empty-array.js37
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/findIndex/prop-desc.js21
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/findIndex/return-abrupt-from-predicate-call.js27
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/findIndex/return-abrupt-from-property.js33
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/findIndex/return-abrupt-from-this-length-as-symbol.js27
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/findIndex/return-abrupt-from-this-length.js40
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/findIndex/return-abrupt-from-this.js23
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/findIndex/return-index-predicate-result-is-true.js65
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/findIndex/return-negative-one-if-predicate-returns-false-value.js55
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/findIndex/shell.js161
22 files changed, 908 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Array/prototype/findIndex/array-altered-during-loop.js b/js/src/tests/test262/built-ins/Array/prototype/findIndex/array-altered-during-loop.js
new file mode 100644
index 0000000000..0a51a82754
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/findIndex/array-altered-during-loop.js
@@ -0,0 +1,49 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-array.prototype.findindex
+description: >
+ The range of elements processed is set before the first call to `predicate`.
+info: |
+ 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] )
+
+ ...
+ 6. If thisArg was supplied, let T be thisArg; else let T be undefined.
+ 7. Let k be 0.
+ 8. Repeat, while k < len
+ ...
+ d. Let testResult be ToBoolean(Call(predicate, T, «kValue, k, O»)).
+ ...
+---*/
+
+var arr = ['Shoes', 'Car', 'Bike'];
+var results = [];
+
+arr.findIndex(function(kValue) {
+ if (results.length === 0) {
+ arr.splice(1, 1);
+ }
+ results.push(kValue);
+});
+
+assert.sameValue(results.length, 3, 'predicate called three times');
+assert.sameValue(results[0], 'Shoes');
+assert.sameValue(results[1], 'Bike');
+assert.sameValue(results[2], undefined);
+
+results = [];
+arr = ['Skateboard', 'Barefoot'];
+arr.findIndex(function(kValue) {
+ if (results.length === 0) {
+ arr.push('Motorcycle');
+ arr[1] = 'Magic Carpet';
+ }
+
+ results.push(kValue);
+});
+
+assert.sameValue(results.length, 2, 'predicate called twice');
+assert.sameValue(results[0], 'Skateboard');
+assert.sameValue(results[1], 'Magic Carpet');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/findIndex/browser.js b/js/src/tests/test262/built-ins/Array/prototype/findIndex/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/findIndex/browser.js
diff --git a/js/src/tests/test262/built-ins/Array/prototype/findIndex/call-with-boolean.js b/js/src/tests/test262/built-ins/Array/prototype/findIndex/call-with-boolean.js
new file mode 100644
index 0000000000..fe775ec2f4
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/findIndex/call-with-boolean.js
@@ -0,0 +1,20 @@
+// Copyright (c) 2020 Rick Waldron. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-array.prototype.findIndex
+description: Array.prototype.findIndex applied to boolean primitive
+---*/
+
+assert.sameValue(
+ Array.prototype.findIndex.call(true, () => {}),
+ -1,
+ 'Array.prototype.findIndex.call(true, () => {}) must return -1'
+);
+assert.sameValue(
+ Array.prototype.findIndex.call(false, () => {}),
+ -1,
+ 'Array.prototype.findIndex.call(false, () => {}) must return -1'
+);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/findIndex/callbackfn-resize-arraybuffer.js b/js/src/tests/test262/built-ins/Array/prototype/findIndex/callbackfn-resize-arraybuffer.js
new file mode 100644
index 0000000000..dbd5c88d63
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/findIndex/callbackfn-resize-arraybuffer.js
@@ -0,0 +1,76 @@
+// |reftest| shell-option(--enable-arraybuffer-resizable) skip-if(!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- resizable-arraybuffer is not enabled unconditionally, requires shell-options
+// Copyright (C) 2021 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-array.prototype.findindex
+description: TypedArray instance buffer can be resized during iteration
+includes: [testTypedArray.js, compareArray.js]
+features: [TypedArray, resizable-arraybuffer]
+---*/
+
+// If the host chooses to throw as allowed by the specification, the observed
+// behavior will be identical to the case where `ArrayBuffer.prototype.resize`
+// has not been implemented. The following assertion prevents this test from
+// passing in runtimes which have not implemented the method.
+assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function');
+
+testWithTypedArrayConstructors(function(TA) {
+ var BPE = TA.BYTES_PER_ELEMENT;
+ var buffer = new ArrayBuffer(BPE * 3, {maxByteLength: BPE * 4});
+ var sample = new TA(buffer);
+ var finalElement, expectedElements, expectedIndices, expectedArrays;
+ var elements, indices, arrays, result;
+
+ elements = [];
+ indices = [];
+ arrays = [];
+ result = Array.prototype.findIndex.call(sample, function(element, index, array) {
+ if (elements.length === 0) {
+ try {
+ buffer.resize(2 * BPE);
+ finalElement = undefined;
+ expectedElements = [0, 0];
+ expectedIndices = [0, 1];
+ expectedArrays = [sample, sample];
+ } catch (_) {
+ finalElement = 0;
+ expectedElements = [0, 0, 0];
+ expectedIndices = [0, 1, 2];
+ expectedArrays = [sample, sample, sample];
+ }
+ }
+
+ elements.push(element);
+ indices.push(index);
+ arrays.push(array);
+ return false;
+ });
+
+ assert.compareArray(elements, [0, 0, finalElement], 'elements (shrink)');
+ assert.compareArray(indices, [0, 1, 2], 'indices (shrink)');
+ assert.compareArray(arrays, [sample, sample, sample], 'arrays (shrink)');
+ assert.sameValue(result, -1, 'result (shrink)');
+
+ elements = [];
+ indices = [];
+ arrays = [];
+ result = Array.prototype.findIndex.call(sample, function(element, index, array) {
+ if (elements.length === 0) {
+ try {
+ buffer.resize(4 * BPE);
+ } catch (_) {}
+ }
+
+ elements.push(element);
+ indices.push(index);
+ arrays.push(array);
+ return false;
+ });
+
+ assert.compareArray(elements, expectedElements, 'elements (grow)');
+ assert.compareArray(indices, expectedIndices, 'indices (grow)');
+ assert.compareArray(arrays, expectedArrays, 'arrays (grow)');
+ assert.sameValue(result, -1, 'result (grow)');
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/findIndex/length.js b/js/src/tests/test262/built-ins/Array/prototype/findIndex/length.js
new file mode 100644
index 0000000000..dafeb333b1
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/findIndex/length.js
@@ -0,0 +1,20 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-array.prototype.findindex
+description: Array.prototype.findIndex.length value and descriptor.
+info: |
+ 17 ECMAScript Standard Built-in Objects
+includes: [propertyHelper.js]
+---*/
+
+assert.sameValue(
+ Array.prototype.findIndex.length, 1,
+ 'The value of `Array.prototype.findIndex.length` is `1`'
+);
+
+verifyNotEnumerable(Array.prototype.findIndex, 'length');
+verifyNotWritable(Array.prototype.findIndex, 'length');
+verifyConfigurable(Array.prototype.findIndex, 'length');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/findIndex/name.js b/js/src/tests/test262/built-ins/Array/prototype/findIndex/name.js
new file mode 100644
index 0000000000..ad6b6d5a28
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/findIndex/name.js
@@ -0,0 +1,24 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-array.prototype.findindex
+description: >
+ Array.prototype.findIndex.name value and descriptor.
+info: |
+ 22.1.3.9 Array.prototype.findIndex ( predicate [ , thisArg ] )
+
+ 17 ECMAScript Standard Built-in Objects
+
+includes: [propertyHelper.js]
+---*/
+
+assert.sameValue(
+ Array.prototype.findIndex.name, 'findIndex',
+ 'The value of `Array.prototype.findIndex.name` is `"findIndex"`'
+);
+
+verifyNotEnumerable(Array.prototype.findIndex, 'name');
+verifyNotWritable(Array.prototype.findIndex, 'name');
+verifyConfigurable(Array.prototype.findIndex, 'name');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/findIndex/not-a-constructor.js b/js/src/tests/test262/built-ins/Array/prototype/findIndex/not-a-constructor.js
new file mode 100644
index 0000000000..ce4d52002d
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/findIndex/not-a-constructor.js
@@ -0,0 +1,35 @@
+// Copyright (C) 2020 Rick Waldron. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-ecmascript-standard-built-in-objects
+description: >
+ Array.prototype.findIndex does not implement [[Construct]], is not new-able
+info: |
+ ECMAScript Function Objects
+
+ Built-in function objects that are not identified as constructors do not
+ implement the [[Construct]] internal method unless otherwise specified in
+ the description of a particular function.
+
+ sec-evaluatenew
+
+ ...
+ 7. If IsConstructor(constructor) is false, throw a TypeError exception.
+ ...
+includes: [isConstructor.js]
+features: [Reflect.construct, arrow-function]
+---*/
+
+assert.sameValue(
+ isConstructor(Array.prototype.findIndex),
+ false,
+ 'isConstructor(Array.prototype.findIndex) must return false'
+);
+
+assert.throws(TypeError, () => {
+ new Array.prototype.findIndex(() => {});
+}, '`new Array.prototype.findIndex(() => {})` throws TypeError');
+
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/findIndex/predicate-call-parameters.js b/js/src/tests/test262/built-ins/Array/prototype/findIndex/predicate-call-parameters.js
new file mode 100644
index 0000000000..cb5505f555
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/findIndex/predicate-call-parameters.js
@@ -0,0 +1,47 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-array.prototype.findindex
+description: >
+ Predicate called as F.call( thisArg, kValue, k, O ) for each array entry.
+info: |
+ 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] )
+
+ ...
+ 6. If thisArg was supplied, let T be thisArg; else let T be undefined.
+ 7. Let k be 0.
+ 8. Repeat, while k < len
+ ...
+ d. Let testResult be ToBoolean(Call(predicate, T, «kValue, k, O»)).
+ ...
+---*/
+
+var arr = ['Mike', 'Rick', 'Leo'];
+
+var results = [];
+
+arr.findIndex(function(kValue, k, O) {
+ results.push(arguments);
+});
+
+assert.sameValue(results.length, 3);
+
+var result = results[0];
+assert.sameValue(result[0], 'Mike');
+assert.sameValue(result[1], 0);
+assert.sameValue(result[2], arr);
+assert.sameValue(result.length, 3);
+
+result = results[1];
+assert.sameValue(result[0], 'Rick');
+assert.sameValue(result[1], 1);
+assert.sameValue(result[2], arr);
+assert.sameValue(result.length, 3);
+
+result = results[2];
+assert.sameValue(result[0], 'Leo');
+assert.sameValue(result[1], 2);
+assert.sameValue(result[2], arr);
+assert.sameValue(result.length, 3);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/findIndex/predicate-call-this-non-strict.js b/js/src/tests/test262/built-ins/Array/prototype/findIndex/predicate-call-this-non-strict.js
new file mode 100644
index 0000000000..9399052631
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/findIndex/predicate-call-this-non-strict.js
@@ -0,0 +1,34 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-array.prototype.findindex
+description: >
+ Predicate thisArg as F.call( thisArg, kValue, k, O ) for each array entry.
+info: |
+ 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] )
+
+ ...
+ 8. Repeat, while k < len
+ ...
+ d. Let testResult be ToBoolean(Call(predicate, T, «kValue, k, O»)).
+ e. ReturnIfAbrupt(testResult).
+ ...
+flags: [noStrict]
+---*/
+
+var result;
+
+[1].find(function(kValue, k, O) {
+ result = this;
+});
+
+assert.sameValue(result, this);
+
+var o = {};
+[1].find(function() {
+ result = this;
+}, o);
+
+assert.sameValue(result, o);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/findIndex/predicate-call-this-strict-strict.js b/js/src/tests/test262/built-ins/Array/prototype/findIndex/predicate-call-this-strict-strict.js
new file mode 100644
index 0000000000..5d1029f8da
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/findIndex/predicate-call-this-strict-strict.js
@@ -0,0 +1,35 @@
+'use strict';
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-array.prototype.findindex
+description: >
+ Predicate thisArg as F.call( thisArg, kValue, k, O ) for each array entry.
+info: |
+ 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] )
+
+ ...
+ 8. Repeat, while k < len
+ ...
+ d. Let testResult be ToBoolean(Call(predicate, T, «kValue, k, O»)).
+ e. ReturnIfAbrupt(testResult).
+ ...
+flags: [onlyStrict]
+---*/
+
+var result;
+
+[1].find(function(kValue, k, O) {
+ result = this;
+});
+
+assert.sameValue(result, undefined);
+
+var o = {};
+[1].find(function() {
+ result = this;
+}, o);
+
+assert.sameValue(result, o);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/findIndex/predicate-called-for-each-array-property.js b/js/src/tests/test262/built-ins/Array/prototype/findIndex/predicate-called-for-each-array-property.js
new file mode 100644
index 0000000000..b343af598d
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/findIndex/predicate-called-for-each-array-property.js
@@ -0,0 +1,28 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-array.prototype.findindex
+description: >
+ Predicate is called for each array property.
+info: |
+ 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] )
+
+ ...
+ 6. If thisArg was supplied, let T be thisArg; else let T be undefined.
+ 7. Let k be 0.
+ 8. Repeat, while k < len
+ ...
+ d. Let testResult be ToBoolean(Call(predicate, T, «kValue, k, O»)).
+ ...
+---*/
+
+var arr = [undefined, , , 'foo'];
+var called = 0;
+
+arr.findIndex(function() {
+ called++;
+});
+
+assert.sameValue(called, 4);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/findIndex/predicate-is-not-callable-throws.js b/js/src/tests/test262/built-ins/Array/prototype/findIndex/predicate-is-not-callable-throws.js
new file mode 100644
index 0000000000..f985fa0aee
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/findIndex/predicate-is-not-callable-throws.js
@@ -0,0 +1,51 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-array.prototype.findindex
+description: >
+ Throws a TypeError exception if predicate is not callable.
+info: |
+ 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] )
+
+ ...
+ 5. If IsCallable(predicate) is false, throw a TypeError exception.
+ ...
+---*/
+
+assert.throws(TypeError, function() {
+ [].findIndex({});
+});
+
+assert.throws(TypeError, function() {
+ [].findIndex(null);
+});
+
+assert.throws(TypeError, function() {
+ [].findIndex(undefined);
+});
+
+assert.throws(TypeError, function() {
+ [].findIndex(true);
+});
+
+assert.throws(TypeError, function() {
+ [].findIndex(1);
+});
+
+assert.throws(TypeError, function() {
+ [].findIndex('');
+});
+
+assert.throws(TypeError, function() {
+ [].findIndex(1);
+});
+
+assert.throws(TypeError, function() {
+ [].findIndex([]);
+});
+
+assert.throws(TypeError, function() {
+ [].findIndex(/./);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/findIndex/predicate-not-called-on-empty-array.js b/js/src/tests/test262/built-ins/Array/prototype/findIndex/predicate-not-called-on-empty-array.js
new file mode 100644
index 0000000000..c3bd339896
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/findIndex/predicate-not-called-on-empty-array.js
@@ -0,0 +1,37 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-array.prototype.findindex
+description: >
+ Predicate is only called if this.length is > 0.
+info: |
+ 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] )
+
+ ...
+ 7. Let k be 0.
+ 8. Repeat, while k < len
+ ...
+ d. Let testResult be ToBoolean(Call(predicate, T, «kValue, k, O»)).
+ ...
+ 9. Return -1.
+---*/
+
+var called = false;
+
+var predicate = function() {
+ called = true;
+ return true;
+};
+
+var result = [].findIndex(predicate);
+
+assert.sameValue(
+ called, false,
+ '[].findIndex(predicate) does not call predicate'
+);
+assert.sameValue(
+ result, -1,
+ '[].findIndex(predicate) returned undefined'
+);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/findIndex/prop-desc.js b/js/src/tests/test262/built-ins/Array/prototype/findIndex/prop-desc.js
new file mode 100644
index 0000000000..c894ccf968
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/findIndex/prop-desc.js
@@ -0,0 +1,21 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-array.prototype.findindex
+description: Property type and descriptor.
+info: |
+ 17 ECMAScript Standard Built-in Objects
+includes: [propertyHelper.js]
+---*/
+
+assert.sameValue(
+ typeof Array.prototype.findIndex,
+ 'function',
+ '`typeof Array.prototype.findIndex` is `function`'
+);
+
+verifyNotEnumerable(Array.prototype, 'findIndex');
+verifyWritable(Array.prototype, 'findIndex');
+verifyConfigurable(Array.prototype, 'findIndex');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/findIndex/return-abrupt-from-predicate-call.js b/js/src/tests/test262/built-ins/Array/prototype/findIndex/return-abrupt-from-predicate-call.js
new file mode 100644
index 0000000000..41e0b25bd5
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/findIndex/return-abrupt-from-predicate-call.js
@@ -0,0 +1,27 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-array.prototype.findindex
+description: >
+ Return abrupt from predicate call.
+info: |
+ 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] )
+
+ ...
+ 7. Let k be 0.
+ 8. Repeat, while k < len
+ ...
+ d. Let testResult be ToBoolean(Call(predicate, T, «kValue, k, O»)).
+ e. ReturnIfAbrupt(testResult).
+ ...
+---*/
+
+var predicate = function() {
+ throw new Test262Error();
+};
+
+assert.throws(Test262Error, function() {
+ [1].findIndex(predicate);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/findIndex/return-abrupt-from-property.js b/js/src/tests/test262/built-ins/Array/prototype/findIndex/return-abrupt-from-property.js
new file mode 100644
index 0000000000..641f324b13
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/findIndex/return-abrupt-from-property.js
@@ -0,0 +1,33 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-array.prototype.findindex
+description: >
+ Returns abrupt from getting property value from `this`.
+info: |
+ 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] )
+
+ ...
+ 7. Let k be 0.
+ 8. Repeat, while k < len
+ a. Let Pk be ToString(k).
+ b. Let kValue be Get(O, Pk).
+ c. ReturnIfAbrupt(kValue).
+ ...
+---*/
+
+var o = {
+ length: 1
+};
+
+Object.defineProperty(o, 0, {
+ get: function() {
+ throw new Test262Error();
+ }
+});
+
+assert.throws(Test262Error, function() {
+ [].findIndex.call(o, function() {});
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/findIndex/return-abrupt-from-this-length-as-symbol.js b/js/src/tests/test262/built-ins/Array/prototype/findIndex/return-abrupt-from-this-length-as-symbol.js
new file mode 100644
index 0000000000..3884770242
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/findIndex/return-abrupt-from-this-length-as-symbol.js
@@ -0,0 +1,27 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-array.prototype.findindex
+description: >
+ Return abrupt from ToLength(Get(O, "length")) where length is a Symbol.
+info: |
+ 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] )
+
+ 1. Let O be ToObject(this value).
+ 2. ReturnIfAbrupt(O).
+ 3. Let len be ToLength(Get(O, "length")).
+ 4. ReturnIfAbrupt(len).
+ ...
+features: [Symbol]
+---*/
+
+var o = {};
+
+o.length = Symbol(1);
+
+// predicate fn is given to avoid false positives
+assert.throws(TypeError, function() {
+ [].findIndex.call(o, function() {});
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/findIndex/return-abrupt-from-this-length.js b/js/src/tests/test262/built-ins/Array/prototype/findIndex/return-abrupt-from-this-length.js
new file mode 100644
index 0000000000..152e05756b
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/findIndex/return-abrupt-from-this-length.js
@@ -0,0 +1,40 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-array.prototype.findindex
+description: >
+ Return abrupt from ToLength(Get(O, "length")).
+info: |
+ 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] )
+
+ 1. Let O be ToObject(this value).
+ 2. ReturnIfAbrupt(O).
+ 3. Let len be ToLength(Get(O, "length")).
+ 4. ReturnIfAbrupt(len).
+---*/
+
+var o1 = {};
+
+Object.defineProperty(o1, 'length', {
+ get: function() {
+ throw new Test262Error();
+ },
+ configurable: true
+});
+// predicate fn is given to avoid false positives
+assert.throws(Test262Error, function() {
+ [].findIndex.call(o1, function() {});
+});
+
+var o2 = {
+ length: {
+ valueOf: function() {
+ throw new Test262Error();
+ }
+ }
+};
+assert.throws(Test262Error, function() {
+ [].findIndex.call(o2, function() {});
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/findIndex/return-abrupt-from-this.js b/js/src/tests/test262/built-ins/Array/prototype/findIndex/return-abrupt-from-this.js
new file mode 100644
index 0000000000..88e0ca0b38
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/findIndex/return-abrupt-from-this.js
@@ -0,0 +1,23 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-array.prototype.findindex
+description: >
+ Return abrupt from ToObject(this value).
+info: |
+ 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] )
+
+ 1. Let O be ToObject(this value).
+ 2. ReturnIfAbrupt(O).
+---*/
+
+// predicate fn is given to avoid false positives
+assert.throws(TypeError, function() {
+ Array.prototype.findIndex.call(undefined, function() {});
+});
+
+assert.throws(TypeError, function() {
+ Array.prototype.findIndex.call(null, function() {});
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/findIndex/return-index-predicate-result-is-true.js b/js/src/tests/test262/built-ins/Array/prototype/findIndex/return-index-predicate-result-is-true.js
new file mode 100644
index 0000000000..a327f75137
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/findIndex/return-index-predicate-result-is-true.js
@@ -0,0 +1,65 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-array.prototype.findindex
+description: >
+ Return index if predicate return a boolean true value.
+info: |
+ 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] )
+
+ ...
+ 8. Repeat, while k < len
+ ...
+ d. Let testResult be ToBoolean(Call(predicate, T, «kValue, k, O»)).
+ e. ReturnIfAbrupt(testResult).
+ f. If testResult is true, return k.
+ ...
+features: [Symbol]
+---*/
+
+var arr = ['Shoes', 'Car', 'Bike'];
+var called = 0;
+
+var result = arr.findIndex(function(val) {
+ called++;
+ return true;
+});
+
+assert.sameValue(result, 0);
+assert.sameValue(called, 1, 'predicate was called once');
+
+called = 0;
+result = arr.findIndex(function(val) {
+ called++;
+ return val === 'Bike';
+});
+
+assert.sameValue(called, 3, 'predicate was called three times');
+assert.sameValue(result, 2);
+
+result = arr.findIndex(function(val) {
+ return 'string';
+});
+assert.sameValue(result, 0, 'coerced string');
+
+result = arr.findIndex(function(val) {
+ return {};
+});
+assert.sameValue(result, 0, 'coerced object');
+
+result = arr.findIndex(function(val) {
+ return Symbol('');
+});
+assert.sameValue(result, 0, 'coerced Symbol');
+
+result = arr.findIndex(function(val) {
+ return 1;
+});
+assert.sameValue(result, 0, 'coerced number');
+
+result = arr.findIndex(function(val) {
+ return -1;
+});
+assert.sameValue(result, 0, 'coerced negative number');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/findIndex/return-negative-one-if-predicate-returns-false-value.js b/js/src/tests/test262/built-ins/Array/prototype/findIndex/return-negative-one-if-predicate-returns-false-value.js
new file mode 100644
index 0000000000..419ec5ccce
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/findIndex/return-negative-one-if-predicate-returns-false-value.js
@@ -0,0 +1,55 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-array.prototype.findindex
+description: >
+ Return -1 if predicate always returns a boolean false value.
+info: |
+ 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] )
+
+ ...
+ 8. Repeat, while k < len
+ ...
+ d. Let testResult be ToBoolean(Call(predicate, T, «kValue, k, O»)).
+ ...
+ 9. Return -1.
+features: [Symbol]
+---*/
+
+var arr = ['Shoes', 'Car', 'Bike'];
+var called = 0;
+
+var result = arr.findIndex(function(val) {
+ called++;
+ return false;
+});
+
+assert.sameValue(called, 3, 'predicate was called three times');
+assert.sameValue(result, -1);
+
+result = arr.findIndex(function(val) {
+ return '';
+});
+assert.sameValue(result, -1, 'coerced string');
+
+result = arr.findIndex(function(val) {
+ return undefined;
+});
+assert.sameValue(result, -1, 'coerced undefined');
+
+result = arr.findIndex(function(val) {
+ return null;
+});
+assert.sameValue(result, -1, 'coerced null');
+
+result = arr.findIndex(function(val) {
+ return 0;
+});
+assert.sameValue(result, -1, 'coerced 0');
+
+result = arr.findIndex(function(val) {
+ return NaN;
+});
+assert.sameValue(result, -1, 'coerced NaN');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/findIndex/shell.js b/js/src/tests/test262/built-ins/Array/prototype/findIndex/shell.js
new file mode 100644
index 0000000000..05fecd6ef1
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/findIndex/shell.js
@@ -0,0 +1,161 @@
+// GENERATED, DO NOT EDIT
+// file: testTypedArray.js
+// Copyright (C) 2015 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+description: |
+ Collection of functions used to assert the correctness of TypedArray objects.
+defines:
+ - floatArrayConstructors
+ - nonClampedIntArrayConstructors
+ - intArrayConstructors
+ - typedArrayConstructors
+ - TypedArray
+ - testWithTypedArrayConstructors
+ - nonAtomicsFriendlyTypedArrayConstructors
+ - testWithAtomicsFriendlyTypedArrayConstructors
+ - testWithNonAtomicsFriendlyTypedArrayConstructors
+ - testTypedArrayConversions
+---*/
+
+var floatArrayConstructors = [
+ Float64Array,
+ Float32Array
+];
+
+var nonClampedIntArrayConstructors = [
+ Int32Array,
+ Int16Array,
+ Int8Array,
+ Uint32Array,
+ Uint16Array,
+ Uint8Array
+];
+
+var intArrayConstructors = nonClampedIntArrayConstructors.concat([Uint8ClampedArray]);
+
+// Float16Array is a newer feature
+// adding it to this list unconditionally would cause implementations lacking it to fail every test which uses it
+if (typeof Float16Array !== 'undefined') {
+ floatArrayConstructors.push(Float16Array);
+}
+
+/**
+ * Array containing every non-bigint typed array constructor.
+ */
+
+var typedArrayConstructors = floatArrayConstructors.concat(intArrayConstructors);
+
+/**
+ * The %TypedArray% intrinsic constructor function.
+ */
+var TypedArray = Object.getPrototypeOf(Int8Array);
+
+/**
+ * Callback for testing a typed array constructor.
+ *
+ * @callback typedArrayConstructorCallback
+ * @param {Function} Constructor the constructor object to test with.
+ */
+
+/**
+ * Calls the provided function for every typed array constructor.
+ *
+ * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor.
+ * @param {Array} selected - An optional Array with filtered typed arrays
+ */
+function testWithTypedArrayConstructors(f, selected) {
+ var constructors = selected || typedArrayConstructors;
+ for (var i = 0; i < constructors.length; ++i) {
+ var constructor = constructors[i];
+ try {
+ f(constructor);
+ } catch (e) {
+ e.message += " (Testing with " + constructor.name + ".)";
+ throw e;
+ }
+ }
+}
+
+var nonAtomicsFriendlyTypedArrayConstructors = floatArrayConstructors.concat([Uint8ClampedArray]);
+/**
+ * Calls the provided function for every non-"Atomics Friendly" typed array constructor.
+ *
+ * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor.
+ * @param {Array} selected - An optional Array with filtered typed arrays
+ */
+function testWithNonAtomicsFriendlyTypedArrayConstructors(f) {
+ testWithTypedArrayConstructors(f, nonAtomicsFriendlyTypedArrayConstructors);
+}
+
+/**
+ * Calls the provided function for every "Atomics Friendly" typed array constructor.
+ *
+ * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor.
+ * @param {Array} selected - An optional Array with filtered typed arrays
+ */
+function testWithAtomicsFriendlyTypedArrayConstructors(f) {
+ testWithTypedArrayConstructors(f, [
+ Int32Array,
+ Int16Array,
+ Int8Array,
+ Uint32Array,
+ Uint16Array,
+ Uint8Array,
+ ]);
+}
+
+/**
+ * Helper for conversion operations on TypedArrays, the expected values
+ * properties are indexed in order to match the respective value for each
+ * TypedArray constructor
+ * @param {Function} fn - the function to call for each constructor and value.
+ * will be called with the constructor, value, expected
+ * value, and a initial value that can be used to avoid
+ * a false positive with an equivalent expected value.
+ */
+function testTypedArrayConversions(byteConversionValues, fn) {
+ var values = byteConversionValues.values;
+ var expected = byteConversionValues.expected;
+
+ testWithTypedArrayConstructors(function(TA) {
+ var name = TA.name.slice(0, -5);
+
+ return values.forEach(function(value, index) {
+ var exp = expected[name][index];
+ var initial = 0;
+ if (exp === 0) {
+ initial = 1;
+ }
+ fn(TA, value, exp, initial);
+ });
+ });
+}
+
+/**
+ * Checks if the given argument is one of the float-based TypedArray constructors.
+ *
+ * @param {constructor} ctor - the value to check
+ * @returns {boolean}
+ */
+function isFloatTypedArrayConstructor(arg) {
+ return floatArrayConstructors.indexOf(arg) !== -1;
+}
+
+/**
+ * Determines the precision of the given float-based TypedArray constructor.
+ *
+ * @param {constructor} ctor - the value to check
+ * @returns {string} "half", "single", or "double" for Float16Array, Float32Array, and Float64Array respectively.
+ */
+function floatTypedArrayConstructorPrecision(FA) {
+ if (typeof Float16Array !== "undefined" && FA === Float16Array) {
+ return "half";
+ } else if (FA === Float32Array) {
+ return "single";
+ } else if (FA === Float64Array) {
+ return "double";
+ } else {
+ throw new Error("Malformed test - floatTypedArrayConstructorPrecision called with non-float TypedArray");
+ }
+}