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
449 lines (401 loc) · 10.8 KB
/
breakpoints.js
File metadata and controls
449 lines (401 loc) · 10.8 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
/* 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
/**
* Redux actions for breakpoints
* @module actions/breakpoints
*/
import { PROMISE } from "./utils/middleware/promise";
import {
getBreakpoint,
getBreakpoints,
getSelectedSource,
getBreakpointAtLocation
} from "../selectors";
import { createBreakpoint, assertBreakpoint } from "../utils/breakpoint";
import addBreakpointPromise from "./breakpoints/addBreakpoint";
import remapLocations from "./breakpoints/remapLocations";
import { isEmptyLineInSource } from "../reducers/ast";
// this will need to be changed so that addCLientBreakpoint is removed
import { syncClientBreakpoint } from "./breakpoints/syncBreakpoint";
import type { ThunkArgs, Action } from "./types";
import type {
Breakpoint,
SourceId,
PendingBreakpoint,
Location
} from "../types";
import type { BreakpointsMap } from "../reducers/types";
type addBreakpointOptions = {
condition?: string,
hidden?: boolean
};
/**
* Syncing a breakpoint add breakpoint information that is stored, and
* contact the server for more data.
*
* @memberof actions/breakpoints
* @static
* @param {String} $1.sourceId String value
* @param {PendingBreakpoint} $1.location PendingBreakpoint value
*/
export function syncBreakpoint(
sourceId: SourceId,
pendingBreakpoint: PendingBreakpoint
) {
return async ({ dispatch, getState, client, sourceMaps }: ThunkArgs) => {
const { breakpoint, previousLocation } = await syncClientBreakpoint(
getState,
client,
sourceMaps,
sourceId,
pendingBreakpoint
);
return dispatch(
({
type: "SYNC_BREAKPOINT",
breakpoint,
previousLocation
}: Action)
);
};
}
/**
* 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) => {
return dispatch(
({
type: "ADD_BREAKPOINT",
breakpoint,
[PROMISE]: addBreakpointPromise(
getState,
client,
sourceMaps,
breakpoint
)
}: Action)
);
};
}
/**
* 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 }));
};
}
/**
* Remove a single breakpoint
*
* @memberof actions/breakpoints
* @static
*/
export function removeBreakpoint(location: Location) {
return ({ dispatch, getState, client }: ThunkArgs) => {
const bp = getBreakpoint(getState(), location);
if (!bp || bp.loading) {
return;
}
// If the breakpoint is already disabled, we don't need to communicate
// with the server. We just need to dispatch an action
// simulating a successful server request
if (bp.disabled) {
return dispatch(
({
type: "REMOVE_BREAKPOINT",
breakpoint: bp,
status: "done"
}: Action)
);
}
return dispatch(
({
type: "REMOVE_BREAKPOINT",
breakpoint: bp,
disabled: false,
[PROMISE]: client.removeBreakpoint(bp.generatedLocation)
}: Action)
);
};
}
/**
* 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;
}
return dispatch(
({
type: "ENABLE_BREAKPOINT",
breakpoint,
[PROMISE]: addBreakpointPromise(
getState,
client,
sourceMaps,
breakpoint
)
}: Action)
);
};
}
/**
* Disable a single breakpoint
*
* @memberof actions/breakpoints
* @static
*/
export function disableBreakpoint(location: Location) {
return async ({ dispatch, getState, client }: ThunkArgs) => {
const bp = getBreakpoint(getState(), location);
if (!bp || bp.loading) {
return;
}
await client.removeBreakpoint(bp.generatedLocation);
const newBreakpoint: Breakpoint = { ...bp, disabled: true };
return dispatch(
({
type: "DISABLE_BREAKPOINT",
breakpoint: newBreakpoint
}: Action)
);
};
}
/**
* Toggle All Breakpoints
*
* @memberof actions/breakpoints
* @static
*/
export function toggleAllBreakpoints(shouldDisableBreakpoints: boolean) {
return async ({ dispatch, getState, client }: ThunkArgs) => {
const breakpoints = getBreakpoints(getState());
const modifiedBreakpoints = [];
for (const [, breakpoint] of breakpoints) {
if (shouldDisableBreakpoints) {
await client.removeBreakpoint(breakpoint.generatedLocation);
const newBreakpoint: Breakpoint = { ...breakpoint, disabled: true };
modifiedBreakpoints.push(newBreakpoint);
} else {
const newBreakpoint: Breakpoint = { ...breakpoint, disabled: false };
modifiedBreakpoints.push(newBreakpoint);
}
}
if (shouldDisableBreakpoints) {
return dispatch(
({
type: "DISABLE_ALL_BREAKPOINTS",
breakpoints: modifiedBreakpoints
}: Action)
);
}
return dispatch(
({
type: "ENABLE_ALL_BREAKPOINTS",
breakpoints: modifiedBreakpoints
}: Action)
);
};
}
/**
* Toggle Breakpoints
*
* @memberof actions/breakpoints
* @static
*/
export function toggleBreakpoints(
shouldDisableBreakpoints: boolean,
breakpoints: BreakpointsMap
) {
return async ({ dispatch }: ThunkArgs) => {
for (const [, breakpoint] of breakpoints) {
if (shouldDisableBreakpoints) {
await dispatch(disableBreakpoint(breakpoint.location));
} else {
await dispatch(enableBreakpoint(breakpoint.location));
}
}
};
}
/**
* Removes all breakpoints
*
* @memberof actions/breakpoints
* @static
*/
export function removeAllBreakpoints() {
return async ({ dispatch, getState }: ThunkArgs) => {
const breakpoints = getBreakpoints(getState());
for (const [, breakpoint] of breakpoints) {
await dispatch(removeBreakpoint(breakpoint.location));
}
};
}
/**
* Removes breakpoints
*
* @memberof actions/breakpoints
* @static
*/
export function removeBreakpoints(breakpoints: BreakpointsMap) {
return async ({ dispatch }: ThunkArgs) => {
for (const [, breakpoint] of breakpoints) {
await dispatch(removeBreakpoint(breakpoint.location));
}
};
}
export function remapBreakpoints(sourceId: string) {
return async ({ dispatch, getState, sourceMaps }: ThunkArgs) => {
const breakpoints = getBreakpoints(getState());
const newBreakpoints = await remapLocations(
breakpoints,
sourceId,
sourceMaps
);
return dispatch(
({
type: "REMAP_BREAKPOINTS",
breakpoints: newBreakpoints
}: Action)
);
};
}
/**
* Update the condition of a breakpoint.
*
* @throws {Error} "not implemented"
* @memberof actions/breakpoints
* @static
* @param {Location} location
* @see DebuggerController.Breakpoints.addBreakpoint
* @param {string} condition
* The condition to set on the breakpoint
* @param {Boolean} $1.disabled Disable value for breakpoint value
*/
export function setBreakpointCondition(
location: Location,
{ condition }: addBreakpointOptions = {}
) {
return async ({ dispatch, getState, client, sourceMaps }: ThunkArgs) => {
const bp = getBreakpoint(getState(), location);
if (!bp) {
return dispatch(addBreakpoint(location, { condition }));
}
if (bp.loading) {
return;
}
if (bp.disabled) {
await dispatch(enableBreakpoint(location));
bp.disabled = !bp.disabled;
}
await client.setBreakpointCondition(
bp.id,
location,
condition,
sourceMaps.isOriginalId(bp.location.sourceId)
);
const newBreakpoint = { ...bp, condition };
assertBreakpoint(newBreakpoint);
return dispatch(
({
type: "SET_BREAKPOINT_CONDITION",
breakpoint: newBreakpoint
}: Action)
);
};
}
export function toggleBreakpoint(line: ?number, column?: number) {
return ({ dispatch, getState, client, sourceMaps }: ThunkArgs) => {
if (!line) {
return;
}
const state = getState();
const selectedSource = getSelectedSource(state);
const bp = getBreakpointAtLocation(state, { line, column });
const isEmptyLine = isEmptyLineInSource(state, line, selectedSource);
if ((!bp && isEmptyLine) || (bp && bp.loading)) {
return;
}
if (bp) {
// NOTE: it's possible the breakpoint has slid to a column
return dispatch(
removeBreakpoint({
sourceId: bp.location.sourceId,
sourceUrl: bp.location.sourceUrl,
line: bp.location.line,
column: column || bp.location.column
})
);
}
return dispatch(
addBreakpoint({
sourceId: selectedSource.get("id"),
sourceUrl: selectedSource.get("url"),
line: line,
column: column
})
);
};
}
export function addOrToggleDisabledBreakpoint(line: ?number, column?: number) {
return ({ dispatch, getState, client, sourceMaps }: ThunkArgs) => {
if (!line) {
return;
}
const selectedSource = getSelectedSource(getState());
const bp = getBreakpointAtLocation(getState(), { line, column });
if (bp && bp.loading) {
return;
}
if (bp) {
// NOTE: it's possible the breakpoint has slid to a column
return dispatch(
toggleDisabledBreakpoint(line, column || bp.location.column)
);
}
return dispatch(
addBreakpoint({
sourceId: selectedSource.get("id"),
sourceUrl: selectedSource.get("url"),
line: line,
column: column
})
);
};
}
export function toggleDisabledBreakpoint(line: number, column?: number) {
return ({ dispatch, getState, client, sourceMaps }: ThunkArgs) => {
const bp = getBreakpointAtLocation(getState(), { line, column });
if (!bp || bp.loading) {
return;
}
if (!bp.disabled) {
return dispatch(disableBreakpoint(bp.location));
}
return dispatch(enableBreakpoint(bp.location));
};
}