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
77 lines (65 loc) · 1.98 KB
/
Copy pathaddBreakpoint.js
File metadata and controls
77 lines (65 loc) · 1.98 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
/* 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 {
locationMoved,
breakpointExists,
assertBreakpoint,
getASTLocation,
assertLocation
} from "../../utils/breakpoint";
import { getSource, getSymbols } from "../../selectors";
import { getGeneratedLocation } from "../../utils/source-maps";
export default async function addBreakpoint(
getState,
client,
sourceMaps,
{ breakpoint }
) {
const state = getState();
const source = getSource(state, breakpoint.location.sourceId);
const location = { ...breakpoint.location, sourceUrl: source.url };
const generatedLocation = await getGeneratedLocation(
state,
source.toJS(),
location,
sourceMaps
);
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,
sourceMaps.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 newBreakpoint = {
id,
disabled: false,
hidden: breakpoint.hidden,
loading: false,
condition: breakpoint.condition,
location: newLocation,
astLocation,
hitCount,
generatedLocation: newGeneratedLocation
};
assertBreakpoint(newBreakpoint);
const previousLocation = locationMoved(location, newLocation)
? location
: null;
return {
breakpoint: newBreakpoint,
previousLocation
};
}