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
|
/* 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/>. */
/**
* Tells if a given Source Actor is registered in the redux store
*
* @param {Object} state
* @param {String} sourceActorId
* Source Actor ID
* @return {Boolean}
*/
export function hasSourceActor(state, sourceActorId) {
return state.sourceActors.mutableSourceActors.has(sourceActorId);
}
/**
* Get the Source Actor object. See create.js:createSourceActor()
*
* @param {Object} state
* @param {String} sourceActorId
* Source Actor ID
* @return {Object}
* The Source Actor object (if registered)
*/
export function getSourceActor(state, sourceActorId) {
return state.sourceActors.mutableSourceActors.get(sourceActorId);
}
/**
* Reports if the Source Actor relates to a valid source map / original source.
*
* @param {Object} state
* @param {String} sourceActorId
* Source Actor ID
* @return {Boolean}
* True if it has a valid source map/original object.
*/
export function isSourceActorWithSourceMap(state, sourceActorId) {
return state.sourceActors.mutableSourceActorsWithSourceMap.has(sourceActorId);
}
// Used by threads selectors
/**
* Get all Source Actor objects for a given thread. See create.js:createSourceActor()
*
* @param {Object} state
* @param {Array<String>} threadActorIDs
* List of Thread IDs
* @return {Array<Object>}
*/
export function getSourceActorsForThread(state, threadActorIDs) {
if (!Array.isArray(threadActorIDs)) {
threadActorIDs = [threadActorIDs];
}
const actors = [];
for (const sourceActor of state.sourceActors.mutableSourceActors.values()) {
if (threadActorIDs.includes(sourceActor.thread)) {
actors.push(sourceActor);
}
}
return actors;
}
/**
* Get the list of all breakable lines for a given source actor.
*
* @param {Object} state
* @param {String} sourceActorId
* Source Actor ID
* @return {AsyncValue<Array<Number>>}
* List of all the breakable lines.
*/
export function getSourceActorBreakableLines(state, sourceActorId) {
return state.sourceActors.mutableBreakableLines.get(sourceActorId);
}
// Used by sources selectors
/**
* Get the list of all breakable lines for a set of source actors.
*
* This is typically used to fetch the breakable lines of HTML sources
* which are made of multiple source actors (one per inline script).
*
* @param {Object} state
* @param {Array<String>} sourceActors
* List of Source Actors
* @param {Boolean} isHTML
* True, if we are fetching the breakable lines for an HTML source.
* For them, we have to aggregate the lines of each source actors.
* Otherwise, we might still have many source actors, but one per thread.
* In this case, we simply return the first source actor to have the lines ready.
* @return {Array<Number>}
* List of all the breakable lines.
*/
export function getBreakableLinesForSourceActors(state, sourceActors, isHTML) {
const allBreakableLines = [];
for (const sourceActor of sourceActors) {
const breakableLines = state.sourceActors.mutableBreakableLines.get(
sourceActor.id
);
if (breakableLines) {
if (isHTML) {
allBreakableLines.push(...breakableLines);
} else {
return breakableLines;
}
}
}
return allBreakableLines;
}
|