tor-browser

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

thread-utils.js (3452B)


      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 "use strict";
      5 
      6 const asyncStoreHelper = require("resource://devtools/client/shared/async-store-helper.js");
      7 const { validateBreakpointLocation } = ChromeUtils.importESModule(
      8  "resource://devtools/shared/validate-breakpoint.sys.mjs",
      9  { global: "contextual" }
     10 );
     11 
     12 const asyncStore = asyncStoreHelper("debugger", {
     13  pendingBreakpoints: ["pending-breakpoints", {}],
     14  openedURLs: ["openedURLs", []],
     15  prettyPrintedURLs: ["pretty-printed-urls", []],
     16  xhrBreakpoints: ["xhr-breakpoints", []],
     17  eventListenerBreakpoints: ["event-listener-breakpoints", undefined],
     18  blackboxedRanges: ["blackboxedRanges", {}],
     19  directoryRoots: ["directory-roots", {}],
     20 });
     21 exports.asyncStore = asyncStore;
     22 
     23 exports.getThreadOptions = async function () {
     24  return {
     25    shouldPauseOnDebuggerStatement: Services.prefs.getBoolPref(
     26      "devtools.debugger.pause-on-debugger-statement"
     27    ),
     28    pauseOnExceptions: Services.prefs.getBoolPref(
     29      "devtools.debugger.pause-on-exceptions"
     30    ),
     31    ignoreCaughtExceptions: Services.prefs.getBoolPref(
     32      "devtools.debugger.ignore-caught-exceptions"
     33    ),
     34    shouldIncludeSavedFrames: Services.prefs.getBoolPref(
     35      "devtools.debugger.features.async-captured-stacks"
     36    ),
     37    shouldIncludeAsyncLiveFrames: Services.prefs.getBoolPref(
     38      "devtools.debugger.features.async-live-stacks"
     39    ),
     40    skipBreakpoints: Services.prefs.getBoolPref(
     41      "devtools.debugger.skip-pausing"
     42    ),
     43    logEventBreakpoints: Services.prefs.getBoolPref(
     44      "devtools.debugger.log-event-breakpoints"
     45    ),
     46    // This option is always true. See Bug 1654590 for removal.
     47    observeAsmJS: true,
     48    breakpoints: sanitizeBreakpoints(await asyncStore.pendingBreakpoints),
     49    // XXX: `event-listener-breakpoints` is a copy of the event-listeners state
     50    // of the debugger panel. The `active` property is therefore linked to
     51    // the `active` property of the state.
     52    // See devtools/client/debugger/src/reducers/event-listeners.js
     53    eventBreakpoints:
     54      ((await asyncStore.eventListenerBreakpoints) || {}).active || [],
     55  };
     56 };
     57 
     58 /**
     59 * Bug 1720512 - We used to store invalid breakpoints, leading to blank debugger.
     60 * Filter out only the one that look invalid.
     61 */
     62 function sanitizeBreakpoints(breakpoints) {
     63  if (typeof breakpoints != "object") {
     64    return {};
     65  }
     66  // We are not doing any assertion against keys,
     67  // as it looks like we are never using them anywhere in frontend, nor backend.
     68  const validBreakpoints = {};
     69  for (const key in breakpoints) {
     70    const bp = breakpoints[key];
     71    try {
     72      if (!bp) {
     73        throw new Error("Undefined breakpoint");
     74      }
     75      // Debugger's main.js's `syncBreakpoints` will only use generatedLocation
     76      // when restoring breakpoints.
     77      validateBreakpointLocation(bp.generatedLocation);
     78      // But Toolbox will still pass location to thread actor's reconfigure
     79      // for target that don't support watcher+BreakpointListActor
     80      validateBreakpointLocation(bp.location);
     81      validBreakpoints[key] = bp;
     82    } catch (e) {
     83      console.error(
     84        "Ignore invalid breakpoint from debugger store",
     85        bp,
     86        e.message
     87      );
     88    }
     89  }
     90  return validBreakpoints;
     91 }
     92 exports.sanitizeBreakpoints = sanitizeBreakpoints;