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
|
/* 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 {
getSelectedFrame,
getCurrentThread,
getIsCurrentThreadPaused,
getIsPaused,
} from "../../selectors/index";
import { PROMISE } from "../utils/middleware/promise";
import { evaluateExpressions } from "../expressions";
import { selectLocation } from "../sources/index";
import { fetchScopes } from "./fetchScopes";
import { fetchFrames } from "./fetchFrames";
import { recordEvent } from "../../utils/telemetry";
import { validateFrame } from "../../utils/context";
export function selectThread(thread) {
return async ({ dispatch, getState }) => {
if (getCurrentThread(getState()) === thread) {
return;
}
dispatch({ type: "SELECT_THREAD", thread });
const selectedFrame = getSelectedFrame(getState(), thread);
const serverRequests = [];
// Update the watched expressions as we may never have evaluated them against this thread
// Note that selectedFrame may be null if the thread isn't paused.
serverRequests.push(dispatch(evaluateExpressions(selectedFrame)));
// If we were paused on the newly selected thread, ensure:
// - select the source where we are paused,
// - fetching the paused stackframes,
// - fetching the paused scope, so that variable preview are working on the selected source.
// (frames and scopes is supposed to be fetched on pause,
// but if two threads pause concurrently, it might be cancelled)
if (selectedFrame) {
serverRequests.push(dispatch(selectLocation(selectedFrame.location)));
serverRequests.push(dispatch(fetchFrames(thread)));
serverRequests.push(dispatch(fetchScopes(selectedFrame)));
}
await Promise.all(serverRequests);
};
}
/**
* Debugger commands like stepOver, stepIn, stepOut, resume
*
* @param string type
*/
export function command(type) {
return async ({ dispatch, getState, client }) => {
if (!type) {
return null;
}
// For now, all commands are by default against the currently selected thread
const thread = getCurrentThread(getState());
const frame = getSelectedFrame(getState(), thread);
return dispatch({
type: "COMMAND",
command: type,
thread,
[PROMISE]: client[type](thread, frame?.id),
});
};
}
/**
* StepIn
*
* @returns {Function} {@link command}
*/
export function stepIn() {
return ({ dispatch, getState }) => {
if (!getIsCurrentThreadPaused(getState())) {
return null;
}
return dispatch(command("stepIn"));
};
}
/**
* stepOver
*
* @returns {Function} {@link command}
*/
export function stepOver() {
return ({ dispatch, getState }) => {
if (!getIsCurrentThreadPaused(getState())) {
return null;
}
return dispatch(command("stepOver"));
};
}
/**
* stepOut
*
* @returns {Function} {@link command}
*/
export function stepOut() {
return ({ dispatch, getState }) => {
if (!getIsCurrentThreadPaused(getState())) {
return null;
}
return dispatch(command("stepOut"));
};
}
/**
* resume
*
* @returns {Function} {@link command}
*/
export function resume() {
return ({ dispatch, getState }) => {
if (!getIsCurrentThreadPaused(getState())) {
return null;
}
recordEvent("continue");
return dispatch(command("resume"));
};
}
/**
* restart frame
*/
export function restart(frame) {
return async ({ dispatch, getState, client }) => {
if (!getIsPaused(getState(), frame.thread)) {
return null;
}
validateFrame(getState(), frame);
return dispatch({
type: "COMMAND",
command: "restart",
thread: frame.thread,
[PROMISE]: client.restart(frame.thread, frame.id),
});
};
}
|