Commit 992cf3e9 authored by Jason Laster's avatar Jason Laster Committed by Jason Laster
Browse files

Bug 1520957 - [release 119] Replace formatted breakpoint with generic...

Bug 1520957 - [release 119] Replace formatted breakpoint with generic Breakpoint type (#7730). r=dwalsh
parent fdc3f8cd
Loading
Loading
Loading
Loading
+38 −4
Original line number Original line Diff line number Diff line
@@ -37,15 +37,32 @@ Array [
  Object {
  Object {
    "breakpoints": Array [
    "breakpoints": Array [
      Object {
      Object {
        "astLocation": Object {
          "index": 0,
          "name": undefined,
          "offset": Object {
            "line": 2,
            "sourceId": "a",
            "sourceUrl": "http://localhost:8000/examples/a",
          },
        },
        "condition": null,
        "condition": null,
        "disabled": false,
        "disabled": false,
        "generatedLocation": Object {
          "line": 2,
          "sourceId": "a",
          "sourceUrl": "http://localhost:8000/examples/a",
        },
        "hidden": false,
        "id": "hi",
        "id": "hi",
        "log": false,
        "loading": false,
        "selectedLocation": Object {
        "location": Object {
          "line": 2,
          "line": 2,
          "sourceId": "a",
          "sourceId": "a",
          "sourceUrl": "http://localhost:8000/examples/a",
          "sourceUrl": "http://localhost:8000/examples/a",
        },
        },
        "log": false,
        "originalText": "return a",
        "text": "return a",
        "text": "return a",
      },
      },
    ],
    ],
@@ -107,15 +124,32 @@ Array [
  Object {
  Object {
    "breakpoints": Array [
    "breakpoints": Array [
      Object {
      Object {
        "astLocation": Object {
          "index": 0,
          "name": undefined,
          "offset": Object {
            "line": 5,
            "sourceId": "a",
            "sourceUrl": "http://localhost:8000/examples/a",
          },
        },
        "condition": null,
        "condition": null,
        "disabled": true,
        "disabled": true,
        "generatedLocation": Object {
          "line": 5,
          "sourceId": "a",
          "sourceUrl": "http://localhost:8000/examples/a",
        },
        "hidden": false,
        "id": "hi",
        "id": "hi",
        "log": false,
        "loading": false,
        "selectedLocation": Object {
        "location": Object {
          "line": 5,
          "line": 5,
          "sourceId": "a",
          "sourceId": "a",
          "sourceUrl": "http://localhost:8000/examples/a",
          "sourceUrl": "http://localhost:8000/examples/a",
        },
        },
        "log": false,
        "originalText": "",
        "text": "",
        "text": "",
      },
      },
    ],
    ],
+25 −24
Original line number Original line Diff line number Diff line
@@ -8,19 +8,19 @@ import React, { PureComponent } from "react";
import { connect } from "../../../utils/connect";
import { connect } from "../../../utils/connect";
import { createSelector } from "reselect";
import { createSelector } from "reselect";
import classnames from "classnames";
import classnames from "classnames";

import actions from "../../../actions";
import actions from "../../../actions";


import showContextMenu from "./BreakpointsContextMenu";
import showContextMenu from "./BreakpointsContextMenu";
import { CloseButton } from "../../shared/Button";
import { CloseButton } from "../../shared/Button";


import { getLocationWithoutColumn } from "../../../utils/breakpoint";
import {
  getLocationWithoutColumn,
  getSelectedText
} from "../../../utils/breakpoint";
import { getSelectedLocation } from "../../../utils/source-maps";
import { getSelectedLocation } from "../../../utils/source-maps";
import { features } from "../../../utils/prefs";
import { features } from "../../../utils/prefs";
import { getEditor } from "../../../utils/editor";
import { getEditor } from "../../../utils/editor";


import type { FormattedBreakpoint } from "../../../selectors/breakpointSources";

import type {
import type {
  Breakpoint as BreakpointType,
  Breakpoint as BreakpointType,
  Frame,
  Frame,
@@ -39,8 +39,9 @@ import {
} from "../../../selectors";
} from "../../../selectors";


type Props = {
type Props = {
  breakpoint: FormattedBreakpoint,
  breakpoint: BreakpointType,
  breakpoints: BreakpointType[],
  breakpoints: BreakpointType[],
  selectedSource: Source,
  source: Source,
  source: Source,
  frame: FormattedFrame,
  frame: FormattedFrame,
  enableBreakpoint: typeof actions.enableBreakpoint,
  enableBreakpoint: typeof actions.enableBreakpoint,
@@ -61,51 +62,52 @@ class Breakpoint extends PureComponent<Props> {
    showContextMenu({ ...this.props, contextMenuEvent: e });
    showContextMenu({ ...this.props, contextMenuEvent: e });
  };
  };


  get selectedLocation() {
    const { breakpoint, selectedSource } = this.props;
    return getSelectedLocation(breakpoint, selectedSource);
  }

  onDoubleClick = () => {
  onDoubleClick = () => {
    const { breakpoint, openConditionalPanel } = this.props;
    const { breakpoint, openConditionalPanel } = this.props;
    if (breakpoint.condition) {
    if (breakpoint.condition) {
      openConditionalPanel(breakpoint.selectedLocation);
      openConditionalPanel(this.selectedLocation);
    }
    }
  };
  };


  selectBreakpoint = event => {
  selectBreakpoint = () => {
    const { breakpoint, selectSpecificLocation } = this.props;
    const { selectSpecificLocation } = this.props;

    selectSpecificLocation(this.selectedLocation);
    event.preventDefault();
    selectSpecificLocation(breakpoint.selectedLocation);
  };
  };


  removeBreakpoint = event => {
  removeBreakpoint = event => {
    const { breakpoint, removeBreakpoint } = this.props;
    const { removeBreakpoint } = this.props;

    event.stopPropagation();
    event.stopPropagation();
    removeBreakpoint(breakpoint.selectedLocation);
    removeBreakpoint(this.selectedLocation);
  };
  };


  handleBreakpointCheckbox = () => {
  handleBreakpointCheckbox = () => {
    const { breakpoint, enableBreakpoint, disableBreakpoint } = this.props;
    const { breakpoint, enableBreakpoint, disableBreakpoint } = this.props;
    if (breakpoint.disabled) {
    if (breakpoint.disabled) {
      enableBreakpoint(breakpoint.selectedLocation);
      enableBreakpoint(this.selectedLocation);
    } else {
    } else {
      disableBreakpoint(breakpoint.selectedLocation);
      disableBreakpoint(this.selectedLocation);
    }
    }
  };
  };


  isCurrentlyPausedAtBreakpoint() {
  isCurrentlyPausedAtBreakpoint() {
    const { frame, breakpoint } = this.props;
    const { frame } = this.props;
    if (!frame) {
    if (!frame) {
      return false;
      return false;
    }
    }


    const bpId = getLocationWithoutColumn(breakpoint.selectedLocation);
    const bpId = getLocationWithoutColumn(this.selectedLocation);
    const frameId = getLocationWithoutColumn(frame.selectedLocation);
    const frameId = getLocationWithoutColumn(frame.selectedLocation);

    return bpId == frameId;
    return bpId == frameId;
  }
  }


  getBreakpointLocation() {
  getBreakpointLocation() {
    const { breakpoint, source } = this.props;
    const { source } = this.props;
    const { column, line } = breakpoint.selectedLocation;
    const { column, line } = this.selectedLocation;


    const isWasm = source && source.isWasm;
    const isWasm = source && source.isWasm;
    const columnVal = features.columnBreakpoints && column ? `:${column}` : "";
    const columnVal = features.columnBreakpoints && column ? `:${column}` : "";
@@ -117,8 +119,8 @@ class Breakpoint extends PureComponent<Props> {
  }
  }


  getBreakpointText() {
  getBreakpointText() {
    const { breakpoint } = this.props;
    const { breakpoint, selectedSource } = this.props;
    return breakpoint.condition || breakpoint.text;
    return breakpoint.condition || getSelectedText(breakpoint, selectedSource);
  }
  }


  highlightText() {
  highlightText() {
@@ -161,7 +163,6 @@ class Breakpoint extends PureComponent<Props> {
        <label
        <label
          htmlFor={breakpoint.id}
          htmlFor={breakpoint.id}
          className="breakpoint-label cm-s-mozilla"
          className="breakpoint-label cm-s-mozilla"
          onClick={this.selectBreakpoint}
          title={this.getBreakpointText()}
          title={this.getBreakpointText()}
        >
        >
          <span dangerouslySetInnerHTML={this.highlightText()} />
          <span dangerouslySetInnerHTML={this.highlightText()} />
+14 −11
Original line number Original line Diff line number Diff line
@@ -6,13 +6,14 @@


import { buildMenu, showMenu } from "devtools-contextmenu";
import { buildMenu, showMenu } from "devtools-contextmenu";


import { getSelectedLocation } from "../../../utils/source-maps";
import actions from "../../../actions";
import actions from "../../../actions";
import type { Breakpoint } from "../../../types";
import type { Breakpoint, Source } from "../../../types";
import type { FormattedBreakpoint } from "../../../selectors/breakpointSources";


type Props = {
type Props = {
  breakpoint: FormattedBreakpoint,
  breakpoint: Breakpoint,
  breakpoints: Breakpoint[],
  breakpoints: Breakpoint[],
  selectedSource: Source,
  removeBreakpoint: typeof actions.removeBreakpoint,
  removeBreakpoint: typeof actions.removeBreakpoint,
  removeBreakpoints: typeof actions.removeBreakpoints,
  removeBreakpoints: typeof actions.removeBreakpoints,
  removeAllBreakpoints: typeof actions.removeAllBreakpoints,
  removeAllBreakpoints: typeof actions.removeAllBreakpoints,
@@ -29,6 +30,7 @@ export default function showContextMenu(props: Props) {
  const {
  const {
    breakpoint,
    breakpoint,
    breakpoints,
    breakpoints,
    selectedSource,
    removeBreakpoint,
    removeBreakpoint,
    removeBreakpoints,
    removeBreakpoints,
    removeAllBreakpoints,
    removeAllBreakpoints,
@@ -95,6 +97,7 @@ export default function showContextMenu(props: Props) {
    "breakpointMenuItem.addCondition2.accesskey"
    "breakpointMenuItem.addCondition2.accesskey"
  );
  );


  const selectedLocation = getSelectedLocation(breakpoint, selectedSource);
  const otherBreakpoints = breakpoints.filter(b => b.id !== breakpoint.id);
  const otherBreakpoints = breakpoints.filter(b => b.id !== breakpoint.id);
  const enabledBreakpoints = breakpoints.filter(b => !b.disabled);
  const enabledBreakpoints = breakpoints.filter(b => !b.disabled);
  const disabledBreakpoints = breakpoints.filter(b => b.disabled);
  const disabledBreakpoints = breakpoints.filter(b => b.disabled);
@@ -110,7 +113,7 @@ export default function showContextMenu(props: Props) {
    label: deleteSelfLabel,
    label: deleteSelfLabel,
    accesskey: deleteSelfKey,
    accesskey: deleteSelfKey,
    disabled: false,
    disabled: false,
    click: () => removeBreakpoint(breakpoint.selectedLocation)
    click: () => removeBreakpoint(selectedLocation)
  };
  };


  const deleteAllItem = {
  const deleteAllItem = {
@@ -134,7 +137,7 @@ export default function showContextMenu(props: Props) {
    label: enableSelfLabel,
    label: enableSelfLabel,
    accesskey: enableSelfKey,
    accesskey: enableSelfKey,
    disabled: false,
    disabled: false,
    click: () => toggleDisabledBreakpoint(breakpoint.selectedLocation.line)
    click: () => toggleDisabledBreakpoint(selectedLocation.line)
  };
  };


  const enableAllItem = {
  const enableAllItem = {
@@ -158,7 +161,7 @@ export default function showContextMenu(props: Props) {
    label: disableSelfLabel,
    label: disableSelfLabel,
    accesskey: disableSelfKey,
    accesskey: disableSelfKey,
    disabled: false,
    disabled: false,
    click: () => toggleDisabledBreakpoint(breakpoint.selectedLocation.line)
    click: () => toggleDisabledBreakpoint(selectedLocation.line)
  };
  };


  const disableAllItem = {
  const disableAllItem = {
@@ -181,7 +184,7 @@ export default function showContextMenu(props: Props) {
    label: removeConditionLabel,
    label: removeConditionLabel,
    accesskey: removeConditionKey,
    accesskey: removeConditionKey,
    disabled: false,
    disabled: false,
    click: () => setBreakpointCondition(breakpoint.selectedLocation)
    click: () => setBreakpointCondition(selectedLocation)
  };
  };


  const addConditionItem = {
  const addConditionItem = {
@@ -189,8 +192,8 @@ export default function showContextMenu(props: Props) {
    label: addConditionLabel,
    label: addConditionLabel,
    accesskey: addConditionKey,
    accesskey: addConditionKey,
    click: () => {
    click: () => {
      selectSpecificLocation(breakpoint.selectedLocation);
      selectSpecificLocation(selectedLocation);
      openConditionalPanel(breakpoint.selectedLocation);
      openConditionalPanel(selectedLocation);
    }
    }
  };
  };


@@ -199,8 +202,8 @@ export default function showContextMenu(props: Props) {
    label: editConditionLabel,
    label: editConditionLabel,
    accesskey: editConditionKey,
    accesskey: editConditionKey,
    click: () => {
    click: () => {
      selectSpecificLocation(breakpoint.selectedLocation);
      selectSpecificLocation(selectedLocation);
      openConditionalPanel(breakpoint.selectedLocation);
      openConditionalPanel(selectedLocation);
    }
    }
  };
  };


+12 −4
Original line number Original line Diff line number Diff line
@@ -15,9 +15,11 @@ import BreakpointHeading from "./BreakpointHeading";


import actions from "../../../actions";
import actions from "../../../actions";
import { getDisplayPath } from "../../../utils/source";
import { getDisplayPath } from "../../../utils/source";
import { getSelectedLocation } from "../../../utils/source-maps";

import {
import {
  makeLocationId,
  makeLocationId,
  sortFormattedBreakpoints
  sortSelectedBreakpoints
} from "../../../utils/breakpoint";
} from "../../../utils/breakpoint";


import { getSelectedSource, getBreakpointSources } from "../../../selectors";
import { getSelectedSource, getBreakpointSources } from "../../../selectors";
@@ -74,7 +76,7 @@ class Breakpoints extends Component<Props> {
  }
  }


  renderBreakpoints() {
  renderBreakpoints() {
    const { breakpointSources } = this.props;
    const { breakpointSources, selectedSource } = this.props;
    const sources = [
    const sources = [
      ...breakpointSources.map(({ source, breakpoints }) => source)
      ...breakpointSources.map(({ source, breakpoints }) => source)
    ];
    ];
@@ -82,7 +84,10 @@ class Breakpoints extends Component<Props> {
    return [
    return [
      ...breakpointSources.map(({ source, breakpoints, i }) => {
      ...breakpointSources.map(({ source, breakpoints, i }) => {
        const path = getDisplayPath(source, sources);
        const path = getDisplayPath(source, sources);
        const sortedBreakpoints = sortFormattedBreakpoints(breakpoints);
        const sortedBreakpoints = sortSelectedBreakpoints(
          breakpoints,
          selectedSource
        );


        return [
        return [
          <BreakpointHeading
          <BreakpointHeading
@@ -95,7 +100,10 @@ class Breakpoints extends Component<Props> {
            <Breakpoint
            <Breakpoint
              breakpoint={breakpoint}
              breakpoint={breakpoint}
              source={source}
              source={source}
              key={makeLocationId(breakpoint.selectedLocation)}
              selectedSource={selectedSource}
              key={makeLocationId(
                getSelectedLocation(breakpoint, selectedSource)
              )}
            />
            />
          ))
          ))
        ];
        ];
+5 −4
Original line number Original line Diff line number Diff line
@@ -6,7 +6,7 @@ import React from "react";
import { shallow } from "enzyme";
import { shallow } from "enzyme";


import Breakpoint from "../Breakpoint";
import Breakpoint from "../Breakpoint";
import { makeSource } from "../../../../utils/test-head";
import { makeSource, makeOriginalSource } from "../../../../utils/test-head";


describe("Breakpoint", () => {
describe("Breakpoint", () => {
  it("simple", () => {
  it("simple", () => {
@@ -31,7 +31,8 @@ describe("Breakpoint", () => {
  it("paused at an original location", () => {
  it("paused at an original location", () => {
    const { component } = render({
    const { component } = render({
      frame: { selectedLocation: location },
      frame: { selectedLocation: location },
      breakpoint: { selectedLocation: location }
      breakpoint: { location },
      selectedSource: makeOriginalSource("foo")
    });
    });


    expect(component).toMatchSnapshot();
    expect(component).toMatchSnapshot();
@@ -47,7 +48,6 @@ describe("Breakpoint", () => {


const generatedLocation = { sourceId: "foo", line: 53, column: 73 };
const generatedLocation = { sourceId: "foo", line: 53, column: 73 };
const location = { sourceId: "foo/original", line: 5, column: 7 };
const location = { sourceId: "foo/original", line: 5, column: 7 };
const selectedLocation = generatedLocation;


function render(overrides = {}) {
function render(overrides = {}) {
  const props = generateDefaults(overrides);
  const props = generateDefaults(overrides);
@@ -60,7 +60,8 @@ function render(overrides = {}) {


function makeBreakpoint(overrides = {}) {
function makeBreakpoint(overrides = {}) {
  return {
  return {
    selectedLocation,
    location,
    generatedLocation,
    disabled: false,
    disabled: false,
    ...overrides
    ...overrides
  };
  };
Loading