summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/realms/nuking.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/jit-test/tests/realms/nuking.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--js/src/jit-test/tests/realms/nuking.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/realms/nuking.js b/js/src/jit-test/tests/realms/nuking.js
new file mode 100644
index 0000000000..1d0656a716
--- /dev/null
+++ b/js/src/jit-test/tests/realms/nuking.js
@@ -0,0 +1,49 @@
+// Ensure nuking happens on a single target realm instead of compartment.
+
+var g1 = newGlobal({newCompartment: true});
+var g2 = newGlobal({sameCompartmentAs: g1});
+g2.other = g1;
+
+var o1 = g1.Math;
+var o2 = g2.Math;
+
+g1.nukeAllCCWs();
+
+// o1 is now dead.
+ex = null;
+try {
+ assertEq(o1.abs(1), 1);
+} catch (e) {
+ ex = e;
+}
+assertEq(ex.toString().includes("dead object"), true);
+
+// o2 still works.
+assertEq(o2.abs(1), 1);
+
+// g2 can still access g1 because they're same-compartment.
+assertEq(g2.evaluate("other.Math.abs(-2)"), 2);
+
+// Attempting to create a new wrapper targeting nuked realm g1 should return a
+// dead wrapper now. Note that we can't use g1 directly because that's now a
+// dead object, so we try to get to g1 via g2.
+ex = null;
+try {
+ g2.other.toString();
+} catch (e) {
+ ex = e;
+}
+assertEq(ex.toString().includes("dead object"), true);
+
+// Nuke g2 too. We have nuked all realms in its compartment so we should now
+// throw if we try to create a new outgoing wrapper.
+g2.evaluate("(" + function() {
+ nukeAllCCWs();
+ var ex = null;
+ try {
+ newGlobal({newCompartment: true}).Array();
+ } catch (e) {
+ ex = e;
+ }
+ assertEq(ex.toString().includes('dead object'), true);
+} + ")()");