7 onmessage = (event) => {
16 throw "Unknown message";
20 function startTest() {
21 // Registry with no registered objects.
22 let registry1 = new FinalizationRegistry(v => { holdings1.push(v); });
24 // Registry with three registered objects.
25 let registry2 = new FinalizationRegistry(v => { holdings2.push(v); });
26 registry2.register({}, 1);
27 registry2.register({}, 2);
28 registry2.register({}, 3);
30 // Registry with registered object that is then unregistered.
31 let registry3 = new FinalizationRegistry(v => { holdings3.push(v); });
33 registry3.register({}, 1, token3);
34 registry3.unregister(token3);
36 // Registry with registered object that doesn't die.
37 let registry4 = new FinalizationRegistry(v => { holdings4.push(v); });
39 registry4.register(object4, 1);
41 // Registry observing cyclic JS data structure.
42 let registry5 = new FinalizationRegistry(v => { holdings5.push(v); });
43 registry5.register(makeJSCycle(4), 5);
45 const { gc } = getJSTestingFunctions();
48 Promise.resolve().then(() => {
52 postMessage('started');
55 function checkNoCallbacks() {
56 is(holdings1.length, 0);
57 is(holdings2.length, 0);
58 is(holdings3.length, 0);
59 is(holdings4.length, 0);
60 is(holdings5.length, 0);
63 function checkResults() {
64 is(holdings1.length, 0);
66 let result = holdings2.sort((a, b) => a - b);
72 is(holdings3.length, 0);
73 is(holdings4.length, 0);
75 is(holdings5.length, 1);
78 postMessage('passed');
83 throw `Expected ${b} but got ${a}`;
87 function makeJSCycle(size) {
90 for (let i = 0; i < size; i++) {
92 current = current.next;