forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplay.js
More file actions
183 lines (147 loc) · 3.83 KB
/
Copy pathreplay.js
File metadata and controls
183 lines (147 loc) · 3.83 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
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
/* 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/>. */
// @flow
import { features } from "../utils/prefs";
import type { Action } from "../actions/types";
/**
* Breakpoints reducer
* @module reducers/replay
*/
export type ReplayState = {
history: any,
position: number
};
export function initialState(): ReplayState {
return {
history: [],
position: -1
};
}
const defaultFrameScopes = {
original: {},
generated: {}
};
function update(
state: ReplayState = initialState(),
action: Action
): ReplayState {
if (!features.replay) {
return state;
}
switch (action.type) {
case "TRAVEL_TO": {
return { ...state, position: action.position };
}
case "ADD_SCOPES": {
return addScopes(state, action);
}
case "MAP_SCOPES": {
return mapScopes(state, action);
}
case "CLEAR_HISTORY": {
return { history: [], position: -1 };
}
case "PAUSED": {
return paused(state, action);
}
case "EVALUATE_EXPRESSION": {
return evaluateExpression(state, action);
}
}
return state;
}
function addScopes(state: ReplayState, action: any) {
const { frame, status, value } = action;
const selectedFrameId = frame.id;
const instance = state.history[state.position];
if (!instance) {
return state;
}
const pausedInst = instance.paused;
const generated = {
...pausedInst.frameScopes.generated,
[selectedFrameId]: {
pending: status !== "done",
scope: value
}
};
const newPaused = {
...pausedInst,
frameScopes: {
...pausedInst.frameScopes,
generated
}
};
const history = [...state.history];
history[state.position] = { ...instance, paused: newPaused };
return { ...state, history };
}
function mapScopes(state: ReplayState, action: any) {
const { frame, status, value } = action;
const selectedFrameId = frame.id;
const instance = state.history[state.position];
if (!instance) {
return state;
}
const pausedInst = instance.paused;
const original = {
...pausedInst.frameScopes.original,
[selectedFrameId]: {
pending: status !== "done",
scope: value
}
};
const newPaused = {
...pausedInst,
frameScopes: {
...pausedInst.frameScopes,
original
}
};
const history = [...state.history];
history[state.position] = { ...instance, paused: newPaused };
return { ...state, history };
}
function evaluateExpression(state, action) {
const { input, value } = action;
const instance = state.history[state.position];
if (!instance) {
return state;
}
const prevExpressions = instance.expressions || [];
const expression = { input, value };
const expressions = [...prevExpressions, expression];
const history = [...state.history];
history[state.position] = { ...instance, expressions };
return { ...state, history };
}
function paused(state, action) {
const { selectedFrameId, frames, loadedObjects, why } = action;
// turn this into an object keyed by object id
const objectMap = {};
loadedObjects.forEach(obj => {
objectMap[obj.value.objectId] = obj;
});
const pausedInfo = {
isWaitingOnBreak: false,
selectedFrameId,
frames,
frameScopes: defaultFrameScopes,
loadedObjects: objectMap,
why
};
const history = [...state.history, { paused: pausedInfo }];
const position = state.position + 1;
return { ...state, history, position };
}
export function getHistory(state: any): any {
return state.replay.history;
}
export function getHistoryFrame(state: any, position: number): any {
return state.replay.history[position];
}
export function getHistoryPosition(state: any): any {
return state.replay.position;
}
export default update;