summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Array/to-length.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/Array/to-length.js
parentInitial commit. (diff)
downloadfirefox-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/non262/Array/to-length.js')
-rw-r--r--js/src/tests/non262/Array/to-length.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/js/src/tests/non262/Array/to-length.js b/js/src/tests/non262/Array/to-length.js
new file mode 100644
index 0000000000..d6b4c6d7cd
--- /dev/null
+++ b/js/src/tests/non262/Array/to-length.js
@@ -0,0 +1,40 @@
+const max = Number.MAX_SAFE_INTEGER;
+
+assertEq(Array.prototype.indexOf.call({length: Infinity, [max - 1]: 'test'}, 'test', max - 3), max - 1);
+assertEq(Array.prototype.lastIndexOf.call({length: Infinity, [max - 2]: 'test', [max - 1]: 'test2'}, 'test'), max - 2);
+
+// ToLength doesn't truncate Infinity to zero, so the callback should be invoked
+assertThrowsValue(() => Array.prototype.every.call({length: Infinity, [0]: undefined}, () => { throw "invoked" }), "invoked");
+assertThrowsValue(() => Array.prototype.some.call({length: Infinity, [0]: undefined}, () => { throw "invoked" }), "invoked");
+// Timeout before calling our callback
+// assertThrowsValue(() => Array.prototype.sort.call({length: Infinity}, () => { throw "invoked" }), "invoked");
+assertThrowsValue(() => Array.prototype.forEach.call({length: Infinity, [0]: undefined}, () => { throw "invoked" }), "invoked");
+assertThrowsValue(() => Array.prototype.filter.call({length: Infinity, [0]: undefined}, () => { throw "invoked" }), "invoked");
+assertThrowsValue(() => Array.prototype.reduce.call({length: Infinity, [0]: undefined, [1]: undefined}, () => { throw "invoked" }), "invoked");
+assertThrowsValue(() => Array.prototype.reduceRight.call({length: Infinity, [max - 1]: undefined, [max - 2]: undefined}, () => { throw "invoked" }), "invoked");
+assertThrowsValue(() => Array.prototype.find.call({length: Infinity}, () => { throw "invoked" }), "invoked");
+assertThrowsValue(() => Array.prototype.findIndex.call({length: Infinity}, () => { throw "invoked" }), "invoked");
+assertThrowsValue(() => Array.prototype.fill.call({length: Infinity, set "0"(v) { throw "invoked"; }}, () => { throw "invoked" }), "invoked");
+assertThrowsValue(() => Array.prototype.copyWithin.call({length: Infinity, get [max - 2]() { throw "invoked"; }}, max - 2, max - 2), "invoked");
+
+assertEq(Array.prototype.includes.call({length: Infinity, [max - 1]: "test"}, "test", max - 3), true);
+
+// Invoking the Array constructor with MAX_SAFE_INTEGER will throw, 0 won't
+assertThrowsInstanceOf(() => Array.from({length: Infinity}), RangeError);
+
+// Make sure ArraySpeciesCreate is called with ToLength applied to the length property
+var proxy = new Proxy([], {
+ get(target, property) {
+ if (property === "length")
+ return Infinity;
+
+ assertEq(property, "constructor");
+ function fakeConstructor(length) { assertEq(length, max); throw "invoked"; };
+ fakeConstructor[Symbol.species] = fakeConstructor;
+ return fakeConstructor;
+ }
+})
+assertThrowsValue(() => Array.prototype.map.call(proxy, () => { }), "invoked");
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);