tor-browser

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

breakpoints.js (2387B)


      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 import { createSelector } from "devtools/client/shared/vendor/reselect";
      6 
      7 import { makeBreakpointId } from "../utils/breakpoint/index";
      8 
      9 // This method is only used from the main test helper
     10 export function getBreakpointsMap(state) {
     11  return state.breakpoints.breakpoints;
     12 }
     13 
     14 export const getBreakpointsList = createSelector(
     15  state => state.breakpoints.breakpoints,
     16  breakpoints => Object.values(breakpoints)
     17 );
     18 
     19 export function getBreakpointCount(state) {
     20  return getBreakpointsList(state).length;
     21 }
     22 
     23 export function getBreakpoint(state, location) {
     24  if (!location) {
     25    return undefined;
     26  }
     27 
     28  const breakpoints = getBreakpointsMap(state);
     29  return breakpoints[makeBreakpointId(location)];
     30 }
     31 
     32 /**
     33 * Gets the breakpoints on a line or within a range of lines
     34 *
     35 * @param {object} state
     36 * @param {number} source
     37 * @param {number | object} lines - line or an object with a start and end range of lines
     38 * @returns {Array} breakpoints
     39 */
     40 export function getBreakpointsForSource(state, source, lines) {
     41  if (!source) {
     42    return [];
     43  }
     44 
     45  const breakpoints = getBreakpointsList(state);
     46  return breakpoints.filter(bp => {
     47    const location = source.isOriginal ? bp.location : bp.generatedLocation;
     48 
     49    if (lines) {
     50      const isOnLineOrWithinRange =
     51        typeof lines == "number"
     52          ? location.line == lines
     53          : location.line >= lines.start.line &&
     54            location.line <= lines.end.line;
     55      return location.source === source && isOnLineOrWithinRange;
     56    }
     57    return location.source === source;
     58  });
     59 }
     60 
     61 export function getHiddenBreakpoint(state) {
     62  const breakpoints = getBreakpointsList(state);
     63  return breakpoints.find(bp => bp.options.hidden);
     64 }
     65 
     66 export function hasLogpoint(state, location) {
     67  const breakpoint = getBreakpoint(state, location);
     68  return breakpoint?.options.logValue;
     69 }
     70 
     71 export function getXHRBreakpoints(state) {
     72  return state.breakpoints.xhrBreakpoints;
     73 }
     74 
     75 export const shouldPauseOnAnyXHR = createSelector(
     76  getXHRBreakpoints,
     77  xhrBreakpoints => {
     78    const emptyBp = xhrBreakpoints.find(({ path }) => path.length === 0);
     79    if (!emptyBp) {
     80      return false;
     81    }
     82 
     83    return !emptyBp.disabled;
     84  }
     85 );