5 <title>Test FinalizationRegistry tracks its incumbent global
</title>
6 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
7 <script type=
"application/javascript">
8 let resolvePromise, rejectPromise;
10 async function runTest(global, callback) {
11 let fr = new global.FinalizationRegistry(callback);
12 fr.register({}, undefined);
14 SpecialPowers.DOMWindowUtils.garbageCollect();
16 let promise = new Promise((resolve, reject) =
> {
17 resolvePromise = resolve;
18 rejectPromise = reject;
24 function receiveMessage(event) {
25 resolvePromise(event.source.sourceName);
29 // This test uses FinalizationRegistry to trigger a callback and reports
30 // the incumbent global in the callback using postMessage. In all cases
31 // the author function that scheduled the callback is runTest(), so the
32 // incumbent global should be the main window.
34 SimpleTest.waitForExplicitFinish();
36 window.sourceName =
"main";
37 window.addEventListener(
"message", receiveMessage, false);
39 let other = window.frames[
0];
40 other.sourceName =
"other";
41 other.addEventListener(
"message", receiveMessage, false);
43 is(await runTest(window, v =
> window.postMessage(v)),
"main");
44 is(await runTest(window, window.postMessage.bind(window)),
"main");
45 is(await runTest(other, v =
> other.postMessage(v)),
"main");
46 is(await runTest(other, other.postMessage.bind(other)),
"main");
47 is(await runTest(window, v =
> other.postMessage(v)),
"main");
48 is(await runTest(window, other.postMessage.bind(other)),
"main");
49 is(await runTest(other, v =
> window.postMessage(v)),
"main");
50 is(await runTest(other, window.postMessage.bind(window)),
"main");
57 <div style=
"display: none">
58 <!-- A subframe so we have another global to work with -->