Skip to content

Commit 5ce8b84

Browse files
authored
Refactor pause (2/2) (firefox-devtools#4989)
1 parent 9a34a3a commit 5ce8b84

27 files changed

Lines changed: 208 additions & 262 deletions

flow-typed/debugger-html.js

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,25 @@ declare module "debugger-html" {
147147
click: Function
148148
};
149149

150+
/**
151+
* why
152+
* @memberof types
153+
* @static
154+
*/
155+
declare type ExceptionReason = {|
156+
exception: string | Grip,
157+
message: string,
158+
type: "exception",
159+
frameFinished?: Object
160+
|};
161+
150162
/**
151163
* why
152164
* @memberof types
153165
* @static
154166
*/
155167
declare type Why =
156-
| {|
157-
exception: string | Grip,
158-
type: "exception",
159-
frameFinished?: Object
160-
|}
168+
| ExceptionReason
161169
| {
162170
type: string,
163171
frameFinished?: Object
@@ -205,6 +213,20 @@ declare module "debugger-html" {
205213
from: string
206214
};
207215

216+
/**
217+
* PreviewGrip
218+
* @memberof types
219+
* @static
220+
*/
221+
222+
declare type PreviewGrip = {
223+
kind: string,
224+
url: string,
225+
fileName: string,
226+
message: string,
227+
name: string
228+
};
229+
208230
/**
209231
* Grip
210232
* @memberof types
@@ -217,11 +239,7 @@ declare module "debugger-html" {
217239
frozen: boolean,
218240
isGlobal: boolean,
219241
ownPropertyLength: number,
220-
preview: {
221-
kind: string,
222-
url: string,
223-
fileName: string
224-
},
242+
preview: PreviewGrip,
225243
sealed: boolean,
226244
type: string
227245
};

src/actions/event-listeners.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
import { reportException } from "../utils/DevToolsUtils";
14-
import { getPause, getSourceByURL } from "../selectors";
14+
import { isPaused, getSourceByURL } from "../selectors";
1515

1616
// delay is in ms
1717
const FETCH_EVENT_LISTENERS_DELAY = 200;
@@ -22,7 +22,7 @@ let fetchListenersTimerID;
2222
* @static
2323
*/
2424
async function asPaused(state: any, client: any, func: any) {
25-
if (!getPause(state)) {
25+
if (!isPaused(state)) {
2626
await client.interrupt();
2727
let result;
2828

src/actions/pause/commands.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// @flow
66

7-
import { getPause, getSelectedSource, getTopFrame } from "../../selectors";
7+
import { isPaused, getSelectedSource, getTopFrame } from "../../selectors";
88
import { PROMISE } from "../utils/middleware/promise";
99
import { getNextStep } from "../../workers/parser";
1010
import { addHiddenBreakpoint } from "../breakpoints";
@@ -38,7 +38,7 @@ export function command(type: CommandType) {
3838
*/
3939
export function stepIn() {
4040
return ({ dispatch, getState }: ThunkArgs) => {
41-
if (getPause(getState())) {
41+
if (isPaused(getState())) {
4242
return dispatch(command("stepIn"));
4343
}
4444
};
@@ -52,7 +52,7 @@ export function stepIn() {
5252
*/
5353
export function stepOver() {
5454
return ({ dispatch, getState }: ThunkArgs) => {
55-
if (getPause(getState())) {
55+
if (isPaused(getState())) {
5656
return dispatch(astCommand("stepOver"));
5757
}
5858
};
@@ -66,7 +66,7 @@ export function stepOver() {
6666
*/
6767
export function stepOut() {
6868
return ({ dispatch, getState }: ThunkArgs) => {
69-
if (getPause(getState())) {
69+
if (isPaused(getState())) {
7070
return dispatch(command("stepOut"));
7171
}
7272
};
@@ -80,7 +80,7 @@ export function stepOut() {
8080
*/
8181
export function resume() {
8282
return ({ dispatch, getState }: ThunkArgs) => {
83-
if (getPause(getState())) {
83+
if (isPaused(getState())) {
8484
return dispatch(command("resume"));
8585
}
8686
};
@@ -101,7 +101,6 @@ export function astCommand(stepType: CommandType) {
101101
if (stepType == "stepOver") {
102102
const frame = getTopFrame(getState());
103103
const source = getSelectedSource(getState()).toJS();
104-
105104
const nextLocation = await getNextStep(source, frame.location);
106105
if (nextLocation) {
107106
await dispatch(addHiddenBreakpoint(nextLocation));

src/actions/sources.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,9 @@ export function selectLocation(location: Location, tabIndex: string = "") {
259259
const selectedSource = getSelectedSource(getState());
260260
if (
261261
prefs.autoPrettyPrint &&
262-
!getPrettySource(getState(), source.get("id")) &&
262+
!getPrettySource(getState(), selectedSource.get("id")) &&
263263
shouldPrettyPrint(selectedSource) &&
264-
isMinified(source)
264+
isMinified(selectedSource)
265265
) {
266266
await dispatch(togglePrettyPrint(source.get("id")));
267267
dispatch(closeTab(source.get("url")));

src/actions/utils/middleware/log.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function formatFrame(frame) {
4242
function formatPause(pause) {
4343
return {
4444
...pause,
45-
pauseInfo: { why: pause.pauseInfo.why },
45+
pauseInfo: { why: pause.why },
4646
scopes: [],
4747
frames: pause.frames.map(formatFrame),
4848
loadedObjects: []

src/components/Editor/DebugLine.js

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ import { isException } from "../../utils/pause";
1010
import { connect } from "react-redux";
1111
import {
1212
getVisibleSelectedFrame,
13-
getPause,
13+
getPauseReason,
1414
getSelectedSource
1515
} from "../../selectors";
1616

17-
import type { Frame, Pause } from "debugger-html";
17+
import type { Frame, Why } from "debugger-html";
1818
import type { SourceRecord } from "../../reducers/types";
1919

2020
type Props = {
2121
selectedFrame: Frame,
22-
pauseInfo: Pause,
22+
why: Why,
2323
selectedSource: SourceRecord
2424
};
2525

@@ -40,33 +40,29 @@ export class DebugLine extends Component<Props> {
4040
debugExpression: null;
4141

4242
componentDidUpdate(prevProps: Props) {
43-
const { pauseInfo, selectedFrame, selectedSource } = this.props;
44-
this.setDebugLine(pauseInfo, selectedFrame, selectedSource);
43+
const { why, selectedFrame, selectedSource } = this.props;
44+
this.setDebugLine(why, selectedFrame, selectedSource);
4545
}
4646

4747
componentWillUpdate() {
48-
const { pauseInfo, selectedFrame, selectedSource } = this.props;
49-
this.clearDebugLine(selectedFrame, selectedSource, pauseInfo);
48+
const { why, selectedFrame, selectedSource } = this.props;
49+
this.clearDebugLine(selectedFrame, selectedSource, why);
5050
}
5151

5252
componentDidMount() {
53-
const { pauseInfo, selectedFrame, selectedSource } = this.props;
54-
this.setDebugLine(pauseInfo, selectedFrame, selectedSource);
53+
const { why, selectedFrame, selectedSource } = this.props;
54+
this.setDebugLine(why, selectedFrame, selectedSource);
5555
}
5656

57-
setDebugLine(
58-
pauseInfo: Pause,
59-
selectedFrame: Frame,
60-
selectedSource: SourceRecord
61-
) {
57+
setDebugLine(why: Why, selectedFrame: Frame, selectedSource: SourceRecord) {
6258
if (!isDocumentReady(selectedSource, selectedFrame)) {
6359
return;
6460
}
6561
const sourceId = selectedFrame.location.sourceId;
6662
const doc = getDocument(sourceId);
6763

6864
const { line, column } = toEditorPosition(selectedFrame.location);
69-
const { markTextClass, lineClass } = this.getTextClasses(pauseInfo);
65+
const { markTextClass, lineClass } = this.getTextClasses(why);
7066
doc.addLineClass(line, "line", lineClass);
7167

7268
this.debugExpression = doc.markText(
@@ -76,11 +72,7 @@ export class DebugLine extends Component<Props> {
7672
);
7773
}
7874

79-
clearDebugLine(
80-
selectedFrame: Frame,
81-
selectedSource: SourceRecord,
82-
pause: Pause
83-
) {
75+
clearDebugLine(selectedFrame: Frame, selectedSource: SourceRecord, why: Why) {
8476
if (!isDocumentReady(selectedSource, selectedFrame)) {
8577
return;
8678
}
@@ -92,12 +84,12 @@ export class DebugLine extends Component<Props> {
9284
const sourceId = selectedFrame.location.sourceId;
9385
const { line } = toEditorPosition(selectedFrame.location);
9486
const doc = getDocument(sourceId);
95-
const { lineClass } = this.getTextClasses(pause);
87+
const { lineClass } = this.getTextClasses(why);
9688
doc.removeLineClass(line, "line", lineClass);
9789
}
9890

99-
getTextClasses(pause: Pause): TextClasses {
100-
if (isException(pause.why)) {
91+
getTextClasses(why: Why): TextClasses {
92+
if (isException(why)) {
10193
return {
10294
markTextClass: "debug-expression-error",
10395
lineClass: "new-debug-line-error"
@@ -116,6 +108,6 @@ export default connect(state => {
116108
return {
117109
selectedFrame: getVisibleSelectedFrame(state),
118110
selectedSource: getSelectedSource(state),
119-
pauseInfo: getPause(state)
111+
why: getPauseReason(state)
120112
};
121113
})(DebugLine);

src/components/Editor/GutterMenu.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
getSelectedLocation,
1414
getSelectedSource,
1515
getVisibleBreakpoints,
16-
getPause
16+
isPaused as getIsPaused
1717
} from "../../selectors";
1818

1919
import actions from "../../actions";
@@ -26,7 +26,7 @@ export function gutterMenu({
2626
breakpoint,
2727
line,
2828
event,
29-
pauseData,
29+
isPaused,
3030
toggleBreakpoint,
3131
openConditionalPanel,
3232
toggleDisabledBreakpoint,
@@ -91,7 +91,7 @@ export function gutterMenu({
9191

9292
const items = [toggleBreakpointItem, conditionalBreakpoint];
9393

94-
if (pauseData) {
94+
if (isPaused) {
9595
const continueToHereItem = {
9696
accesskey: L10N.getStr("editor.continueToHere.accesskey"),
9797
disabled: false,
@@ -161,7 +161,7 @@ export default connect(
161161
selectedLocation: getSelectedLocation(state),
162162
selectedSource: selectedSource,
163163
breakpoints: getVisibleBreakpoints(state),
164-
pauseData: getPause(state),
164+
isPaused: getIsPaused(state),
165165
contextMenu: getContextMenu(state),
166166
emptyLines: selectedSource
167167
? getEmptyLines(state, selectedSource.toJS())

src/components/SecondaryPanes/Breakpoints.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@ import { connect } from "react-redux";
1010
import { createSelector } from "reselect";
1111
import { bindActionCreators } from "redux";
1212
import { features } from "../../utils/prefs";
13-
import { isInterrupted } from "../../utils/pause";
1413
import classnames from "classnames";
1514
import actions from "../../actions";
1615
import {
1716
getSources,
1817
getSourceInSources,
19-
getPause,
20-
getBreakpoints
18+
getBreakpoints,
19+
getPauseReason,
20+
getTopFrame
2121
} from "../../selectors";
2222
import { makeLocationId } from "../../utils/breakpoint";
2323
import { endTruncateStr } from "../../utils/utils";
2424
import { getFilename } from "../../utils/source";
25+
import { isInterrupted } from "../../utils/pause";
2526
import { showMenu, buildMenu } from "devtools-contextmenu";
2627
import CloseButton from "../shared/Button/Close";
2728
import "./Breakpoints.css";
@@ -52,13 +53,13 @@ type Props = {
5253
openConditionalPanel: number => void
5354
};
5455

55-
function isCurrentlyPausedAtBreakpoint(pause, breakpoint) {
56-
if (!pause || !isInterrupted(pause.why)) {
56+
function isCurrentlyPausedAtBreakpoint(frame, why, breakpoint) {
57+
if (!isInterrupted(why)) {
5758
return false;
5859
}
5960

6061
const bpId = makeLocationId(breakpoint.location);
61-
const pausedId = makeLocationId(pause.frame.location);
62+
const pausedId = makeLocationId(frame.location);
6263
return bpId === pausedId;
6364
}
6465

@@ -406,9 +407,9 @@ class Breakpoints extends PureComponent<Props> {
406407
}
407408
}
408409

409-
function updateLocation(sources, pause, bp): LocalBreakpoint {
410+
function updateLocation(sources, frame, why, bp): LocalBreakpoint {
410411
const source = getSourceInSources(sources, bp.location.sourceId);
411-
const isCurrentlyPaused = isCurrentlyPausedAtBreakpoint(pause, bp);
412+
const isCurrentlyPaused = isCurrentlyPausedAtBreakpoint(frame, why, bp);
412413
const locationId = makeLocationId(bp.location);
413414

414415
const location = { ...bp.location, source };
@@ -420,10 +421,11 @@ function updateLocation(sources, pause, bp): LocalBreakpoint {
420421
const _getBreakpoints = createSelector(
421422
getBreakpoints,
422423
getSources,
423-
getPause,
424-
(breakpoints, sources, pause) =>
424+
getTopFrame,
425+
getPauseReason,
426+
(breakpoints, sources, frame, why) =>
425427
breakpoints
426-
.map(bp => updateLocation(sources, pause, bp))
428+
.map(bp => updateLocation(sources, frame, why, bp))
427429
.filter(
428430
bp => bp.location.source && !bp.location.source.get("isBlackBoxed")
429431
)

0 commit comments

Comments
 (0)