summaryrefslogtreecommitdiffstats
path: root/js/xpconnect/tests/mochitest/test_weakRefs_collected_wrapper.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /js/xpconnect/tests/mochitest/test_weakRefs_collected_wrapper.html
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
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>