summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Array/change-array-by-copy-cross-compartment-create.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/change-array-by-copy-cross-compartment-create.js
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.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/change-array-by-copy-cross-compartment-create.js')
-rw-r--r--js/src/tests/non262/Array/change-array-by-copy-cross-compartment-create.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/js/src/tests/non262/Array/change-array-by-copy-cross-compartment-create.js b/js/src/tests/non262/Array/change-array-by-copy-cross-compartment-create.js
new file mode 100644
index 0000000000..bd6e6d0a9f
--- /dev/null
+++ b/js/src/tests/non262/Array/change-array-by-copy-cross-compartment-create.js
@@ -0,0 +1,26 @@
+// |reftest| shell-option(--enable-change-array-by-copy) skip-if(!Array.prototype.with)
+
+function test(otherGlobal) {
+ let arrays = [
+ ["with", otherGlobal.Array.prototype.with.call([1,2,3], 1, 3)],
+ ["toSpliced", otherGlobal.Array.prototype.toSpliced.call([1, 2, 3], 0, 1, 4, 5)],
+ ["toReversed", otherGlobal.Array.prototype.toReversed.call([1, 2, 3])],
+ ["toSorted", otherGlobal.Array.prototype.toSorted.call([1, 2, 3], (x, y) => y > x)]
+ ]
+
+ // Test that calling each method in a different compartment returns an array, and that
+ // the returned array's prototype matches the other compartment's Array prototype,
+ // not this one.
+ for (const [name, arr] of arrays) {
+ assertEq(arr instanceof Array, false, name + " returned an instance of Array");
+ assertEq(arr instanceof otherGlobal.Array, true, name + " did not return an instance of new global's Array");
+ assertEq(Object.getPrototypeOf(arr) !== Object.getPrototypeOf([1, 2, 3]), true,
+ name + " returned an object with a prototype from the wrong realm");
+ }
+}
+
+test(newGlobal());
+test(newGlobal({newCompartment: true}));
+
+if (typeof reportCompare === "function")
+ reportCompare(0, 0);