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/non262/TypedArray/at.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.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/non262/TypedArray/at.js')
-rw-r--r-- | js/src/tests/non262/TypedArray/at.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/js/src/tests/non262/TypedArray/at.js b/js/src/tests/non262/TypedArray/at.js new file mode 100644 index 0000000000..bab5dc8ff2 --- /dev/null +++ b/js/src/tests/non262/TypedArray/at.js @@ -0,0 +1,47 @@ +for (var constructor of anyTypedArrayConstructors) { + assertEq(constructor.prototype.at.length, 1); + + assertEq(new constructor([0]).at(0), 0); + assertEq(new constructor([0]).at(-1), 0); + + assertEq(new constructor([]).at(0), undefined); + assertEq(new constructor([]).at(-1), undefined); + assertEq(new constructor([]).at(1), undefined); + + assertEq(new constructor([0, 1]).at(0), 0); + assertEq(new constructor([0, 1]).at(1), 1); + assertEq(new constructor([0, 1]).at(-2), 0); + assertEq(new constructor([0, 1]).at(-1), 1); + + assertEq(new constructor([0, 1]).at(2), undefined); + assertEq(new constructor([0, 1]).at(-3), undefined); + assertEq(new constructor([0, 1]).at(-4), undefined); + assertEq(new constructor([0, 1]).at(Infinity), undefined); + assertEq(new constructor([0, 1]).at(-Infinity), undefined); + assertEq(new constructor([0, 1]).at(NaN), 0); // ToInteger(NaN) = 0 + + // Called from other globals. + if (typeof newGlobal === "function") { + var at = newGlobal()[constructor.name].prototype.at; + assertEq(at.call(new constructor([1, 2, 3]), 2), 3); + } + + // Throws if `this` isn't a TypedArray. + var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, + new Proxy(new constructor(), {})]; + invalidReceivers.forEach(invalidReceiver => { + assertThrowsInstanceOf(() => { + constructor.prototype.at.call(invalidReceiver); + }, TypeError, "Assert that 'at' fails if this value is not a TypedArray"); + }); + + // Test that the length getter is never called. + assertEq(Object.defineProperty(new constructor([1, 2, 3]), "length", { + get() { + throw new Error("length accessor called"); + } + }).at(1), 2); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); |