forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddBreakpoint.js
More file actions
156 lines (134 loc) · 4.17 KB
/
Copy pathaddBreakpoint.js
File metadata and controls
156 lines (134 loc) · 4.17 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
/* 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/>. */
import { isOriginalId } from "devtools-source-map";
import {
locationMoved,
breakpointExists,
assertBreakpoint,
createBreakpoint,
getASTLocation,
assertLocation
} from "../../utils/breakpoint";
import { PROMISE } from "../utils/middleware/promise";
import { getSource, getSymbols, getBreakpoint } from "../../selectors";
import { getGeneratedLocation } from "../../utils/source-maps";
import { getTextAtPosition } from "../../utils/source";
import { recordEvent } from "../../utils/telemetry";
async function addBreakpointPromise(getState, client, sourceMaps, breakpoint) {
const state = getState();
const source = getSource(state, breakpoint.location.sourceId);
const location = {
...breakpoint.location,
sourceId: source.id,
sourceUrl: source.url
};
const generatedLocation = await getGeneratedLocation(
state,
source,
location,
sourceMaps
);
const generatedSource = getSource(state, generatedLocation.sourceId);
assertLocation(location);
assertLocation(generatedLocation);
if (breakpointExists(state, location)) {
const newBreakpoint = { ...breakpoint, location, generatedLocation };
assertBreakpoint(newBreakpoint);
return { breakpoint: newBreakpoint };
}
const { id, hitCount, actualLocation } = await client.setBreakpoint(
generatedLocation,
breakpoint.condition,
isOriginalId(location.sourceId)
);
const newGeneratedLocation = actualLocation || generatedLocation;
const newLocation = await sourceMaps.getOriginalLocation(
newGeneratedLocation
);
const symbols = getSymbols(getState(), source);
const astLocation = await getASTLocation(source, symbols, newLocation);
const originalText = getTextAtPosition(source, location);
const text = getTextAtPosition(generatedSource, actualLocation);
const newBreakpoint = {
id,
disabled: false,
hidden: breakpoint.hidden,
loading: false,
condition: breakpoint.condition,
location: newLocation,
astLocation,
hitCount,
generatedLocation: newGeneratedLocation,
text,
originalText
};
assertBreakpoint(newBreakpoint);
const previousLocation = locationMoved(location, newLocation)
? location
: null;
return {
breakpoint: newBreakpoint,
previousLocation
};
}
/**
* Add a new hidden breakpoint
*
* @memberOf actions/breakpoints
* @param location
* @return {function(ThunkArgs)}
*/
export function addHiddenBreakpoint(location: Location) {
return ({ dispatch }: ThunkArgs) => {
return dispatch(addBreakpoint(location, { hidden: true }));
};
}
/**
* Enabling a breakpoint
* will reuse the existing breakpoint information that is stored.
*
* @memberof actions/breakpoints
* @static
* @param {Location} $1.location Location value
*/
export function enableBreakpoint(location: Location) {
return async ({ dispatch, getState, client, sourceMaps }: ThunkArgs) => {
const breakpoint = getBreakpoint(getState(), location);
if (!breakpoint || breakpoint.loading) {
return;
}
// To instantly reflect in the UI, we optimistically enable the breakpoint
const enabledBreakpoint = {
...breakpoint,
disabled: false
};
return dispatch({
type: "ENABLE_BREAKPOINT",
breakpoint: enabledBreakpoint,
[PROMISE]: addBreakpointPromise(getState, client, sourceMaps, breakpoint)
});
};
}
/**
* Add a new breakpoint
*
* @memberof actions/breakpoints
* @static
* @param {String} $1.condition Conditional breakpoint condition value
* @param {Boolean} $1.disabled Disable value for breakpoint value
*/
export function addBreakpoint(
location: Location,
{ condition, hidden }: addBreakpointOptions = {}
) {
const breakpoint = createBreakpoint(location, { condition, hidden });
return ({ dispatch, getState, sourceMaps, client }: ThunkArgs) => {
recordEvent("add_breakpoint");
return dispatch({
type: "ADD_BREAKPOINT",
breakpoint,
[PROMISE]: addBreakpointPromise(getState, client, sourceMaps, breakpoint)
});
};
}