tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_onGarbageCollection.html (1434B)


      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>
     11 
     12    <script type="application/javascript">
     13    SimpleTest.waitForExplicitFinish();
     14 
     15    const { gc } = Cu.getJSTestingFunctions();
     16 
     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")(),
     21      {
     22        freshCompartment: true,
     23        wantGlobalProperties: ["ChromeUtils"],
     24      }
     25    );
     26    Cu.evalInSandbox(`
     27 const { addDebuggerToGlobal } = ChromeUtils.importESModule(
     28  'resource://gre/modules/jsdebugger.sys.mjs'
     29 );
     30 addDebuggerToGlobal(globalThis);
     31 `, sandbox
     32    );
     33 
     34    const dbg = new sandbox.Debugger(this);
     35 
     36    dbg.memory.onGarbageCollection = function (data) {
     37      // Don't keep calling this hook after we finish.
     38      dbg.memory.onGarbageCollection = undefined;
     39      dbg.removeAllDebuggees();
     40 
     41      ok(data, "The onGarbageCollection hook was fired.");
     42      SimpleTest.finish();
     43    };
     44 
     45    gc();
     46    </script>
     47  </body>
     48 </html>