forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapFrames.js
More file actions
78 lines (65 loc) · 1.92 KB
/
mapFrames.js
File metadata and controls
78 lines (65 loc) · 1.92 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
// @flow
import { getFrames, getSymbols, getSource } from "../../selectors";
import { findClosestFunction } from "../../utils/ast";
import type { Frame } from "../../types";
import type { State } from "../../reducers/types";
import type { ThunkArgs } from "../types";
export function updateFrameLocation(frame: Frame, sourceMaps: any) {
return sourceMaps.getOriginalLocation(frame.location).then(loc => ({
...frame,
location: loc,
generatedLocation: frame.generatedLocation || frame.location
}));
}
function updateFrameLocations(
frames: Frame[],
sourceMaps: any
): Promise<Frame[]> {
if (!frames || frames.length == 0) {
return Promise.resolve(frames);
}
return Promise.all(
frames.map(frame => updateFrameLocation(frame, sourceMaps))
);
}
export function mapDisplayNames(frames: Frame[], getState: () => State) {
return frames.map(frame => {
const source = getSource(getState(), frame.location.sourceId);
const symbols = getSymbols(getState(), source);
if (!symbols || !symbols.functions) {
return frame;
}
const originalFunction = findClosestFunction(
symbols.functions,
frame.location
);
if (!originalFunction) {
return frame;
}
const originalDisplayName = originalFunction.name;
return { ...frame, originalDisplayName };
});
}
/**
* Map call stack frame locations and display names to originals.
* e.g.
* 1. When the debuggee pauses
* 2. When a source is pretty printed
* 3. When symbols are loaded
* @memberof actions/pause
* @static
*/
export function mapFrames() {
return async function({ dispatch, getState, sourceMaps }: ThunkArgs) {
const frames = getFrames(getState());
if (!frames) {
return;
}
let mappedFrames = await updateFrameLocations(frames, sourceMaps);
mappedFrames = mapDisplayNames(mappedFrames, getState);
dispatch({
type: "MAP_FRAMES",
frames: mappedFrames
});
};
}