summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/TypedArray/prototype/findIndex/predicate-call-changes-value.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/TypedArray/prototype/findIndex/predicate-call-changes-value.js')
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/findIndex/predicate-call-changes-value.js69
1 files changed, 69 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/findIndex/predicate-call-changes-value.js b/js/src/tests/test262/built-ins/TypedArray/prototype/findIndex/predicate-call-changes-value.js
new file mode 100644
index 0000000000..8ee1fcccae
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/findIndex/predicate-call-changes-value.js
@@ -0,0 +1,69 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-%typedarray%.prototype.findindex
+description: >
+ Change values during predicate call
+info: |
+ 22.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] )
+
+ %TypedArray%.prototype.findIndex is a distinct function that implements the
+ same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that
+ the this object's [[ArrayLength]] internal slot is accessed in place of
+ performing a [[Get]] of "length".
+
+ ...
+
+ 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] )
+
+ ...
+ 6. Repeat, while k < len
+ ...
+ c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
+ ...
+includes: [compareArray.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var arr = [10, 20, 30];
+ var sample;
+ var result;
+
+ sample = new TA(3);
+ sample.findIndex(function(val, i) {
+ sample[i] = arr[i];
+
+ assert.sameValue(val, 0, "value is not mapped to instance");
+ });
+ assert(compareArray(sample, arr), "values set during each predicate call");
+
+ sample = new TA(arr);
+ result = sample.findIndex(function(val, i) {
+ if ( i === 0 ) {
+ sample[2] = 7;
+ }
+ return val === 7;
+ });
+ assert.sameValue(result, 2, "value found");
+
+ sample = new TA(arr);
+ result = sample.findIndex(function(val, i) {
+ if ( i === 0 ) {
+ sample[2] = 7;
+ }
+ return val === 30;
+ });
+ assert.sameValue(result, -1, "value not found");
+
+ sample = new TA(arr);
+ result = sample.findIndex(function(val, i) {
+ if ( i > 0 ) {
+ sample[0] = 7;
+ }
+ return val === 7;
+ });
+ assert.sameValue(result, -1, "value not found - changed after call");
+});
+
+reportCompare(0, 0);