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
|
/* 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 { getThreadPauseState } from "../reducers/pause";
import { getSelectedSource, getSelectedLocation } from "./sources";
import { getBlackBoxRanges } from "./source-blackbox";
// eslint-disable-next-line
import { getSelectedLocation as _getSelectedLocation } from "../utils/selected-location";
import { isFrameBlackBoxed } from "../utils/source";
import { createSelector } from "devtools/client/shared/vendor/reselect";
export const getSelectedFrame = createSelector(
(state, thread) => state.pause.threads[thread],
threadPauseState => {
if (!threadPauseState) return null;
const { selectedFrameId, frames } = threadPauseState;
if (frames) {
return frames.find(frame => frame.id == selectedFrameId);
}
return null;
}
);
export const getVisibleSelectedFrame = createSelector(
getSelectedLocation,
state => getSelectedFrame(state, getCurrentThread(state)),
(selectedLocation, selectedFrame) => {
if (!selectedFrame) {
return null;
}
const { id, displayName } = selectedFrame;
return {
id,
displayName,
location: _getSelectedLocation(selectedFrame, selectedLocation),
};
}
);
export function getContext(state) {
return state.pause.cx;
}
export function getThreadContext(state) {
return state.pause.threadcx;
}
export function getNavigateCounter(state) {
return state.pause.threadcx.navigateCounter;
}
export function getPauseReason(state, thread) {
return getThreadPauseState(state.pause, thread).why;
}
export function getShouldBreakpointsPaneOpenOnPause(state, thread) {
return getThreadPauseState(state.pause, thread)
.shouldBreakpointsPaneOpenOnPause;
}
export function getPauseCommand(state, thread) {
return getThreadPauseState(state.pause, thread).command;
}
export function isStepping(state, thread) {
return ["stepIn", "stepOver", "stepOut"].includes(
getPauseCommand(state, thread)
);
}
export function getCurrentThread(state) {
return getThreadContext(state).thread;
}
export function getIsPaused(state, thread) {
return getThreadPauseState(state.pause, thread).isPaused;
}
export function getIsCurrentThreadPaused(state) {
return getIsPaused(state, getCurrentThread(state));
}
export function isEvaluatingExpression(state, thread) {
return getThreadPauseState(state.pause, thread).command === "expression";
}
export function getIsWaitingOnBreak(state, thread) {
return getThreadPauseState(state.pause, thread).isWaitingOnBreak;
}
export function getShouldPauseOnDebuggerStatement(state) {
return state.pause.shouldPauseOnDebuggerStatement;
}
export function getShouldPauseOnExceptions(state) {
return state.pause.shouldPauseOnExceptions;
}
export function getShouldPauseOnCaughtExceptions(state) {
return state.pause.shouldPauseOnCaughtExceptions;
}
export function getFrames(state, thread) {
const { frames, framesLoading } = getThreadPauseState(state.pause, thread);
return framesLoading ? null : frames;
}
export const getCurrentThreadFrames = createSelector(
state => {
const { frames, framesLoading } = getThreadPauseState(
state.pause,
getCurrentThread(state)
);
if (framesLoading) {
return [];
}
return frames;
},
getBlackBoxRanges,
(frames, blackboxedRanges) => {
return frames.filter(frame => !isFrameBlackBoxed(frame, blackboxedRanges));
}
);
function getGeneratedFrameId(frameId) {
if (frameId.includes("-originalFrame")) {
// The mapFrames can add original stack frames -- get generated frameId.
return frameId.substr(0, frameId.lastIndexOf("-originalFrame"));
}
return frameId;
}
export function getGeneratedFrameScope(state, frame) {
if (!frame) {
return null;
}
return getFrameScopes(state, frame.thread).generated[
getGeneratedFrameId(frame.id)
];
}
export function getOriginalFrameScope(state, frame) {
if (!frame) {
return null;
}
// Only compute original scope if we are currently showing an original source.
const source = getSelectedSource(state);
if (!source || !source.isOriginal) {
return null;
}
const original = getFrameScopes(state, frame.thread).original[
getGeneratedFrameId(frame.id)
];
if (original && (original.pending || original.scope)) {
return original;
}
return null;
}
// This is only used by tests
export function getFrameScopes(state, thread) {
return getThreadPauseState(state.pause, thread).frameScopes;
}
export function getSelectedFrameBindings(state, thread) {
const scopes = getFrameScopes(state, thread);
const selectedFrameId = getSelectedFrameId(state, thread);
if (!scopes || !selectedFrameId) {
return null;
}
const frameScope = scopes.generated[selectedFrameId];
if (!frameScope || frameScope.pending) {
return null;
}
let currentScope = frameScope.scope;
let frameBindings = [];
while (currentScope && currentScope.type != "object") {
if (currentScope.bindings) {
const bindings = Object.keys(currentScope.bindings.variables);
const args = [].concat(
...currentScope.bindings.arguments.map(argument =>
Object.keys(argument)
)
);
frameBindings = [...frameBindings, ...bindings, ...args];
}
currentScope = currentScope.parent;
}
return frameBindings;
}
function getFrameScope(state, frame) {
return (
getOriginalFrameScope(state, frame) || getGeneratedFrameScope(state, frame)
);
}
// This is only used by tests
export function getSelectedScope(state, thread) {
const frame = getSelectedFrame(state, thread);
const frameScope = getFrameScope(state, frame);
if (!frameScope) {
return null;
}
return frameScope.scope || null;
}
export function getSelectedOriginalScope(state, thread) {
const frame = getSelectedFrame(state, thread);
return getOriginalFrameScope(state, frame);
}
export function getSelectedScopeMappings(state, thread) {
const frameId = getSelectedFrameId(state, thread);
if (!frameId) {
return null;
}
return getFrameScopes(state, thread).mappings[frameId];
}
export function getSelectedFrameId(state, thread) {
return getThreadPauseState(state.pause, thread).selectedFrameId;
}
export function isTopFrameSelected(state, thread) {
const selectedFrameId = getSelectedFrameId(state, thread);
const topFrame = getTopFrame(state, thread);
return selectedFrameId == topFrame?.id;
}
export function getTopFrame(state, thread) {
const frames = getFrames(state, thread);
return frames?.[0];
}
// getTopFrame wouldn't return the top frame if the frames are still being fetched
export function getCurrentlyFetchedTopFrame(state, thread) {
const { frames } = getThreadPauseState(state.pause, thread);
return frames?.[0];
}
export function hasFrame(state, frame) {
// Don't use getFrames as it returns null when the frames are still loading
const { frames } = getThreadPauseState(state.pause, frame.thread);
if (!frames) {
return false;
}
// Compare IDs and not frame objects as they get cloned during mapping
return frames.some(f => f.id == frame.id);
}
export function getSkipPausing(state) {
return state.pause.skipPausing;
}
export function isMapScopesEnabled(state) {
return state.pause.mapScopes;
}
export function getInlinePreviews(state, thread, frameId) {
return getThreadPauseState(state.pause, thread).inlinePreview[
getGeneratedFrameId(frameId)
];
}
// This is only used by tests
export function getSelectedInlinePreviews(state) {
const thread = getCurrentThread(state);
const frameId = getSelectedFrameId(state, thread);
if (!frameId) {
return null;
}
return getInlinePreviews(state, thread, frameId);
}
export function getLastExpandedScopes(state, thread) {
return getThreadPauseState(state.pause, thread).lastExpandedScopes;
}
|