Backed out changeset 713114c0331a (bug 1938707) by developer request CLOSED TREE
[gecko.git] / js / xpconnect / tests / chrome / test_onGarbageCollection.html
blobce056ed354dee3f870f21b2f90ecd39f5fad1044
1 <!doctype html>
2 <html>
3 <head>
4 <title>Bug 1150253 - Sanity test for the SpiderMonkey Debugger API's onGarbageCollection hook</title>
5 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js">
6 </script>
7 </head>
8 <body xmlns="http://www.w3.org/1999/xhtml">
9 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1150253"
10 target="_blank">Mozilla Bug 1150253</a>
12 <script type="application/javascript">
13 SimpleTest.waitForExplicitFinish();
15 const { gc } = Cu.getJSTestingFunctions();
17 // Instantiate `Debugger` in a sandbox as Debugger requires to be created
18 // in a compartment different than the debuggee.
19 let sandbox = Cu.Sandbox(
20 Components.Constructor("@mozilla.org/systemprincipal;1", "nsIPrincipal")(),
22 freshCompartment: true,
23 wantGlobalProperties: ["ChromeUtils"],
26 Cu.evalInSandbox(`
27 const { addDebuggerToGlobal } = ChromeUtils.importESModule(
28 'resource://gre/modules/jsdebugger.sys.mjs'
30 addDebuggerToGlobal(globalThis);
31 `, sandbox
34 const dbg = new sandbox.Debugger(this);
36 dbg.memory.onGarbageCollection = function (data) {
37 // Don't keep calling this hook after we finish.
38 dbg.memory.onGarbageCollection = undefined;
39 dbg.removeAllDebuggees();
41 ok(data, "The onGarbageCollection hook was fired.");
42 SimpleTest.finish();
45 gc();
46 </script>
47 </body>
48 </html>