summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/realms/nuking.js
blob: 1d0656a71603d2a95119379ef974a74f793183cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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);
} + ")()");