forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBreakpoints.js
More file actions
206 lines (178 loc) · 5.89 KB
/
Copy pathBreakpoints.js
File metadata and controls
206 lines (178 loc) · 5.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
// @flow
import React, { Component } from "react";
import { bindActionCreators } from "redux";
import { connect } from "react-redux";
import * as I from "immutable";
import classnames from "classnames";
import { createSelector } from "reselect";
import { sortBy } from "lodash";
import actions from "../../actions";
import CloseButton from "../shared/Button/Close";
import { endTruncateStr } from "../../utils/utils";
import { features } from "../../utils/prefs";
import { getFilename } from "../../utils/source";
import {
getSources,
getSourceInSources,
getBreakpoints,
getPauseReason,
getTopFrame
} from "../../selectors";
import { isInterrupted } from "../../utils/pause";
import { makeLocationId } from "../../utils/breakpoint";
import showContextMenu from "./BreakpointsContextMenu";
import type { Breakpoint, Location } from "../../types";
import "./Breakpoints.css";
type LocalBreakpoint = Breakpoint & {
location: any,
isCurrentlyPaused: boolean,
locationId: string
};
type BreakpointsMap = I.Map<string, LocalBreakpoint>;
type Props = {
breakpoints: BreakpointsMap,
enableBreakpoint: Location => void,
disableBreakpoint: Location => void,
selectLocation: Object => void,
removeBreakpoint: string => void,
removeAllBreakpoints: () => void,
removeBreakpoints: BreakpointsMap => void,
toggleBreakpoints: (boolean, BreakpointsMap) => void,
toggleAllBreakpoints: boolean => void,
toggleDisabledBreakpoint: number => void,
setBreakpointCondition: Location => void,
openConditionalPanel: number => void
};
function isCurrentlyPausedAtBreakpoint(frame, why, breakpoint) {
if (!frame || !isInterrupted(why)) {
return false;
}
const bpId = makeLocationId(breakpoint.location);
const pausedId = makeLocationId(frame.location);
return bpId === pausedId;
}
function getBreakpointFilename(source) {
return source && source.toJS ? getFilename(source.toJS()) : "";
}
function renderSourceLocation(source, line, column) {
const filename = getBreakpointFilename(source);
const isWasm = source && source.isWasm;
const columnVal = features.columnBreakpoints && column ? `:${column}` : "";
const bpLocation = isWasm
? `0x${line.toString(16).toUpperCase()}`
: `${line}${columnVal}`;
if (!filename) {
return null;
}
return (
<div className="location">
{`${endTruncateStr(filename, 30)}: ${bpLocation}`}
</div>
);
}
class Breakpoints extends Component<Props> {
shouldComponentUpdate(nextProps, nextState) {
const { breakpoints } = this.props;
return breakpoints !== nextProps.breakpoints;
}
handleCheckbox(breakpoint) {
if (breakpoint.loading) {
return;
}
if (breakpoint.disabled) {
this.props.enableBreakpoint(breakpoint.location);
} else {
this.props.disableBreakpoint(breakpoint.location);
}
}
selectBreakpoint(breakpoint) {
this.props.selectLocation(breakpoint.location);
}
removeBreakpoint(event, breakpoint) {
event.stopPropagation();
this.props.removeBreakpoint(breakpoint.location);
}
renderBreakpoint(breakpoint) {
const locationId = breakpoint.locationId;
const line = breakpoint.location.line;
const column = breakpoint.location.column;
const isCurrentlyPaused = breakpoint.isCurrentlyPaused;
const isDisabled = breakpoint.disabled;
const isConditional = !!breakpoint.condition;
const isHidden = breakpoint.hidden;
if (isHidden) {
return;
}
return (
<div
className={classnames({
breakpoint,
paused: isCurrentlyPaused,
disabled: isDisabled,
"is-conditional": isConditional
})}
key={locationId}
onClick={() => this.selectBreakpoint(breakpoint)}
onContextMenu={e =>
showContextMenu({ ...this.props, breakpoint, contextMenuEvent: e })
}
>
<input
type="checkbox"
className="breakpoint-checkbox"
checked={!isDisabled}
onChange={() => this.handleCheckbox(breakpoint)}
onClick={ev => ev.stopPropagation()}
/>
<label className="breakpoint-label" title={breakpoint.text}>
{renderSourceLocation(breakpoint.location.source, line, column)}
</label>
<CloseButton
handleClick={ev => this.removeBreakpoint(ev, breakpoint)}
tooltip={L10N.getStr("breakpoints.removeBreakpointTooltip")}
/>
</div>
);
}
render() {
const { breakpoints } = this.props;
const children =
breakpoints.size === 0 ? (
<div className="pane-info">{L10N.getStr("breakpoints.none")}</div>
) : (
sortBy(
[...breakpoints.valueSeq()],
[
bp => getBreakpointFilename(bp.location.source),
bp => bp.location.line
]
).map(bp => this.renderBreakpoint(bp))
);
return <div className="pane breakpoints-list">{children}</div>;
}
}
function updateLocation(sources, frame, why, bp): LocalBreakpoint {
const source = getSourceInSources(sources, bp.location.sourceId);
const isCurrentlyPaused = isCurrentlyPausedAtBreakpoint(frame, why, bp);
const locationId = makeLocationId(bp.location);
const location = { ...bp.location, source };
const localBP = { ...bp, location, locationId, isCurrentlyPaused };
return localBP;
}
const _getBreakpoints = createSelector(
getBreakpoints,
getSources,
getTopFrame,
getPauseReason,
(breakpoints, sources, frame, why) =>
breakpoints
.map(bp => updateLocation(sources, frame, why, bp))
.filter(bp => bp.location.source && !bp.location.source.isBlackBoxed)
);
export default connect(
(state, props) => ({ breakpoints: _getBreakpoints(state) }),
dispatch => bindActionCreators(actions, dispatch)
)(Breakpoints);