Commit dd90a112 authored by Hubert Boma Manilla's avatar Hubert Boma Manilla
Browse files

Bug 1824705 - [devtools] Add support for sourcemaps ignore list r=devtools-reviewers,nchevobbe

Also there is a patch to add support for ignoreList to the sourcemap library
https://github.com/mozilla/source-map/pull/481

Differential Revision: https://phabricator.services.mozilla.com/D174357
parent e3e9a991
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@ import {
  getPendingBreakpointList,
  isMapScopesEnabled,
  getBlackBoxRanges,
  isSourceMapIgnoreListEnabled,
  isSourceOnSourceMapIgnoreList,
} from "../../selectors";

import { setBreakpointPositions } from "./breakpointPositions";
@@ -81,14 +83,19 @@ function clientRemoveBreakpoint(client, state, generatedLocation) {
export function enableBreakpoint(cx, initialBreakpoint) {
  return thunkArgs => {
    const { dispatch, getState, client } = thunkArgs;
    const breakpoint = getBreakpoint(getState(), initialBreakpoint.location);
    const blackboxedRanges = getBlackBoxRanges(getState());
    const state = getState();
    const breakpoint = getBreakpoint(state, initialBreakpoint.location);
    const blackboxedRanges = getBlackBoxRanges(state);
    const isSourceOnIgnoreList =
      isSourceMapIgnoreListEnabled(state) &&
      isSourceOnSourceMapIgnoreList(state, breakpoint.location.source);
    if (
      !breakpoint ||
      !breakpoint.disabled ||
      isLineBlackboxed(
        blackboxedRanges[breakpoint.location.source.url],
        breakpoint.location.line
        breakpoint.location.line,
        isSourceOnIgnoreList
      )
    ) {
      return null;
+3 −3
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ import {
  getBreakpointsForSource,
} from "../../selectors";

async function _blackboxSourceActorsForSource(
export async function blackboxSourceActorsForSource(
  thunkArgs,
  source,
  shouldBlackBox,
@@ -82,7 +82,7 @@ export function toggleBlackBox(cx, source, shouldBlackBox, ranges = []) {
        ? shouldBlackBox
        : !isSourceBlackBoxed(getState(), source);

    await _blackboxSourceActorsForSource(
    await blackboxSourceActorsForSource(
      thunkArgs,
      source,
      shouldBlackBox,
@@ -200,7 +200,7 @@ export function blackBoxSources(cx, sourcesToBlackBox, shouldBlackBox) {
    }

    for (const source of sources) {
      await _blackboxSourceActorsForSource(thunkArgs, source, shouldBlackBox);
      await blackboxSourceActorsForSource(thunkArgs, source, shouldBlackBox);
    }

    if (shouldBlackBox) {
+10 −3
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@
 * Redux actions for the sources state
 * @module actions/sources
 */

import { PROMISE } from "../utils/middleware/promise";
import { insertSourceActors } from "../../actions/source-actors";
import {
  makeSourceId,
@@ -18,6 +18,7 @@ import { toggleBlackBox } from "./blackbox";
import { syncBreakpoint } from "../breakpoints";
import { loadSourceText } from "./loadSourceText";
import { togglePrettyPrint } from "./prettyPrint";
import { toggleSourceMapIgnoreList } from "../ui";
import { selectLocation, setBreakableLines } from "../sources";

import { getRawSourceURL, isPrettyURL } from "../../utils/source";
@@ -54,14 +55,12 @@ function loadSourceMaps(cx, sources) {
      );

      await sourceQueue.flush();

      return sourceList.flat();
    } catch (error) {
      if (!(error instanceof ContextError)) {
        throw error;
      }
    }

    return [];
  };
}
@@ -91,6 +90,10 @@ function loadSourceMap(cx, sourceActor) {
          sourceMapURL: sourceActor.sourceMapURL || "",
          isWasm: sourceActor.introductionType === "wasm",
        });
        dispatch({
          type: "ADD_SOURCEMAP_IGNORE_LIST_SOURCES",
          [PROMISE]: sourceMapLoader.getSourceMapIgnoreList(source.id),
        });
      }
    } catch (e) {
      console.error(e);
@@ -194,6 +197,10 @@ function restoreBlackBoxedSources(cx, sources) {
        await dispatch(toggleBlackBox(cx, source, true, ranges));
      }
    }

    if (prefs.sourceMapIgnoreListEnabled) {
      await dispatch(toggleSourceMapIgnoreList(cx, true));
    }
  };
}

+24 −0
Original line number Diff line number Diff line
@@ -9,6 +9,9 @@ import {
  getSource,
  getSourceContent,
  getMainThread,
  getIgnoreListSourceUrls,
  getSourceByURL,
  getBreakpointsForSource,
} from "../selectors";
import { selectSource } from "../actions/sources/select";
import {
@@ -16,6 +19,8 @@ import {
  getLocationsInViewport,
  updateDocuments,
} from "../utils/editor";
import { blackboxSourceActorsForSource } from "./sources/blackbox";
import { toggleBreakpoints } from "./breakpoints";
import { copyToTheClipboard } from "../utils/clipboard";
import { isFulfilled } from "../utils/async-value";

@@ -242,3 +247,22 @@ export function setHideOrShowIgnoredSources(shouldHide) {
    dispatch({ type: "HIDE_IGNORED_SOURCES", shouldHide });
  };
}

export function toggleSourceMapIgnoreList(cx, shouldEnable) {
  return async thunkArgs => {
    const { dispatch, getState } = thunkArgs;
    const ignoreListSourceUrls = getIgnoreListSourceUrls(getState());
    // Blackbox the source actors on the server
    for (const url of ignoreListSourceUrls) {
      const source = getSourceByURL(getState(), url);
      await blackboxSourceActorsForSource(thunkArgs, source, shouldEnable);
      // Disable breakpoints in sources on the ignore list
      const breakpoints = getBreakpointsForSource(getState(), source.id);
      await dispatch(toggleBreakpoints(cx, shouldEnable, breakpoints));
    }
    await dispatch({
      type: "ENABLE_SOURCEMAP_IGNORELIST",
      shouldEnable,
    });
  };
}
+33 −4
Original line number Diff line number Diff line
@@ -7,7 +7,12 @@ import PropTypes from "prop-types";
import { Component } from "react";
import { toEditorLine, fromEditorLine } from "../../utils/editor";
import { isLineBlackboxed } from "../../utils/source";
import { getBlackBoxRanges, getSelectedSource } from "../../selectors";
import {
  getBlackBoxRanges,
  getSelectedSource,
  isSourceMapIgnoreListEnabled,
  isSourceOnSourceMapIgnoreList,
} from "../../selectors";
import { isWasm } from "../../utils/wasm";

// This renders blackbox line highlighting in the editor
@@ -17,6 +22,7 @@ class BlackboxLines extends Component {
      editor: PropTypes.object,
      selectedSource: PropTypes.object,
      blackboxedRangesForSelectedSource: PropTypes.object,
      isSourceOnIgnoreList: PropTypes.bool,
    };
  }

@@ -24,6 +30,11 @@ class BlackboxLines extends Component {
    const { selectedSource, blackboxedRangesForSelectedSource, editor } =
      this.props;

    if (this.props.isSourceOnIgnoreList) {
      this.setAllBlackboxLines(editor);
      return;
    }

    // When `blackboxedRangesForSelectedSource` is undefined, the source isn't blackboxed
    if (!blackboxedRangesForSelectedSource) {
      return;
@@ -47,8 +58,17 @@ class BlackboxLines extends Component {
  }

  componentDidUpdate() {
    const { selectedSource, blackboxedRangesForSelectedSource, editor } =
      this.props;
    const {
      selectedSource,
      blackboxedRangesForSelectedSource,
      editor,
      isSourceOnIgnoreList,
    } = this.props;

    if (this.props.isSourceOnIgnoreList) {
      this.setAllBlackboxLines(editor);
      return;
    }

    // when unblackboxed
    if (!blackboxedRangesForSelectedSource) {
@@ -75,7 +95,13 @@ class BlackboxLines extends Component {
          sourceIsWasm
        );

        if (isLineBlackboxed(blackboxedRangesForSelectedSource, line)) {
        if (
          isLineBlackboxed(
            blackboxedRangesForSelectedSource,
            line,
            isSourceOnIgnoreList
          )
        ) {
          this.setBlackboxLine(editor, lineHandle);
        } else {
          this.clearBlackboxLine(editor, lineHandle);
@@ -128,6 +154,9 @@ const mapStateToProps = state => {
    blackboxedRangesForSelectedSource: selectedSource
      ? getBlackBoxRanges(state)[selectedSource.url]
      : undefined,
    isSourceOnIgnoreList:
      isSourceMapIgnoreListEnabled(state) &&
      isSourceOnSourceMapIgnoreList(state, selectedSource),
  };
};

Loading