summaryrefslogtreecommitdiffstats
path: root/devtools/server/tracer/tests/browser/WorkerDebugger.tracer.js
blob: ef15fd5cfb3dc37b0eada1a9de3d88504a7b67ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"use strict";

/* global global */

try {
  // For some reason WorkerDebuggerGlobalScope.global doesn't expose JS variables
  // and we can't call via global.foo(). Instead we have to go throught the Debugger API.
  const dbg = new Debugger(global);
  const [debuggee] = dbg.getDebuggees();

  const { JSTracer } = ChromeUtils.importESModule(
    "resource://devtools/server/tracer/tracer.sys.mjs",
    { global: "contextual" }
  );

  const frames = [];
  const listener = {
    onTracingFrame(args) {
      frames.push(args);

      // Return true, to also log the trace to stdout
      return true;
    },
  };
  JSTracer.addTracingListener(listener);
  JSTracer.startTracing({ global, prefix: "testWorkerPrefix" });

  debuggee.executeInGlobal("foo()");

  JSTracer.stopTracing();
  JSTracer.removeTracingListener(listener);

  // Send the frames to the main thread to do the assertions there.
  postMessage(JSON.stringify(frames));
} catch (e) {
  dump(
    "Exception while running debugger test script: " + e + "\n" + e.stack + "\n"
  );
}