Bug 1915045 Ensure decode tasks are scheduled on BufferingState::Enter() r=media...
[gecko.git] / js / xpconnect / tests / mochitest / test_weakRefs_collected_wrapper.html
blobc7af313d96212225f5b9de6744fba6f2873b4cfc
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>Test WeakRefs with DOM wrappers that get cycle collected</title>
6 <script src="/tests/SimpleTest/SimpleTest.js"></script>
7 <script type="application/javascript">
8 let weakrefs = [];
10 function go() {
11 SimpleTest.waitForExplicitFinish();
13 // 1. nsISupports-derived object.
14 let doc = document.implementation.createHTMLDocument();
15 weakrefs.push(new WeakRef(doc));
17 // 2. non-nsISupports-derived object.
18 let buffer = new AudioBuffer({length: 1, sampleRate: 8000});
19 weakrefs.push(new WeakRef(buffer));
21 // 3. nsISupports non-wrapper-cached object.
22 let image = new ImageData(1, 1);
23 weakrefs.push(new WeakRef(image));
25 // 4. non-nsISupports non-wrapper-cached object.
26 let iterator = document.fonts.values();
27 weakrefs.push(new WeakRef(iterator));
29 for (let wr of weakrefs) {
30 isnot(wr.deref(), undefined, "Check that live wrapper is returned");
33 // setTimeout will call its callback in a new task.
34 setTimeout(task2, 0);
37 function task2() {
38 // Trigger a GC and CC to collect the DOM objects, but no GC to
39 // collect the wrappers.
40 SpecialPowers.DOMWindowUtils.garbageCollect();
41 SpecialPowers.DOMWindowUtils.cycleCollect();
43 for (let wr of weakrefs) {
44 is(wr.deref(), undefined, "Check that stale wrapper is not exposed");
47 SimpleTest.finish();
49 </script>
50 </head>
51 <body onload="go()"></body>
52 </html>