tor-browser

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

WorkerDebugger.tracer.js (1047B)


      1 "use strict";
      2 
      3 /* global global */
      4 
      5 try {
      6  // For some reason WorkerDebuggerGlobalScope.global doesn't expose JS variables
      7  // and we can't call via global.foo(). Instead we have to go throught the Debugger API.
      8  const dbg = new Debugger(global);
      9  const [debuggee] = dbg.getDebuggees();
     10 
     11  const { JSTracer } = ChromeUtils.importESModule(
     12    "resource://devtools/server/tracer/tracer.sys.mjs",
     13    { global: "contextual" }
     14  );
     15 
     16  const frames = [];
     17  const listener = {
     18    onTracingFrame(args) {
     19      frames.push(args);
     20 
     21      // Return true, to also log the trace to stdout
     22      return true;
     23    },
     24  };
     25  JSTracer.addTracingListener(listener);
     26  JSTracer.startTracing({ global, prefix: "testWorkerPrefix" });
     27 
     28  debuggee.executeInGlobal("foo()");
     29 
     30  JSTracer.stopTracing();
     31  JSTracer.removeTracingListener(listener);
     32 
     33  // Send the frames to the main thread to do the assertions there.
     34  postMessage(JSON.stringify(frames));
     35 } catch (e) {
     36  dump(
     37    "Exception while running debugger test script: " + e + "\n" + e.stack + "\n"
     38  );
     39 }