tor-browser

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

index.js (2244B)


      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 { getSourceActorsForSource } from "../../selectors/index";
      6 import { sortSelectedLocations } from "../location";
      7 export * from "./breakpointPositions";
      8 
      9 // The ID for a Breakpoint is derived from its location in its Source.
     10 export function makeBreakpointId(location) {
     11  const { source, line, column } = location;
     12  const columnString = column || "";
     13  return `${source.id}:${line}:${columnString}`;
     14 }
     15 
     16 export function makeBreakpointServerLocationId(breakpointServerLocation) {
     17  const { sourceUrl, sourceId, line, column } = breakpointServerLocation;
     18  const sourceUrlOrId = sourceUrl || sourceId;
     19  const columnString = column || "";
     20 
     21  return `${sourceUrlOrId}:${line}:${columnString}`;
     22 }
     23 
     24 /**
     25 * Create a location object to set a breakpoint on the server.
     26 *
     27 * Debugger location objects includes a source and sourceActor attributes
     28 * whereas the server don't need them and instead only need either
     29 * the source URL -or- a precise source actor ID.
     30 */
     31 export function makeBreakpointServerLocation(state, location) {
     32  const source = location.source;
     33  if (!source) {
     34    throw new Error("Missing 'source' attribute on location object");
     35  }
     36  const breakpointLocation = {
     37    line: location.line,
     38    column: location.column,
     39  };
     40  if (source.url) {
     41    breakpointLocation.sourceUrl = source.url;
     42  } else {
     43    breakpointLocation.sourceId = getSourceActorsForSource(
     44      state,
     45      source.id
     46    )[0].id;
     47  }
     48  return breakpointLocation;
     49 }
     50 
     51 export function createXHRBreakpoint(path, method, overrides = {}) {
     52  const properties = {
     53    path,
     54    method,
     55    disabled: false,
     56    loading: false,
     57    text: L10N.getFormatStr("xhrBreakpoints.item.label", path),
     58  };
     59 
     60  return { ...properties, ...overrides };
     61 }
     62 
     63 export function getSelectedText(breakpoint, selectedSource) {
     64  return !!selectedSource && !selectedSource.isOriginal
     65    ? breakpoint.text
     66    : breakpoint.originalText;
     67 }
     68 
     69 export function sortSelectedBreakpoints(breakpoints, selectedSource) {
     70  return sortSelectedLocations(breakpoints, selectedSource);
     71 }