diff options
Diffstat (limited to 'test/built-ins/TypedArray/prototype/findIndex')
35 files changed, 881 insertions, 17 deletions
diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/detached-buffer.js new file mode 100644 index 000000000..f8e8ed449 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/detached-buffer.js @@ -0,0 +1,32 @@ +// 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: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var predicate = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.findIndex(predicate); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/get-length-ignores-length-prop.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/get-length-ignores-length-prop.js new file mode 100644 index 000000000..d4287dfbd --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/get-length-ignores-length-prop.js @@ -0,0 +1,52 @@ +// 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: > + [[Get]] of "length" uses [[ArrayLength]] +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 ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +Object.defineProperty(TypedArray.prototype, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + Object.defineProperty(TA.prototype, "length", { + get: function() { + throw new Test262Error(); + } + }); + + var sample = new TA([42n]); + + Object.defineProperty(sample, "length", { + get: function() { + throw new Test262Error(); + }, + configurable: true + }); + + assert.sameValue( + sample.findIndex(function() { return true; }), + 0 + ); +}); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/invoked-as-func.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/invoked-as-func.js new file mode 100644 index 000000000..f305556a1 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/invoked-as-func.js @@ -0,0 +1,29 @@ +// 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: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var findIndex = TypedArray.prototype.findIndex; + +assert.sameValue(typeof findIndex, 'function'); + +assert.throws(TypeError, function() { + findIndex(); +}); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/invoked-as-method.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/invoked-as-method.js new file mode 100644 index 000000000..1871afdab --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/invoked-as-method.js @@ -0,0 +1,29 @@ +// 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: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(typeof TypedArrayPrototype.findIndex, 'function'); + +assert.throws(TypeError, function() { + TypedArrayPrototype.findIndex(); +}); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/length.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/length.js new file mode 100644 index 000000000..64d37958e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/length.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.findindex +description: > + %TypedArray%.prototype.findIndex.length is 1. +info: | + %TypedArray%.prototype.findIndex (predicate [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +assert.sameValue(TypedArray.prototype.findIndex.length, 1); + +verifyNotEnumerable(TypedArray.prototype.findIndex, "length"); +verifyNotWritable(TypedArray.prototype.findIndex, "length"); +verifyConfigurable(TypedArray.prototype.findIndex, "length"); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/name.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/name.js new file mode 100644 index 000000000..84a9724a2 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/name.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.findindex +description: > + %TypedArray%.prototype.findIndex.name is "findIndex". +info: | + %TypedArray%.prototype.findIndex (predicate [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +assert.sameValue(TypedArray.prototype.findIndex.name, "findIndex"); + +verifyNotEnumerable(TypedArray.prototype.findIndex, "name"); +verifyNotWritable(TypedArray.prototype.findIndex, "name"); +verifyConfigurable(TypedArray.prototype.findIndex, "name"); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-call-changes-value.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-call-changes-value.js new file mode 100644 index 000000000..2fa760323 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-call-changes-value.js @@ -0,0 +1,67 @@ +// 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, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var arr = [10n, 20n, 30n]; + var sample; + var result; + + sample = new TA(3); + sample.findIndex(function(val, i) { + sample[i] = arr[i]; + + assert.sameValue(val, 0n, "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] = 7n; + } + return val === 7n; + }); + assert.sameValue(result, 2, "value found"); + + sample = new TA(arr); + result = sample.findIndex(function(val, i) { + if ( i === 0 ) { + sample[2] = 7n; + } + return val === 30n; + }); + assert.sameValue(result, -1, "value not found"); + + sample = new TA(arr); + result = sample.findIndex(function(val, i) { + if ( i > 0 ) { + sample[0] = 7n; + } + return val === 7n; + }); + assert.sameValue(result, -1, "value not found - changed after call"); +}); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-call-parameters.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-call-parameters.js new file mode 100644 index 000000000..1025bbb24 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-call-parameters.js @@ -0,0 +1,60 @@ +// 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: > + Predicate called as F.call( thisArg, kValue, k, O ) for each array entry. +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 ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + 5. Let k be 0. + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([39n, 2n, 62n]); + var results = []; + var result; + + sample.foo = "bar"; // Ignores non integer index properties + + sample.findIndex(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 3, "predicate is called for each index"); + + result = results[0]; + assert.sameValue(result[0], 39n, "results[0][0] === 39, value"); + assert.sameValue(result[1], 0, "results[0][1] === 0, index"); + assert.sameValue(result[2], sample, "results[0][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[0].length === 3, arguments"); + + result = results[1]; + assert.sameValue(result[0], 2n, "results[1][0] === 2, value"); + assert.sameValue(result[1], 1, "results[1][1] === 1, index"); + assert.sameValue(result[2], sample, "results[1][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[1].length === 3, arguments"); + + result = results[2]; + assert.sameValue(result[0], 62n, "results[2][0] === 62, value"); + assert.sameValue(result[1], 2, "results[2][1] === 2, index"); + assert.sameValue(result[2], sample, "results[2][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[2].length === 3, arguments"); +}); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-call-this-non-strict.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-call-this-non-strict.js new file mode 100644 index 000000000..3c1d4b9f2 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-call-this-non-strict.js @@ -0,0 +1,57 @@ +// 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: > + Verify predicate this on non-strict mode +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 ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + 5. Let k be 0. + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +flags: [noStrict] +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var T = this; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + var result; + + sample.findIndex(function() { + result = this; + }); + + assert.sameValue(result, T, "without thisArg, predicate this is the global"); + + result = null; + sample.findIndex(function() { + result = this; + }, undefined); + + assert.sameValue(result, T, "predicate this is the global when thisArg is undefined"); + + var o = {}; + result = null; + sample.findIndex(function() { + result = this; + }, o); + + assert.sameValue(result, o, "thisArg becomes the predicate this"); +}); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-call-this-strict.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-call-this-strict.js new file mode 100644 index 000000000..af6ce6a73 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-call-this-strict.js @@ -0,0 +1,51 @@ +// 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: > + Predicate thisArg as F.call( thisArg, kValue, k, O ) for each array entry. +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 ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + 5. Let k be 0. + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +flags: [onlyStrict] +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + var result; + + sample.findIndex(function() { + result = this; + }); + + assert.sameValue( + result, + undefined, + "without thisArg, predicate this is undefined" + ); + + var o = {}; + sample.findIndex(function() { + result = this; + }, o); + + assert.sameValue(result, o, "thisArg becomes the predicate this"); +}); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-is-not-callable-throws.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-is-not-callable-throws.js new file mode 100644 index 000000000..c8a101d05 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-is-not-callable-throws.js @@ -0,0 +1,64 @@ +// 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: > + Throws a TypeError exception if predicate is not callable. +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 ] ) + + ... + 3. If IsCallable(predicate) is false, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(TypeError, function() { + sample.findIndex({}); + }, "{}"); + + assert.throws(TypeError, function() { + sample.findIndex(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.findIndex(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.findIndex(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.findIndex(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.findIndex(1); + }, "1"); + + assert.throws(TypeError, function() { + sample.findIndex(""); + }, "string"); + + assert.throws(TypeError, function() { + sample.findIndex([]); + }, "[]"); + + assert.throws(TypeError, function() { + sample.findIndex(/./); + }, "/./"); +}); + diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-may-detach-buffer.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-may-detach-buffer.js new file mode 100644 index 000000000..80078b3fe --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-may-detach-buffer.js @@ -0,0 +1,51 @@ +// 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: > + Predicate may detach the buffer +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 + ... + b. Let kValue be ? Get(O, Pk). + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 3. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var loops = 0; + var completion = false; + + assert.throws(TypeError, function() { + sample.findIndex(function() { + loops++; + $DETACHBUFFER(sample.buffer); + completion = true; + }); + }, "throws a TypeError getting a value from the detached buffer"); + + assert.sameValue(loops, 1, "predicated is called once"); + assert(completion, "abrupt completion does not come from DETACHBUFFER"); +}); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-not-called-on-empty-array.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-not-called-on-empty-array.js new file mode 100644 index 000000000..a08e80ef5 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-not-called-on-empty-array.js @@ -0,0 +1,48 @@ +// 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: > + Predicate is not called on an empty instance +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 »)). + ... + 7. Return -1. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + var called = false; + + var predicate = function() { + called = true; + return true; + }; + + var result = sample.findIndex(predicate); + + assert.sameValue( + called, false, + "does not call predicate" + ); + assert.sameValue( + result, -1, + "returns -1 on an empty instance" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/prop-desc.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/prop-desc.js new file mode 100644 index 000000000..9913a867e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/prop-desc.js @@ -0,0 +1,19 @@ +// 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: > + "findIndex" property of TypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +verifyNotEnumerable(TypedArrayPrototype, 'findIndex'); +verifyWritable(TypedArrayPrototype, 'findIndex'); +verifyConfigurable(TypedArrayPrototype, 'findIndex'); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/return-abrupt-from-predicate-call.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/return-abrupt-from-predicate-call.js new file mode 100644 index 000000000..49405f3c5 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/return-abrupt-from-predicate-call.js @@ -0,0 +1,38 @@ +// 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: > + Return abrupt from 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 ] ) + + ... + 5. Let k be 0. + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var predicate = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + assert.throws(Test262Error, function() { + sample.findIndex(predicate); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/return-index-predicate-result-is-true.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/return-index-predicate-result-is-true.js new file mode 100644 index 000000000..25e26d808 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/return-index-predicate-result-is-true.js @@ -0,0 +1,65 @@ +// 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: > + Return index if predicate return a boolean true value. +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 ] ) + + ... + 5. Let k be 0. + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + d. If testResult is true, return k. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([39n, 3n, 9n]); + var called = 0; + + var result = sample.findIndex(function() { + called++; + return true; + }); + + assert.sameValue(result, 0, "returned true on sample[0]"); + assert.sameValue(called, 1, "predicate was called once"); + + called = 0; + result = sample.findIndex(function(val) { + called++; + return val === 9n; + }); + + assert.sameValue(called, 3, "predicate was called three times"); + assert.sameValue(result, 2, "returned true on sample[3]"); + + result = sample.findIndex(function() { return "string"; }); + assert.sameValue(result, 0, "ToBoolean(string)"); + + result = sample.findIndex(function() { return {}; }); + assert.sameValue(result, 0, "ToBoolean(object)"); + + result = sample.findIndex(function() { return Symbol(""); }); + assert.sameValue(result, 0, "ToBoolean(symbol)"); + + result = sample.findIndex(function() { return 1; }); + assert.sameValue(result, 0, "ToBoolean(number)"); + + result = sample.findIndex(function() { return -1; }); + assert.sameValue(result, 0, "ToBoolean(negative number)"); +}); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/return-negative-one-if-predicate-returns-false-value.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/return-negative-one-if-predicate-returns-false-value.js new file mode 100644 index 000000000..fcf5d800c --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/return-negative-one-if-predicate-returns-false-value.js @@ -0,0 +1,58 @@ +// 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: > + Return -1 if predicate always returns a boolean false value. +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 »)). + ... + 7. Return -1. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([1n, 2n, 3n]); + var called = 0; + + var result = sample.findIndex(function() { + called++; + return false; + }); + + assert.sameValue(called, 3, "predicate was called three times"); + assert.sameValue(result, -1, "result is -1 when predicate returns are false"); + + result = sample.findIndex(function() { return ""; }); + assert.sameValue(result, -1, "ToBoolean(string)"); + + result = sample.findIndex(function() { return undefined; }); + assert.sameValue(result, -1, "ToBoolean(undefined)"); + + result = sample.findIndex(function() { return null; }); + assert.sameValue(result, -1, "ToBoolean(null)"); + + result = sample.findIndex(function() { return 0; }); + assert.sameValue(result, -1, "ToBoolean(0)"); + + result = sample.findIndex(function() { return -0; }); + assert.sameValue(result, -1, "ToBoolean(-0)"); + + result = sample.findIndex(function() { return NaN; }); + assert.sameValue(result, -1, "ToBoolean(NaN)"); +}); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/this-is-not-object.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/this-is-not-object.js new file mode 100644 index 000000000..fedede8b0 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/this-is-not-object.js @@ -0,0 +1,51 @@ +// 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: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var findIndex = TypedArray.prototype.findIndex; +var predicate = function() {}; + +assert.throws(TypeError, function() { + findIndex.call(undefined, predicate); +}, "this is undefined"); + +assert.throws(TypeError, function() { + findIndex.call(null, predicate); +}, "this is null"); + +assert.throws(TypeError, function() { + findIndex.call(42, predicate); +}, "this is 42"); + +assert.throws(TypeError, function() { + findIndex.call("1", predicate); +}, "this is a string"); + +assert.throws(TypeError, function() { + findIndex.call(true, predicate); +}, "this is true"); + +assert.throws(TypeError, function() { + findIndex.call(false, predicate); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + findIndex.call(s, predicate); +}, "this is a Symbol"); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/this-is-not-typedarray-instance.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/this-is-not-typedarray-instance.js new file mode 100644 index 000000000..0c1bbab00 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/this-is-not-typedarray-instance.js @@ -0,0 +1,43 @@ +// 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: > + Throws a TypeError exception when `this` is not a TypedArray instance +info: | + 22.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var findIndex = TypedArray.prototype.findIndex; +var predicate = function() {}; + +assert.throws(TypeError, function() { + findIndex.call({}, predicate); +}, "this is an Object"); + +assert.throws(TypeError, function() { + findIndex.call([], predicate); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + findIndex.call(ab, predicate); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + findIndex.call(dv, predicate); +}, "this is a DataView instance"); diff --git a/test/built-ins/TypedArray/prototype/findIndex/get-length-ignores-length-prop.js b/test/built-ins/TypedArray/prototype/findIndex/get-length-ignores-length-prop.js index 99566c3d5..89b8815c5 100644 --- a/test/built-ins/TypedArray/prototype/findIndex/get-length-ignores-length-prop.js +++ b/test/built-ins/TypedArray/prototype/findIndex/get-length-ignores-length-prop.js @@ -2,7 +2,6 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- esid: sec-%typedarray%.prototype.findindex -es6id: 22.2.3.11 description: > [[Get]] of "length" uses [[ArrayLength]] info: | diff --git a/test/built-ins/TypedArray/prototype/findIndex/invoked-as-func.js b/test/built-ins/TypedArray/prototype/findIndex/invoked-as-func.js index 16a85a91d..54ca2a83c 100644 --- a/test/built-ins/TypedArray/prototype/findIndex/invoked-as-func.js +++ b/test/built-ins/TypedArray/prototype/findIndex/invoked-as-func.js @@ -1,7 +1,7 @@ // Copyright (C) 2016 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -es6id: 22.2.3.11 +esid: sec-%typedarray%.prototype.findindex description: Throws a TypeError exception when invoked as a function info: | 22.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) diff --git a/test/built-ins/TypedArray/prototype/findIndex/invoked-as-method.js b/test/built-ins/TypedArray/prototype/findIndex/invoked-as-method.js index dfd2e8f25..d5ec6304f 100644 --- a/test/built-ins/TypedArray/prototype/findIndex/invoked-as-method.js +++ b/test/built-ins/TypedArray/prototype/findIndex/invoked-as-method.js @@ -1,7 +1,7 @@ // Copyright (C) 2016 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -es6id: 22.2.3.11 +esid: sec-%typedarray%.prototype.findindex description: Requires a [[TypedArrayName]] internal slot. info: | 22.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) diff --git a/test/built-ins/TypedArray/prototype/findIndex/length.js b/test/built-ins/TypedArray/prototype/findIndex/length.js index f2d44b12b..0ec6d4a5f 100644 --- a/test/built-ins/TypedArray/prototype/findIndex/length.js +++ b/test/built-ins/TypedArray/prototype/findIndex/length.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -es6id: 22.2.3.11 +esid: sec-%typedarray%.prototype.findindex description: > %TypedArray%.prototype.findIndex.length is 1. info: | @@ -20,6 +20,7 @@ info: | object has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }. includes: [propertyHelper.js, testTypedArray.js] +features: [TypedArray] ---*/ assert.sameValue(TypedArray.prototype.findIndex.length, 1); diff --git a/test/built-ins/TypedArray/prototype/findIndex/name.js b/test/built-ins/TypedArray/prototype/findIndex/name.js index c2113b623..deb8c73a9 100644 --- a/test/built-ins/TypedArray/prototype/findIndex/name.js +++ b/test/built-ins/TypedArray/prototype/findIndex/name.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -es6id: 22.2.3.11 +esid: sec-%typedarray%.prototype.findindex description: > %TypedArray%.prototype.findIndex.name is "findIndex". info: | @@ -17,6 +17,7 @@ info: | object, if it exists, has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }. includes: [propertyHelper.js, testTypedArray.js] +features: [TypedArray] ---*/ assert.sameValue(TypedArray.prototype.findIndex.name, "findIndex"); diff --git a/test/built-ins/TypedArray/prototype/findIndex/predicate-call-changes-value.js b/test/built-ins/TypedArray/prototype/findIndex/predicate-call-changes-value.js index 84efabc26..2843859a0 100644 --- a/test/built-ins/TypedArray/prototype/findIndex/predicate-call-changes-value.js +++ b/test/built-ins/TypedArray/prototype/findIndex/predicate-call-changes-value.js @@ -2,7 +2,6 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- esid: sec-%typedarray%.prototype.findindex -es6id: 22.2.3.11 description: > Change values during predicate call info: | @@ -23,6 +22,7 @@ info: | c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). ... includes: [compareArray.js, testTypedArray.js] +features: [TypedArray] ---*/ testWithTypedArrayConstructors(function(TA) { @@ -64,4 +64,4 @@ testWithTypedArrayConstructors(function(TA) { return val === 7; }); assert.sameValue(result, -1, "value not found - changed after call"); -});
\ No newline at end of file +}); diff --git a/test/built-ins/TypedArray/prototype/findIndex/predicate-call-parameters.js b/test/built-ins/TypedArray/prototype/findIndex/predicate-call-parameters.js index a4102dcb3..5483cc49a 100644 --- a/test/built-ins/TypedArray/prototype/findIndex/predicate-call-parameters.js +++ b/test/built-ins/TypedArray/prototype/findIndex/predicate-call-parameters.js @@ -2,7 +2,6 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- esid: sec-%typedarray%.prototype.findindex -es6id: 22.2.3.11 description: > Predicate called as F.call( thisArg, kValue, k, O ) for each array entry. info: | diff --git a/test/built-ins/TypedArray/prototype/findIndex/predicate-call-this-non-strict.js b/test/built-ins/TypedArray/prototype/findIndex/predicate-call-this-non-strict.js index 68175c781..5f6086b8f 100644 --- a/test/built-ins/TypedArray/prototype/findIndex/predicate-call-this-non-strict.js +++ b/test/built-ins/TypedArray/prototype/findIndex/predicate-call-this-non-strict.js @@ -2,7 +2,6 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- esid: sec-%typedarray%.prototype.findindex -es6id: 22.2.3.11 description: > Verify predicate this on non-strict mode info: | diff --git a/test/built-ins/TypedArray/prototype/findIndex/predicate-call-this-strict.js b/test/built-ins/TypedArray/prototype/findIndex/predicate-call-this-strict.js index a4dd13ac2..96ef46098 100644 --- a/test/built-ins/TypedArray/prototype/findIndex/predicate-call-this-strict.js +++ b/test/built-ins/TypedArray/prototype/findIndex/predicate-call-this-strict.js @@ -2,7 +2,6 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- esid: sec-%typedarray%.prototype.findindex -es6id: 22.2.3.11 description: > Predicate thisArg as F.call( thisArg, kValue, k, O ) for each array entry. info: | diff --git a/test/built-ins/TypedArray/prototype/findIndex/predicate-is-not-callable-throws.js b/test/built-ins/TypedArray/prototype/findIndex/predicate-is-not-callable-throws.js index 5b97bf74a..872c4ffe8 100644 --- a/test/built-ins/TypedArray/prototype/findIndex/predicate-is-not-callable-throws.js +++ b/test/built-ins/TypedArray/prototype/findIndex/predicate-is-not-callable-throws.js @@ -2,7 +2,6 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- esid: sec-%typedarray%.prototype.findindex -es6id: 22.2.3.11 description: > Throws a TypeError exception if predicate is not callable. info: | diff --git a/test/built-ins/TypedArray/prototype/findIndex/predicate-may-detach-buffer.js b/test/built-ins/TypedArray/prototype/findIndex/predicate-may-detach-buffer.js index 831d296ce..6124bc3fb 100644 --- a/test/built-ins/TypedArray/prototype/findIndex/predicate-may-detach-buffer.js +++ b/test/built-ins/TypedArray/prototype/findIndex/predicate-may-detach-buffer.js @@ -2,7 +2,6 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- esid: sec-%typedarray%.prototype.findindex -es6id: 22.2.3.11 description: > Predicate may detach the buffer info: | diff --git a/test/built-ins/TypedArray/prototype/findIndex/predicate-not-called-on-empty-array.js b/test/built-ins/TypedArray/prototype/findIndex/predicate-not-called-on-empty-array.js index e4fa770da..e6a4abb4a 100644 --- a/test/built-ins/TypedArray/prototype/findIndex/predicate-not-called-on-empty-array.js +++ b/test/built-ins/TypedArray/prototype/findIndex/predicate-not-called-on-empty-array.js @@ -2,7 +2,6 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- esid: sec-%typedarray%.prototype.findindex -es6id: 22.2.3.11 description: > Predicate is not called on an empty instance info: | diff --git a/test/built-ins/TypedArray/prototype/findIndex/prop-desc.js b/test/built-ins/TypedArray/prototype/findIndex/prop-desc.js index 014d8284a..74abd2659 100644 --- a/test/built-ins/TypedArray/prototype/findIndex/prop-desc.js +++ b/test/built-ins/TypedArray/prototype/findIndex/prop-desc.js @@ -1,7 +1,7 @@ // Copyright (C) 2016 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -es6id: 22.2.3.11 +esid: sec-%typedarray%.prototype.findindex description: > "findIndex" property of TypedArrayPrototype info: | @@ -9,6 +9,7 @@ info: | and in Annex B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. includes: [propertyHelper.js, testTypedArray.js] +features: [TypedArray] ---*/ var TypedArrayPrototype = TypedArray.prototype; diff --git a/test/built-ins/TypedArray/prototype/findIndex/return-abrupt-from-predicate-call.js b/test/built-ins/TypedArray/prototype/findIndex/return-abrupt-from-predicate-call.js index df09745c1..1b01c8221 100644 --- a/test/built-ins/TypedArray/prototype/findIndex/return-abrupt-from-predicate-call.js +++ b/test/built-ins/TypedArray/prototype/findIndex/return-abrupt-from-predicate-call.js @@ -2,7 +2,6 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- esid: sec-%typedarray%.prototype.findindex -es6id: 22.2.3.11 description: > Return abrupt from predicate call. info: | diff --git a/test/built-ins/TypedArray/prototype/findIndex/return-index-predicate-result-is-true.js b/test/built-ins/TypedArray/prototype/findIndex/return-index-predicate-result-is-true.js index 9e4880f22..498e9ac3e 100644 --- a/test/built-ins/TypedArray/prototype/findIndex/return-index-predicate-result-is-true.js +++ b/test/built-ins/TypedArray/prototype/findIndex/return-index-predicate-result-is-true.js @@ -2,7 +2,6 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- esid: sec-%typedarray%.prototype.findindex -es6id: 22.2.3.11 description: > Return index if predicate return a boolean true value. info: | diff --git a/test/built-ins/TypedArray/prototype/findIndex/return-negative-one-if-predicate-returns-false-value.js b/test/built-ins/TypedArray/prototype/findIndex/return-negative-one-if-predicate-returns-false-value.js index f3367fbfa..76bda3ca0 100644 --- a/test/built-ins/TypedArray/prototype/findIndex/return-negative-one-if-predicate-returns-false-value.js +++ b/test/built-ins/TypedArray/prototype/findIndex/return-negative-one-if-predicate-returns-false-value.js @@ -2,7 +2,6 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- esid: sec-%typedarray%.prototype.findindex -es6id: 22.2.3.11 description: > Return -1 if predicate always returns a boolean false value. info: | |