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/includes.js | |
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 '')
-rw-r--r-- | js/src/tests/non262/TypedArray/includes.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/js/src/tests/non262/TypedArray/includes.js b/js/src/tests/non262/TypedArray/includes.js new file mode 100644 index 0000000000..bcc50a2572 --- /dev/null +++ b/js/src/tests/non262/TypedArray/includes.js @@ -0,0 +1,40 @@ +for (var constructor of anyTypedArrayConstructors) { + assertEq(constructor.prototype.includes.length, 1); + + assertEq(new constructor([1, 2, 3]).includes(1), true); + assertEq(new constructor([1, 2, 3]).includes(2), true); + assertEq(new constructor([1, 2, 3]).includes(3), true); + assertEq(new constructor([1, 2, 3]).includes(2, 1), true); + assertEq(new constructor([1, 2, 3]).includes(2, -2), true); + assertEq(new constructor([1, 2, 3]).includes(2, -100), true); + + assertEq(new constructor([1, 2, 3]).includes("2"), false); + assertEq(new constructor([1, 2, 3]).includes(2, 2), false); + assertEq(new constructor([1, 2, 3]).includes(2, -1), false); + assertEq(new constructor([1, 2, 3]).includes(2, 100), false); + + // Called from other globals. + if (typeof newGlobal === "function") { + var includes = newGlobal()[constructor.name].prototype.includes; + assertEq(includes.call(new constructor([1, 2, 3]), 2), true); + } + + // Throws if `this` isn't a TypedArray. + var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, + new Proxy(new constructor(), {})]; + invalidReceivers.forEach(invalidReceiver => { + assertThrowsInstanceOf(() => { + constructor.prototype.includes.call(invalidReceiver); + }, TypeError, "Assert that reverse 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"); + } + }).includes(2), true); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); |