summaryrefslogtreecommitdiffstats
path: root/js/src/tests/ecma_6/Array/to-length.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /js/src/tests/ecma_6/Array/to-length.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/tests/ecma_6/Array/to-length.js')
-rw-r--r--js/src/tests/ecma_6/Array/to-length.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/js/src/tests/ecma_6/Array/to-length.js b/js/src/tests/ecma_6/Array/to-length.js
new file mode 100644
index 000000000..d6b4c6d7c
--- /dev/null
+++ b/js/src/tests/ecma_6/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);