diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/xpconnect/tests/mochitest/test_weakRefs_collected_wrapper.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | js/xpconnect/tests/mochitest/test_weakRefs_collected_wrapper.html | 52 |
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> |