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/Array/change-array-by-copy-errors-from-correct-realm.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/Array/change-array-by-copy-errors-from-correct-realm.js | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/js/src/tests/non262/Array/change-array-by-copy-errors-from-correct-realm.js b/js/src/tests/non262/Array/change-array-by-copy-errors-from-correct-realm.js new file mode 100644 index 0000000000..4e99cbe0ff --- /dev/null +++ b/js/src/tests/non262/Array/change-array-by-copy-errors-from-correct-realm.js @@ -0,0 +1,77 @@ +// |reftest| shell-option(--enable-change-array-by-copy) skip-if(!Array.prototype.with) + +function test(otherGlobal) { + assertEq(TypeError !== otherGlobal.TypeError, true); + assertEq(Object.getPrototypeOf(TypeError) !== Object.getPrototypeOf(otherGlobal.TypeError), true); + assertEq(RangeError !== otherGlobal.RangeError, true); + assertEq(Object.getPrototypeOf(RangeError) !== Object.getPrototypeOf(otherGlobal.RangeError), true); + + + var arrayLike = { + get "0"() { + throw new Error("Get 0"); + }, + get "4294967295" () { // 2 ** 32 - 1 + throw new Error("Get 2147483648"); + }, + get "4294967296" () { // 2 ** 32 + throw new Error("Get 2147483648"); + }, + length: 2 ** 32 + }; + + let gToSorted = otherGlobal.Array.prototype.toSorted; + let gToSpliced = otherGlobal.Array.prototype.toSpliced; + let gToReversed = otherGlobal.Array.prototype.toReversed; + let gWith = otherGlobal.Array.prototype.with; + + let typeErrorCalls = [ + ["toSorted - bad comparator", () => gToSorted.call([], 5)], + ["toSorted - this is null", () => gToSorted.call(null)], + ["toSpliced - array too long", () => { + var oldLen = arrayLike.length; + arrayLike.length = 2**53 - 1; + gToSpliced.call(arrayLike, 0, 0, 1); + arrayLike.length = oldLen; + }] + ] + + let rangeErrorCalls = [ + ["toSorted - array too long", () => gToSorted.call(arrayLike)], + ["toReversed - array too long", () => gToReversed.call(arrayLike)], + ["toSpliced - adding elements would exceed max array length", () => gToSpliced.call(arrayLike, 0, 0)], + ["with - index out of range", () => gWith.call([0, 1, 2], 3, 7)], + ["with - negative index", () => gWith.call([0, 1, 2], -4, 7)], + ["with - array too long", () => gWith.call(arrayLike, 0, 0)] + ] + + // For each erroneous case, make sure the error comes from + // the other realm (not this realm) + for (const [message, f] of typeErrorCalls) { + try { + f(); + } catch (exc) { + assertEq(exc instanceof TypeError, false, message + " threw TypeError from wrong realm"); + assertEq(exc instanceof otherGlobal.TypeError, true, message + " didn't throw TypeError from other realm"); + assertEq(Object.getPrototypeOf(exc) !== Object.getPrototypeOf(TypeError), true, + message + " TypeError has wrong prototype"); + } + } + + for (const [message, f] of rangeErrorCalls) { + try { + f(); + } catch (exc) { + assertEq(exc instanceof RangeError, false, message + " threw RangeError from wrong realm"); + assertEq(exc instanceof otherGlobal.RangeError, true, message + " didn't throw RangeError from other realm"); + assertEq(Object.getPrototypeOf(exc) !== Object.getPrototypeOf(RangeError), true, + message + " TypeError has wrong prototype"); + } + } +} + +test(newGlobal()); +test(newGlobal({newCompartment: true})); + +if (typeof reportCompare === "function") + reportCompare(0, 0); |