tor-browser

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

test_ReadHeapSnapshot_with_allocations.js (1821B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 // Test that we can save a core dump with allocation stacks and read it back
      6 // into a HeapSnapshot.
      7 
      8 if (typeof Debugger != "function") {
      9  const { addDebuggerToGlobal } = ChromeUtils.importESModule(
     10    "resource://gre/modules/jsdebugger.sys.mjs"
     11  );
     12  addDebuggerToGlobal(globalThis);
     13 }
     14 
     15 function run_test() {
     16  Services.prefs.setBoolPref(
     17    "security.allow_parent_unrestricted_js_loads",
     18    true
     19  );
     20  Services.prefs.setBoolPref("security.allow_eval_with_system_principal", true);
     21  Services.prefs.setBoolPref("security.allow_eval_in_parent_process", true);
     22  registerCleanupFunction(() => {
     23    Services.prefs.clearUserPref("security.allow_parent_unrestricted_js_loads");
     24    Services.prefs.clearUserPref("security.allow_eval_with_system_principal");
     25    Services.prefs.clearUserPref("security.allow_eval_in_parent_process");
     26  });
     27 
     28  // Create a Debugger observing a debuggee's allocations.
     29  const debuggee = new Cu.Sandbox(null);
     30  const dbg = new Debugger(debuggee);
     31  dbg.memory.trackingAllocationSites = true;
     32 
     33  // Allocate some objects in the debuggee that will have their allocation
     34  // stacks recorded by the Debugger.
     35  debuggee.eval("this.objects = []");
     36  for (let i = 0; i < 100; i++) {
     37    debuggee.eval("this.objects.push({})");
     38  }
     39 
     40  // Now save a snapshot that will include the allocation stacks and read it
     41  // back again.
     42 
     43  const filePath = ChromeUtils.saveHeapSnapshot({ runtime: true });
     44  ok(true, "Should be able to save a snapshot.");
     45 
     46  const snapshot = ChromeUtils.readHeapSnapshot(filePath);
     47  ok(snapshot, "Should be able to read a heap snapshot");
     48  ok(HeapSnapshot.isInstance(snapshot), "Should be an instanceof HeapSnapshot");
     49 
     50  do_test_finished();
     51 }