From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../TypedArray/prototype/find/BigInt/browser.js | 0 .../prototype/find/BigInt/detached-buffer.js | 34 +++++++++ .../find/BigInt/get-length-ignores-length-prop.js | 56 +++++++++++++++ .../find/BigInt/predicate-call-changes-value.js | 80 ++++++++++++++++++++++ .../find/BigInt/predicate-call-parameters.js | 64 +++++++++++++++++ .../find/BigInt/predicate-call-this-non-strict.js | 61 +++++++++++++++++ .../BigInt/predicate-call-this-strict-strict.js | 56 +++++++++++++++ .../BigInt/predicate-is-not-callable-throws.js | 68 ++++++++++++++++++ .../find/BigInt/predicate-may-detach-buffer.js | 59 ++++++++++++++++ .../BigInt/predicate-not-called-on-empty-array.js | 51 ++++++++++++++ .../BigInt/return-abrupt-from-predicate-call.js | 42 ++++++++++++ .../return-abrupt-from-this-out-of-bounds.js | 62 +++++++++++++++++ .../return-found-value-predicate-result-is-true.js | 67 ++++++++++++++++++ ...n-undefined-if-predicate-returns-false-value.js | 62 +++++++++++++++++ .../TypedArray/prototype/find/BigInt/shell.js | 42 ++++++++++++ 15 files changed, 804 insertions(+) create mode 100644 js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/browser.js create mode 100644 js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/detached-buffer.js create mode 100644 js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/get-length-ignores-length-prop.js create mode 100644 js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/predicate-call-changes-value.js create mode 100644 js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/predicate-call-parameters.js create mode 100644 js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/predicate-call-this-non-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/predicate-call-this-strict-strict.js create mode 100644 js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/predicate-is-not-callable-throws.js create mode 100644 js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/predicate-may-detach-buffer.js create mode 100644 js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/predicate-not-called-on-empty-array.js create mode 100644 js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/return-abrupt-from-predicate-call.js create mode 100644 js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/return-abrupt-from-this-out-of-bounds.js create mode 100644 js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/return-found-value-predicate-result-is-true.js create mode 100644 js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/return-undefined-if-predicate-returns-false-value.js create mode 100644 js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/shell.js (limited to 'js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt') diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/detached-buffer.js new file mode 100644 index 0000000000..51b7d60af4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/detached-buffer.js @@ -0,0 +1,34 @@ +// 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.find +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.10 %TypedArray%.prototype.find (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.find(predicate); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/get-length-ignores-length-prop.js b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/get-length-ignores-length-prop.js new file mode 100644 index 0000000000..05b01d3167 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/get-length-ignores-length-prop.js @@ -0,0 +1,56 @@ +// 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.find +description: > + [[Get]] of "length" uses [[ArrayLength]] +info: | + 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + %TypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( 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.find(function() { return true; }), + 42n + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/predicate-call-changes-value.js b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/predicate-call-changes-value.js new file mode 100644 index 0000000000..64667d84a6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/predicate-call-changes-value.js @@ -0,0 +1,80 @@ +// 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.find +description: > + Change values during predicate call +info: | + 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + %TypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( 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: [compareArray.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var arr = [1n, 2n, 3n]; + var sample; + var result; + + sample = new TA(3); + sample.find(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.find(function(val, i) { + if ( i === 0 ) { + sample[2] = 7n; + } + return val === 7n; + }); + assert.sameValue(result, 7n, "value found"); + + sample = new TA(arr); + result = sample.find(function(val, i) { + if ( i === 0 ) { + sample[2] = 7n; + } + return val === 3n; + }); + assert.sameValue(result, undefined, "value not found"); + + sample = new TA(arr); + result = sample.find(function(val, i) { + if ( i > 0 ) { + sample[0] = 7n; + } + return val === 7n; + }); + assert.sameValue(result, undefined, "value not found - changed after call"); + + sample = new TA(arr); + result = sample.find(function() { + sample[0] = 7n; + return true; + }); + assert.sameValue(result, 1n, "find() returns previous found value"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/predicate-call-parameters.js b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/predicate-call-parameters.js new file mode 100644 index 0000000000..ab3bb965ba --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/predicate-call-parameters.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.find +description: > + Predicate called as F.call( thisArg, kValue, k, O ) for each array entry. +info: | + 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + %TypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( 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.find(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"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/predicate-call-this-non-strict.js b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/predicate-call-this-non-strict.js new file mode 100644 index 0000000000..cbfc687e78 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/predicate-call-this-non-strict.js @@ -0,0 +1,61 @@ +// 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.find +description: > + Verify predicate this on non-strict mode +info: | + 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + %TypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 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.find(function() { + result = this; + }); + + assert.sameValue(result, T, "without thisArg, predicate this is the global"); + + result = null; + sample.find(function() { + result = this; + }, undefined); + + assert.sameValue(result, T, "predicate this is the global when thisArg is undefined"); + + var o = {}; + result = null; + sample.find(function() { + result = this; + }, o); + + assert.sameValue(result, o, "thisArg becomes the predicate this"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/predicate-call-this-strict-strict.js b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/predicate-call-this-strict-strict.js new file mode 100644 index 0000000000..9c5c07eba5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/predicate-call-this-strict-strict.js @@ -0,0 +1,56 @@ +'use strict'; +// 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.find +description: > + Verify predicate this on strict mode +info: | + 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + %TypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 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.find(function() { + result = this; + }); + + assert.sameValue( + result, + undefined, + "without thisArg, predicate this is undefined" + ); + + var o = {}; + sample.find(function() { + result = this; + }, o); + + assert.sameValue(result, o, "thisArg becomes the predicate this"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/predicate-is-not-callable-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/predicate-is-not-callable-throws.js new file mode 100644 index 0000000000..149b44b285 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/predicate-is-not-callable-throws.js @@ -0,0 +1,68 @@ +// 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.find +description: > + Throws a TypeError exception if predicate is not callable. +info: | + 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + %TypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( 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.find({}); + }, "object"); + + assert.throws(TypeError, function() { + sample.find(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.find(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.find(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.find(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.find(1); + }, "number"); + + assert.throws(TypeError, function() { + sample.find(""); + }, "string"); + + assert.throws(TypeError, function() { + sample.find([]); + }, "array"); + + assert.throws(TypeError, function() { + sample.find(/./); + }, "regexp"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/predicate-may-detach-buffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/predicate-may-detach-buffer.js new file mode 100644 index 0000000000..0cb8181ca1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/predicate-may-detach-buffer.js @@ -0,0 +1,59 @@ +// 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.find +description: > + Predicate may detach the buffer +info: | + %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + %TypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 + + ... + + However, such optimization must not introduce any observable changes in the + specified behaviour of the algorithm and must take into account the + possibility that calls to predicate may cause the this value to become + detached. + + + Array.prototype.find ( predicate[ , thisArg ] ) + + Let O be ? ToObject(this value). + Let len be ? LengthOfArrayLike(O). + If IsCallable(predicate) is false, throw a TypeError exception. + Let k be 0. + Repeat, while k < len, + Let Pk be ! ToString(𝔽(k)). + Let kValue be ? Get(O, Pk). + Let testResult be ! ToBoolean(? Call(predicate, thisArg, « kValue, 𝔽(k), O »)). + If testResult is true, return kValue. + Set k to k + 1. + Return undefined. + + IntegerIndexedElementGet ( O, index ) + + ... + Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + If IsDetachedBuffer(buffer) is true, return undefined. + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + sample.find(function() { + if (loops === 0) { + $DETACHBUFFER(sample.buffer); + } + loops++; + }); + + assert.sameValue(loops, 2); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/predicate-not-called-on-empty-array.js b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/predicate-not-called-on-empty-array.js new file mode 100644 index 0000000000..7c863b77c2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/predicate-not-called-on-empty-array.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.find +description: > + Predicate is not called on empty instances +info: | + 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + %TypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 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(); + var called = false; + + var result = sample.find(function() { + called = true; + return true; + }); + + assert.sameValue( + called, + false, + "empty instance does not call predicate" + ); + assert.sameValue( + result, + undefined, + "find returns undefined when predicate is not called" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/return-abrupt-from-predicate-call.js b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/return-abrupt-from-predicate-call.js new file mode 100644 index 0000000000..406a6618f9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/return-abrupt-from-predicate-call.js @@ -0,0 +1,42 @@ +// 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.find +description: > + Return abrupt from predicate call. +info: | + 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + %TypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 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(1); + + var predicate = function() { + throw new Test262Error(); + }; + + assert.throws(Test262Error, function() { + sample.find(predicate); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/return-abrupt-from-this-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000..2025d13dd8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,62 @@ +// |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-%typedarray%.prototype.find +description: Return abrupt when "this" value fails buffer boundary checks +includes: [testBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, TypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof TypedArray.prototype.find, + 'function', + 'implements TypedArray.prototype.find' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.find(() => {}); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.find(() => {}); + + var expectedError; + try { + ab.resize(BPE * 2); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the find operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.find(() => {}); + throw new Test262Error('find completed successfully'); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/return-found-value-predicate-result-is-true.js b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/return-found-value-predicate-result-is-true.js new file mode 100644 index 0000000000..a5c977152a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/return-found-value-predicate-result-is-true.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.find +description: > + Return found value if predicate return a boolean true value. +info: | + 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + %TypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + d. If testResult is true, return kValue. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([39n, 2n, 62n]); + var called, result; + + called = 0; + result = sample.find(function() { + called++; + return true; + }); + assert.sameValue(result, 39n, "returned true on sample[0]"); + assert.sameValue(called, 1, "predicate was called once"); + + called = 0; + result = sample.find(function(val) { + called++; + return val === 62n; + }); + assert.sameValue(called, 3, "predicate was called three times"); + assert.sameValue(result, 62n, "returned true on sample[3]"); + + result = sample.find(function() { return "string"; }); + assert.sameValue(result, 39n, "ToBoolean(string)"); + + result = sample.find(function() { return {}; }); + assert.sameValue(result, 39n, "ToBoolean(object)"); + + result = sample.find(function() { return Symbol(""); }); + assert.sameValue(result, 39n, "ToBoolean(symbol)"); + + result = sample.find(function() { return 1; }); + assert.sameValue(result, 39n, "ToBoolean(number)"); + + result = sample.find(function() { return -1; }); + assert.sameValue(result, 39n, "ToBoolean(negative number)"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/return-undefined-if-predicate-returns-false-value.js b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/return-undefined-if-predicate-returns-false-value.js new file mode 100644 index 0000000000..43714b5e4a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/return-undefined-if-predicate-returns-false-value.js @@ -0,0 +1,62 @@ +// 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.find +description: > + Return undefined if predicate always returns a boolean false value. +info: | + 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + %TypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... + 7. Return undefined. +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + var called = 0; + + var result = sample.find(function() { + called++; + return false; + }); + + assert.sameValue(called, 3, "predicate was called three times"); + assert.sameValue(result, undefined); + + result = sample.find(function() { return ""; }); + assert.sameValue(result, undefined, "ToBoolean(empty string)"); + + result = sample.find(function() { return undefined; }); + assert.sameValue(result, undefined, "ToBoolean(undefined)"); + + result = sample.find(function() { return null; }); + assert.sameValue(result, undefined, "ToBoolean(null)"); + + result = sample.find(function() { return 0; }); + assert.sameValue(result, undefined, "ToBoolean(0)"); + + result = sample.find(function() { return -0; }); + assert.sameValue(result, undefined, "ToBoolean(-0)"); + + result = sample.find(function() { return NaN; }); + assert.sameValue(result, undefined, "ToBoolean(NaN)"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/find/BigInt/shell.js @@ -0,0 +1,42 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.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 BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * 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 testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + 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; + } + } +} -- cgit v1.2.3