Skip to content

Commit fe5e7c5

Browse files
committed
Upgrade Event Listeners redux backend
1 parent 71c9e99 commit fe5e7c5

File tree

7 files changed

+79
-53
lines changed

7 files changed

+79
-53
lines changed

packages/devtools-client-adapters/src/firefox/commands.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,22 @@ function disablePrettyPrint(sourceId) {
144144
return sourceClient.disablePrettyPrint();
145145
}
146146

147+
function interrupt() {
148+
return threadClient.interrupt();
149+
}
150+
151+
function eventListeners() {
152+
return threadClient.eventListeners();
153+
}
154+
155+
function pauseGrip(func) {
156+
return threadClient.pauseGrip(func);
157+
}
158+
147159
const clientCommands = {
160+
interrupt,
161+
eventListeners,
162+
pauseGrip,
148163
resume,
149164
stepIn,
150165
stepOut,

packages/devtools-client-adapters/src/firefox/events.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const { createFrame, createSource } = require("./create");
2+
const { isEnabled } = require("devtools-config");
23

34
const CALL_STACK_PAGE_SIZE = 1000;
45

@@ -36,6 +37,10 @@ function resumed(_, packet) {
3637

3738
function newSource(_, { source }) {
3839
actions.newSource(createSource(source));
40+
41+
if (isEnabled("eventListeners")) {
42+
actions.fetchEventListeners();
43+
}
3944
}
4045

4146
const clientEvents = {

src/actions/event-listeners.js

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,51 @@
1010
*/
1111

1212
const constants = require("../constants");
13-
const { asPaused } = require("../utils/utils");
1413
const { reportException } = require("../utils/DevToolsUtils");
15-
const { Task } = require("../utils/task");
14+
const { getPause } = require("../selectors");
1615

1716
// delay is in ms
1817
const FETCH_EVENT_LISTENERS_DELAY = 200;
18+
let fetchListenersTimerID;
19+
20+
/**
21+
* @memberof utils/utils
22+
* @static
23+
*/
24+
async function asPaused(state: any, client: any, func: any) {
25+
if (!getPause(state)) {
26+
await client.interrupt();
27+
let result;
28+
29+
try {
30+
result = await func(client);
31+
} catch (e) {
32+
// Try to put the debugger back in a working state by resuming
33+
// it
34+
await client.resume();
35+
throw e;
36+
}
37+
38+
await client.resume();
39+
return result;
40+
}
41+
42+
return func(client);
43+
}
1944

2045
/**
2146
* @memberof actions/event-listeners
2247
* @static
2348
*/
2449
function fetchEventListeners() {
25-
return (dispatch, getState) => {
50+
return ({ dispatch, getState, client }) => {
2651
// Make sure we"re not sending a batch of closely repeated requests.
2752
// This can easily happen whenever new sources are fetched.
28-
setNamedTimeout(
29-
"event-listeners-fetch",
30-
FETCH_EVENT_LISTENERS_DELAY,
53+
if (fetchListenersTimerID) {
54+
clearTimeout(fetchListenersTimerID);
55+
}
56+
57+
fetchListenersTimerID = setTimeout(
3158
() => {
3259
// In case there is still a request of listeners going on (it
3360
// takes several RDP round trips right now), make sure we wait
@@ -49,23 +76,19 @@ function fetchEventListeners() {
4976
status: "begin"
5077
});
5178

52-
asPaused(gThreadClient, _getListeners).then(listeners => {
53-
// Notify that event listeners were fetched and shown in the view,
54-
// and callback to resume the active thread if necessary.
55-
window.emit(EVENTS.EVENT_LISTENERS_FETCHED);
56-
79+
asPaused(getState(), client, _getEventListeners).then(listeners => {
5780
dispatch({
5881
type: constants.FETCH_EVENT_LISTENERS,
5982
status: "done",
6083
listeners: listeners
6184
});
6285
});
63-
});
86+
}, FETCH_EVENT_LISTENERS_DELAY);
6487
};
6588
}
6689

67-
const _getListeners = Task.async(function* () {
68-
const response = yield gThreadClient.eventListeners();
90+
async function _getEventListeners(threadClient) {
91+
const response = await threadClient.eventListeners();
6992

7093
// Make sure all the listeners are sorted by the event type, since
7194
// they"re not guaranteed to be clustered together.
@@ -79,7 +102,10 @@ const _getListeners = Task.async(function* () {
79102
if (fetchedDefinitions.has(listener.function.actor)) {
80103
definitionSite = fetchedDefinitions.get(listener.function.actor);
81104
} else if (listener.function.class == "Function") {
82-
definitionSite = yield _getDefinitionSite(listener.function);
105+
definitionSite = await _getDefinitionSite(
106+
threadClient,
107+
listener.function
108+
);
83109
if (!definitionSite) {
84110
// We don"t know where this listener comes from so don"t show it in
85111
// the UI as breaking on it doesn"t work (bug 942899).
@@ -94,22 +120,22 @@ const _getListeners = Task.async(function* () {
94120
fetchedDefinitions.clear();
95121

96122
return listeners;
97-
});
123+
}
98124

99-
const _getDefinitionSite = Task.async(function* (func) {
100-
const grip = gThreadClient.pauseGrip(func);
125+
async function _getDefinitionSite(threadClient, func) {
126+
const grip = threadClient.pauseGrip(func);
101127
let response;
102128

103129
try {
104-
response = yield grip.getDefinitionSite();
130+
response = await grip.getDefinitionSite();
105131
} catch (e) {
106132
// Don't make this error fatal, it would break the entire events pane.
107133
reportException("_getDefinitionSite", e);
108134
return null;
109135
}
110136

111137
return response.source.url;
112-
});
138+
}
113139

114140
/**
115141
* @memberof actions/event-listeners

src/reducers/event-listeners.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ function update(state = initialState, action, emit) {
1414
switch (action.type) {
1515
case constants.UPDATE_EVENT_BREAKPOINTS:
1616
state.activeEventNames = action.eventNames;
17-
emit("activeEventNames", state.activeEventNames);
17+
// emit("activeEventNames", state.activeEventNames);
1818
break;
1919
case constants.FETCH_EVENT_LISTENERS:
2020
if (action.status === "begin") {
2121
state.fetchingListeners = true;
2222
} else if (action.status === "done") {
2323
state.fetchingListeners = false;
2424
state.listeners = action.listeners;
25-
emit("event-listeners", state.listeners);
2625
}
2726
break;
2827
case constants.NAVIGATE:
@@ -32,4 +31,11 @@ function update(state = initialState, action, emit) {
3231
return state;
3332
}
3433

35-
module.exports = update;
34+
function getEventListeners(state) {
35+
return state.listeners;
36+
}
37+
38+
module.exports = {
39+
update,
40+
getEventListeners
41+
};

src/reducers/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const pause = require("./pause");
1010
const ui = require("./ui");
1111

1212
module.exports = {
13-
eventListeners,
13+
eventListeners: eventListeners.update,
1414
sources: sources.update,
1515
breakpoints: breakpoints.update,
1616
pause: pause.update,

src/selectors.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const sources = require("./reducers/sources");
44
const pause = require("./reducers/pause");
55
const breakpoints = require("./reducers/breakpoints");
6+
const eventListeners = require("./reducers/event-listeners");
67
const ui = require("./reducers/ui");
78

89
/**
@@ -36,5 +37,7 @@ module.exports = {
3637
getFrames: pause.getFrames,
3738
getSelectedFrame: pause.getSelectedFrame,
3839

40+
getEventListeners: eventListeners.getEventListeners,
41+
3942
getFileSearchState: ui.getFileSearchState
4043
};

src/utils/utils.js

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,6 @@
1010
* @module utils/utils
1111
*/
1212

13-
const co = require("co");
14-
15-
/**
16-
* @memberof utils/utils
17-
* @static
18-
*/
19-
function asPaused(client: any, func: any) {
20-
if (client.state != "paused") {
21-
return co(function* () {
22-
yield client.interrupt();
23-
let result;
24-
25-
try {
26-
result = yield func();
27-
} catch (e) {
28-
// Try to put the debugger back in a working state by resuming
29-
// it
30-
yield client.resume();
31-
throw e;
32-
}
33-
34-
yield client.resume();
35-
return result;
36-
});
37-
}
38-
return func();
39-
}
40-
4113
/**
4214
* @memberof utils/utils
4315
* @static
@@ -225,7 +197,6 @@ function throttle(func: any, ms: number) {
225197
}
226198

227199
module.exports = {
228-
asPaused,
229200
handleError,
230201
promisify,
231202
truncateStr,

0 commit comments

Comments
 (0)