tor-browser

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

Memory-trackingAllocationSites-03.js (2444B)


      1 // Test that multiple Debuggers behave reasonably.
      2 
      3 load(libdir + "asserts.js");
      4 
      5 let dbg1, dbg2, root1, root2;
      6 
      7 function isTrackingAllocations(global, dbgObj) {
      8  const site = dbgObj.makeDebuggeeValue(global.eval("({})")).allocationSite;
      9  if (site) {
     10    assertEq(typeof site, "object");
     11  }
     12  return !!site;
     13 }
     14 
     15 function test(name, fn) {
     16  print();
     17  print(name);
     18 
     19  // Reset state.
     20  root1 = newGlobal({newCompartment: true});
     21  root2 = newGlobal({newCompartment: true});
     22  dbg1 = new Debugger;
     23  dbg2 = new Debugger;
     24 
     25  // Run the test.
     26  fn();
     27 
     28  print("  OK");
     29 }
     30 
     31 test("Can track allocations even if a different debugger is already tracking " +
     32     "them.",
     33     () => {
     34       let d1r1 = dbg1.addDebuggee(root1);
     35       let d2r1 = dbg2.addDebuggee(root1);
     36       dbg1.memory.trackingAllocationSites = true;
     37       dbg2.memory.trackingAllocationSites = true;
     38       assertEq(isTrackingAllocations(root1, d1r1), true);
     39       assertEq(isTrackingAllocations(root1, d2r1), true);
     40     });
     41 
     42 test("Removing root1 as a debuggee from all debuggers should disable the " +
     43     "allocation hook.",
     44     () => {
     45       dbg1.memory.trackingAllocationSites = true;
     46       let d1r1 = dbg1.addDebuggee(root1);
     47       dbg1.removeAllDebuggees();
     48       assertEq(isTrackingAllocations(root1, d1r1), false);
     49     });
     50 
     51 test("Adding a new debuggee to a debugger that is tracking allocations should " +
     52     "enable the hook for the new debuggee.",
     53     () => {
     54       dbg1.memory.trackingAllocationSites = true;
     55       let d1r1 = dbg1.addDebuggee(root1);
     56       assertEq(isTrackingAllocations(root1, d1r1), true);
     57     });
     58 
     59 test("Setting trackingAllocationSites to true should throw if the debugger " +
     60     "cannot install the allocation hooks for *every* debuggee.",
     61     () => {
     62       let d1r1 = dbg1.addDebuggee(root1);
     63       let d1r2 = dbg1.addDebuggee(root2);
     64 
     65       // Can't install allocation hooks for root2 with this set.
     66       root2.enableShellAllocationMetadataBuilder();
     67 
     68       assertThrowsInstanceOf(() => dbg1.memory.trackingAllocationSites = true,
     69                              Error);
     70 
     71       // And after it throws, its trackingAllocationSites accessor should reflect that
     72       // allocation site tracking is still disabled in that Debugger.
     73       assertEq(dbg1.memory.trackingAllocationSites, false);
     74       assertEq(isTrackingAllocations(root1, d1r1), false);
     75       assertEq(isTrackingAllocations(root2, d1r2), false);
     76     });