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">
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"],
27 const { addDebuggerToGlobal } = ChromeUtils.importESModule(
28 'resource://gre/modules/jsdebugger.sys.mjs'
30 addDebuggerToGlobal(globalThis);
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.");