diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt')
18 files changed, 838 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-arguments-with-thisarg.js b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-arguments-with-thisarg.js new file mode 100644 index 0000000000..56fd8d933c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-arguments-with-thisarg.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.some +description: > + thisArg does not affect callbackfn arguments +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + var results = []; + var thisArg = ["test262", 0, "ecma262", 0]; + + sample.some(function() { + results.push(arguments); + }, thisArg); + + assert.sameValue(results.length, 3, "results.length"); + assert.sameValue(thisArg.length, 4, "thisArg.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], 42n, "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], 43n, "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], 44n, "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-arguments-without-thisarg.js b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-arguments-without-thisarg.js new file mode 100644 index 0000000000..072ab7652f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-arguments-without-thisarg.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.some +description: > + callbackfn arguments +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + var results = []; + + sample.some(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 3, "results.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], 42n, "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], 43n, "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], 44n, "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-detachbuffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-detachbuffer.js new file mode 100644 index 0000000000..d635b54ae2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-detachbuffer.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.some +description: > + Instance buffer can be detached during loop +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [detachArrayBuffer.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + sample.some(function() { + if (loops === 0) { + $DETACHBUFFER(sample.buffer); + } + loops++; + return false; + }); + + assert.sameValue(loops, 2); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-no-interaction-over-non-integer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-no-interaction-over-non-integer.js new file mode 100644 index 0000000000..1284e54378 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-no-interaction-over-non-integer.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.some +description: > + Does not interact over non-integer properties +info: | + 22.2.3.7 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([7n, 8n]); + + var results = []; + + sample.foo = 42; + sample[Symbol("1")] = 43; + + sample.some(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0][1], 0, "results[0][1] - key"); + assert.sameValue(results[1][1], 1, "results[1][1] - key"); + + assert.sameValue(results[0][0], 7n, "results[0][0] - value"); + assert.sameValue(results[1][0], 8n, "results[1][0] - value"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-not-callable-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-not-callable-throws.js new file mode 100644 index 0000000000..3480775715 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-not-callable-throws.js @@ -0,0 +1,71 @@ +// 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.some +description: Throws a TypeError if callbackfn is not callable +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.throws(TypeError, function() { + sample.some(); + }, "no args"); + + assert.throws(TypeError, function() { + sample.some(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.some(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.some("abc"); + }, "string"); + + assert.throws(TypeError, function() { + sample.some(1); + }, "number"); + + assert.throws(TypeError, function() { + sample.some(NaN); + }, "NaN"); + + assert.throws(TypeError, function() { + sample.some(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.some(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.some({}); + }, "{}"); + + assert.throws(TypeError, function() { + sample.some(sample); + }, "same typedArray instance"); + + assert.throws(TypeError, function() { + sample.some(Symbol("1")); + }, "symbol"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-not-called-on-empty.js b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-not-called-on-empty.js new file mode 100644 index 0000000000..d1295d2e0d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-not-called-on-empty.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.some +description: > + callbackfn is not called on empty instances +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + + new TA().some(function() { + called++; + }); + + assert.sameValue(called, 0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-return-does-not-change-instance.js b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-return-does-not-change-instance.js new file mode 100644 index 0000000000..af120f4266 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-return-does-not-change-instance.js @@ -0,0 +1,40 @@ +// 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.some +description: > + The callbackfn return does not change the instance +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n]); + + sample.some(function() { + return 0; + }); + + assert.sameValue(sample[0], 40n, "[0] == 40"); + assert.sameValue(sample[1], 41n, "[1] == 41"); + assert.sameValue(sample[2], 42n, "[2] == 42"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-returns-abrupt.js b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-returns-abrupt.js new file mode 100644 index 0000000000..c47bb27697 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-returns-abrupt.js @@ -0,0 +1,37 @@ +// 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.some +description: Returns abrupt from callbackfn +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + assert.throws(Test262Error, function() { + sample.some(function() { + throw new Test262Error(); + }); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-set-value-during-interaction.js b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-set-value-during-interaction.js new file mode 100644 index 0000000000..5a43c760f2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-set-value-during-interaction.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.some +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect.set, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + var newVal = 0n; + + sample.some(function(val, i) { + if (i > 0) { + assert.sameValue( + sample[i - 1], newVal - 1n, + "get the changed value during the loop" + ); + assert.sameValue( + Reflect.set(sample, 0, 7n), + true, + "re-set a value for sample[0]" + ); + } + assert.sameValue( + Reflect.set(sample, i, newVal), + true, + "set value during iteration" + ); + + newVal++; + }); + + assert.sameValue(sample[0], 7n, "changed values after iteration [0] == 7"); + assert.sameValue(sample[1], 1n, "changed values after iteration [1] == 1"); + assert.sameValue(sample[2], 2n, "changed values after iteration [2] == 2"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-this.js b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-this.js new file mode 100644 index 0000000000..1cadb33cd5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/callbackfn-this.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.some +description: > + callbackfn `this` value +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + ... + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var expected = (function() { return this; })(); +var thisArg = {}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + var results1 = []; + + sample.some(function() { + results1.push(this); + }); + + assert.sameValue(results1.length, 3, "results1"); + assert.sameValue(results1[0], expected, "without thisArg - [0]"); + assert.sameValue(results1[1], expected, "without thisArg - [1]"); + assert.sameValue(results1[2], expected, "without thisArg - [2]"); + + var results2 = []; + + sample.some(function() { + results2.push(this); + }, thisArg); + + assert.sameValue(results2.length, 3, "results2"); + assert.sameValue(results2[0], thisArg, "using thisArg - [0]"); + assert.sameValue(results2[1], thisArg, "using thisArg - [1]"); + assert.sameValue(results2[2], thisArg, "using thisArg - [2]"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/detached-buffer.js new file mode 100644 index 0000000000..4ad0d25690 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/some/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.some +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , 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 callbackfn = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.some(callbackfn); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/get-length-uses-internal-arraylength.js b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000..ce99b23118 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/get-length-uses-internal-arraylength.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.some +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(TypedArray.prototype, "length", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + var calls = 0; + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.some(function() { + calls++; + }); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert.sameValue(calls, 2, "iterations are not affected by custom length"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/return-abrupt-from-this-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000..193e8a2901 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,62 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// 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.some +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.some, + 'function', + 'implements TypedArray.prototype.some' +); + +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.some(() => {}); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.some(() => {}); + + 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 some operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.some(() => {}); + throw new Test262Error('some completed successfully'); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/returns-false-if-every-cb-returns-false.js b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/returns-false-if-every-cb-returns-false.js new file mode 100644 index 0000000000..c9e1ae5199 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/returns-false-if-every-cb-returns-false.js @@ -0,0 +1,45 @@ +// 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.some +description: > + Returns false if every callbackfn calls returns a coerced false. +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 7. Return true. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(42); + + [ + false, + "", + 0, + -0, + NaN, + undefined, + null + ].forEach(function(val) { + var called = 0; + var result = sample.some(function() { + called++; + return val; + }); + assert.sameValue(called, 42, "callbackfn called for each index property"); + assert.sameValue(result, false, "result is false - " + val); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/returns-true-if-any-cb-returns-true.js b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/returns-true-if-any-cb-returns-true.js new file mode 100644 index 0000000000..68c451481d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/returns-true-if-any-cb-returns-true.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.some +description: > + Returns true if any callbackfn returns a coerced true. +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + iii. If testResult is true, return true. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(42); + [ + true, + 1, + "test262", + s, + {}, + [], + -1, + Infinity, + -Infinity, + 0.1, + -0.1 + ].forEach(function(val) { + var called = 0; + var result = sample.some(function() { + called++; + if (called == 1) { + return false; + } + return val; + }); + assert.sameValue(called, 2, "callbackfn called for each index property"); + + var msg = "result is true - " + (val === s ? "symbol" : val); + assert.sameValue(result, true, msg); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/some/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; + } + } +} diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/values-are-not-cached.js b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/values-are-not-cached.js new file mode 100644 index 0000000000..38e4c0eade --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/some/BigInt/values-are-not-cached.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.some +description: > + Integer indexed values are not cached before iteration +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + sample.some(function(v, i) { + if (i < sample.length - 1) { + sample[i+1] = 42n; + } + + assert.sameValue( + v, 42n, "method does not cache values before callbackfn calls" + ); + }); +}); + +reportCompare(0, 0); |