summaryrefslogtreecommitdiffstats
path: root/js/xpconnect/tests/mochitest/test_weakRefs_collected_wrapper.html
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--js/xpconnect/tests/mochitest/test_weakRefs_collected_wrapper.html52
1 files changed, 52 insertions, 0 deletions
diff --git a/js/xpconnect/tests/mochitest/test_weakRefs_collected_wrapper.html b/js/xpconnect/tests/mochitest/test_weakRefs_collected_wrapper.html
new file mode 100644
index 0000000000..c7af313d96
--- /dev/null
+++ b/js/xpconnect/tests/mochitest/test_weakRefs_collected_wrapper.html
@@ -0,0 +1,52 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Test WeakRefs with DOM wrappers that get cycle collected</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="application/javascript">
+ let weakrefs = [];
+
+ function go() {
+ SimpleTest.waitForExplicitFinish();
+
+ // 1. nsISupports-derived object.
+ let doc = document.implementation.createHTMLDocument();
+ weakrefs.push(new WeakRef(doc));
+
+ // 2. non-nsISupports-derived object.
+ let buffer = new AudioBuffer({length: 1, sampleRate: 8000});
+ weakrefs.push(new WeakRef(buffer));
+
+ // 3. nsISupports non-wrapper-cached object.
+ let image = new ImageData(1, 1);
+ weakrefs.push(new WeakRef(image));
+
+ // 4. non-nsISupports non-wrapper-cached object.
+ let iterator = document.fonts.values();
+ weakrefs.push(new WeakRef(iterator));
+
+ for (let wr of weakrefs) {
+ isnot(wr.deref(), undefined, "Check that live wrapper is returned");
+ }
+
+ // setTimeout will call its callback in a new task.
+ setTimeout(task2, 0);
+ }
+
+ function task2() {
+ // Trigger a GC and CC to collect the DOM objects, but no GC to
+ // collect the wrappers.
+ SpecialPowers.DOMWindowUtils.garbageCollect();
+ SpecialPowers.DOMWindowUtils.cycleCollect();
+
+ for (let wr of weakrefs) {
+ is(wr.deref(), undefined, "Check that stale wrapper is not exposed");
+ }
+
+ SimpleTest.finish();
+ }
+ </script>
+ </head>
+ <body onload="go()"></body>
+</html>