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/fill.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/fill.js | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/js/src/tests/non262/TypedArray/fill.js b/js/src/tests/non262/TypedArray/fill.js new file mode 100644 index 0000000000..4349da06a9 --- /dev/null +++ b/js/src/tests/non262/TypedArray/fill.js @@ -0,0 +1,65 @@ +for (var constructor of anyTypedArrayConstructors) { + assertDeepEq(constructor.prototype.fill.length, 1); + + assertDeepEq(new constructor([]).fill(1), new constructor([])); + assertDeepEq(new constructor([1,1,1]).fill(2), new constructor([2,2,2])); + assertDeepEq(new constructor([1,1,1]).fill(2, 1), new constructor([1,2,2])); + assertDeepEq(new constructor([1,1,1]).fill(2, 1, 2), new constructor([1,2,1])); + assertDeepEq(new constructor([1,1,1]).fill(2, -2), new constructor([1,2,2])); + assertDeepEq(new constructor([1,1,1]).fill(2, -2, -1), new constructor([1,2,1])); + assertDeepEq(new constructor([1,1,1]).fill(2, undefined), new constructor([2,2,2])); + assertDeepEq(new constructor([1,1,1]).fill(2, undefined, undefined), new constructor([2,2,2])); + assertDeepEq(new constructor([1,1,1]).fill(2, 1, undefined), new constructor([1,2,2])); + assertDeepEq(new constructor([1,1,1]).fill(2, undefined, 1), new constructor([2,1,1])); + assertDeepEq(new constructor([1,1,1]).fill(2, 2, 1), new constructor([1,1,1])); + assertDeepEq(new constructor([1,1,1]).fill(2, -1, 1), new constructor([1,1,1])); + assertDeepEq(new constructor([1,1,1]).fill(2, -2, 1), new constructor([1,1,1])); + assertDeepEq(new constructor([1,1,1]).fill(2, 1, -2), new constructor([1,1,1])); + assertDeepEq(new constructor([1,1,1]).fill(2, 0.1), new constructor([2,2,2])); + assertDeepEq(new constructor([1,1,1]).fill(2, 0.9), new constructor([2,2,2])); + assertDeepEq(new constructor([1,1,1]).fill(2, 1.1), new constructor([1,2,2])); + assertDeepEq(new constructor([1,1,1]).fill(2, 0.1, 0.9), new constructor([1,1,1])); + assertDeepEq(new constructor([1,1,1]).fill(2, 0.1, 1.9), new constructor([2,1,1])); + assertDeepEq(new constructor([1,1,1]).fill(2, 0.1, 1.9), new constructor([2,1,1])); + assertDeepEq(new constructor([1,1,1]).fill(2, -0), new constructor([2,2,2])); + assertDeepEq(new constructor([1,1,1]).fill(2, 0, -0), new constructor([1,1,1])); + assertDeepEq(new constructor([1,1,1]).fill(2, NaN), new constructor([2,2,2])); + assertDeepEq(new constructor([1,1,1]).fill(2, 0, NaN), new constructor([1,1,1])); + assertDeepEq(new constructor([1,1,1]).fill(2, false), new constructor([2,2,2])); + assertDeepEq(new constructor([1,1,1]).fill(2, true), new constructor([1,2,2])); + assertDeepEq(new constructor([1,1,1]).fill(2, "0"), new constructor([2,2,2])); + assertDeepEq(new constructor([1,1,1]).fill(2, "1"), new constructor([1,2,2])); + assertDeepEq(new constructor([1,1,1]).fill(2, "-2"), new constructor([1,2,2])); + assertDeepEq(new constructor([1,1,1]).fill(2, "-2", "-1"), new constructor([1,2,1])); + assertDeepEq(new constructor([1,1,1]).fill(2, {valueOf: ()=>1}), new constructor([1,2,2])); + assertDeepEq(new constructor([1,1,1]).fill(2, 0, {valueOf: ()=>1}), new constructor([2,1,1])); + + // Called from other globals. + if (typeof newGlobal === "function") { + var fill = newGlobal()[constructor.name].prototype.fill; + assertDeepEq(fill.call(new constructor([3, 2, 1]), 2), new constructor([2, 2, 2])); + } + + // Throws if `this` isn't a TypedArray. + var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, + new Proxy(new constructor(), {})]; + invalidReceivers.forEach(invalidReceiver => { + assertThrowsInstanceOf(() => { + constructor.prototype.fill.call(invalidReceiver, 1); + }, TypeError); + }); + + // Test that the length getter is never called. + Object.defineProperty(new constructor([1, 2, 3]), "length", { + get() { + throw new Error("length accessor called"); + } + }).fill(1); +} + +for (let constructor of anyTypedArrayConstructors.filter(isFloatConstructor)) { + assertDeepEq(new constructor([0, 0]).fill(NaN), new constructor([NaN, NaN])); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); |