tor-browser

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

Memory-drainAllocationsLog-01.js (888B)


      1 // Test basic usage of drainAllocationsLog()
      2 
      3 const root = newGlobal({newCompartment: true});
      4 const dbg = new Debugger();
      5 const wrappedRoot = dbg.addDebuggee(root)
      6 dbg.memory.trackingAllocationSites = true;
      7 
      8 root.eval("(" + function immediate() {
      9  this.tests = [
     10    {x: 1},
     11    [],
     12    /(two|2)\s*problems/,
     13    new function Ctor(){},
     14    new Object(),
     15    new Array(),
     16    new Date(),
     17  ];
     18 } + "());");
     19 
     20 const allocs = dbg.memory.drainAllocationsLog();
     21 print(allocs.join("\n--------------------------------------------------------------------------\n"));
     22 print("Total number of allocations logged: " + allocs.length);
     23 
     24 let idx = -1;
     25 for (let object of root.tests) {
     26  let wrappedObject = wrappedRoot.makeDebuggeeValue(object);
     27  let allocSite = wrappedObject.allocationSite;
     28  let newIdx = allocs.map(x => x.frame).indexOf(allocSite);
     29  assertEq(newIdx > idx, true);
     30  idx = newIdx;
     31 }