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">
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.
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");
51 <body onload=
"go()"></body>