tor-browser

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

breakpoints.js (1956B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 const {
      8  STATES: THREAD_STATES,
      9 } = require("resource://devtools/server/actors/thread.js");
     10 const Targets = require("resource://devtools/server/actors/targets/index.js");
     11 
     12 module.exports = {
     13  async addOrSetSessionDataEntry(
     14    targetActor,
     15    entries,
     16    isDocumentCreation,
     17    updateType
     18  ) {
     19    // The Browser Toolbox uses the Content Process target's Thread actor to debug all scripts
     20    // running into a given process. This includes WindowGlobal scripts.
     21    // Because of this, and in such configuration, we have to ignore the WindowGlobal targets.
     22    if (
     23      targetActor.sessionContext.type == "all" &&
     24      !targetActor.sessionContext.enableWindowGlobalThreadActors &&
     25      targetActor.targetType === Targets.TYPES.FRAME &&
     26      targetActor.typeName != "parentProcessTarget"
     27    ) {
     28      return;
     29    }
     30 
     31    const { threadActor } = targetActor;
     32    if (updateType == "set") {
     33      threadActor.removeAllBreakpoints();
     34    }
     35    const isTargetCreation = threadActor.state == THREAD_STATES.DETACHED;
     36    if (isTargetCreation) {
     37      // If addOrSetSessionDataEntry is called during target creation, attach the
     38      // thread actor automatically and pass the initial breakpoints.
     39      await threadActor.attach({ breakpoints: entries });
     40    } else {
     41      // If addOrSetSessionDataEntry is called for an existing target, set the new
     42      // breakpoints on the already running thread actor.
     43      await Promise.all(
     44        entries.map(({ location, options }) =>
     45          threadActor.setBreakpoint(location, options)
     46        )
     47      );
     48    }
     49  },
     50 
     51  removeSessionDataEntry(targetActor, entries) {
     52    for (const { location } of entries) {
     53      targetActor.threadActor.removeBreakpoint(location);
     54    }
     55  },
     56 };