summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/gc/bug-1643913.js
blob: 1f83a9a0a356da5e07ac1675b1cc0c2ea847c71c (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
gczeal(0);

for (let p of [false, true]) {
  f(p);

  // Run an incremental GC to completion.
  startgc(1);
  while (gcstate() !== 'NotActive') {
    gcslice(10000, { dontStart: true });
  }
}

function ccwToObject() {
  return evalcx('({})', newGlobal({newCompartment: true}));
}

function ccwToRegistry() {
  return evalcx('new FinalizationRegistry(value => {})',
                newGlobal({newCompartment: true}));
}

function f(p) {
  let registry = ccwToRegistry();
  let target = ccwToObject();
  registry.register(target, undefined);

  // Add a CCW from registry to target zone or vice versa to control
  // the order the zones are swept in.
  if (p) {
    registry.ptr = target;
  } else {
    target.ptr = registry;
  }

  gc();
}