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/join.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/join.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/js/src/tests/non262/TypedArray/join.js b/js/src/tests/non262/TypedArray/join.js new file mode 100644 index 0000000000..0e797320fd --- /dev/null +++ b/js/src/tests/non262/TypedArray/join.js @@ -0,0 +1,48 @@ +for (var constructor of anyTypedArrayConstructors) { + assertEq(constructor.prototype.join.length, 1); + + assertEq(new constructor([1, 2, 3]).join(), "1,2,3"); + assertEq(new constructor([1, 2, 3]).join(undefined), "1,2,3"); + assertEq(new constructor([1, 2, 3]).join(null), "1null2null3"); + assertEq(new constructor([1, 2, 3]).join(""), "123"); + assertEq(new constructor([1, 2, 3]).join("+"), "1+2+3"); + assertEq(new constructor([1, 2, 3]).join(.1), "10.120.13"); + assertEq(new constructor([1, 2, 3]).join({toString(){return "foo"}}), "1foo2foo3"); + assertEq(new constructor([1]).join("-"), "1"); + assertEq(new constructor().join(), ""); + assertEq(new constructor().join("*"), ""); + assertEq(new constructor(1).join(), "0"); + assertEq(new constructor(3).join(), "0,0,0"); + + assertThrowsInstanceOf(() => new constructor().join({toString(){throw new TypeError}}), TypeError); + assertThrowsInstanceOf(() => new constructor().join(Symbol()), TypeError); + + // Called from other globals. + if (typeof newGlobal === "function") { + var join = newGlobal()[constructor.name].prototype.join; + assertEq(join.call(new constructor([1, 2, 3]), "\t"), "1\t2\t3"); + } + + // Throws if `this` isn't a TypedArray. + var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, + new Proxy(new constructor(), {})]; + invalidReceivers.forEach(invalidReceiver => { + assertThrowsInstanceOf(() => { + constructor.prototype.join.call(invalidReceiver); + }, TypeError, "Assert that join 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"); + } + }).join("\0"), "1\0002\0003"); +} + +for (let constructor of anyTypedArrayConstructors.filter(isFloatConstructor)) { + assertDeepEq(new constructor([null, , NaN]).join(), "0,NaN,NaN"); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); |