tor-browser

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

Memory-trackingAllocationSites-01.js (1558B)


      1 // Test that we can track allocation sites by setting
      2 // Debugger.Memory.prototype.trackingAllocationSites to true and then get the
      3 // allocation site via Debugger.Object.prototype.allocationSite.
      4 
      5 const root = newGlobal({newCompartment: true});
      6 
      7 const dbg = new Debugger();
      8 const wrappedRoot = dbg.addDebuggee(root);
      9 
     10 assertEq(dbg.memory.trackingAllocationSites, false);
     11 dbg.memory.trackingAllocationSites = true;
     12 assertEq(dbg.memory.trackingAllocationSites, true);
     13 
     14 root.eval("(" + function immediate() {
     15  this.tests = [
     16    { name: "object literal",  object: ({}),                  line: Error().lineNumber },
     17    { name: "array literal",   object: [],                    line: Error().lineNumber },
     18    { name: "regexp literal",  object: /(two|2)\s*problems/,  line: Error().lineNumber },
     19    { name: "new constructor", object: new function Ctor(){}, line: Error().lineNumber },
     20    { name: "new Object",      object: new Object(),          line: Error().lineNumber },
     21    { name: "new Array",       object: new Array(),           line: Error().lineNumber },
     22    { name: "new Date",        object: new Date(),            line: Error().lineNumber }
     23  ];
     24 } + "());");
     25 
     26 dbg.memory.trackingAllocationSites = false;
     27 assertEq(dbg.memory.trackingAllocationSites, false);
     28 
     29 for (let { name, object, line } of root.tests) {
     30  print("Entering test: " + name);
     31 
     32  let wrappedObject = wrappedRoot.makeDebuggeeValue(object);
     33  let allocationSite = wrappedObject.allocationSite;
     34  print("Allocation site: " + allocationSite);
     35 
     36  assertEq(allocationSite.line, line);
     37 }