Never interleave requests to get the page event listeners and avoid redundant requests for definition sites (bug 1106692). r=jlongster

This commit is contained in:
Panos Astithas 2015-03-12 10:09:35 +02:00
parent 54ed56a4dd
commit 53f1c03840

View File

@ -1729,6 +1729,18 @@ EventListeners.prototype = {
});
},
/**
* A semaphore that is used to ensure only a single protocol request for event
* listeners will be ongoing at any given time.
*/
_parsingListeners: false,
/**
* A flag the indicates whether a new request to fetch updated event listeners
* has arrived, while another one was in progress.
*/
_eventListenersUpdateNeeded: false,
/**
* Fetches the currently attached event listeners from the debugee.
* The thread client state is assumed to be "paused".
@ -1737,6 +1749,13 @@ EventListeners.prototype = {
* Invoked once the event listeners are fetched and displayed.
*/
_getListeners: function(aCallback) {
// Don't make a new request if one is still ongoing, but schedule one for
// later.
if (this._parsingListeners) {
this._eventListenersUpdateNeeded = true;
return;
}
this._parsingListeners = true;
gThreadClient.eventListeners(Task.async(function*(aResponse) {
if (aResponse.error) {
throw "Error getting event listeners: " + aResponse.message;
@ -1747,18 +1766,30 @@ EventListeners.prototype = {
aResponse.listeners.sort((a, b) => a.type > b.type ? 1 : -1);
// Add all the listeners in the debugger view event linsteners container.
let fetchedDefinitions = new Map();
for (let listener of aResponse.listeners) {
let definitionSite;
if (listener.function.class == "Function") {
if (fetchedDefinitions.has(listener.function.actor)) {
definitionSite = fetchedDefinitions.get(listener.function.actor);
} else if (listener.function.class == "Function") {
definitionSite = yield this._getDefinitionSite(listener.function);
fetchedDefinitions.set(listener.function.actor, definitionSite);
}
listener.function.url = definitionSite;
DebuggerView.EventListeners.addListener(listener, { staged: true });
}
fetchedDefinitions.clear();
// Flushes all the prepared events into the event listeners container.
DebuggerView.EventListeners.commit();
// Now that we are done, schedule a new update if necessary.
this._parsingListeners = false;
if (this._eventListenersUpdateNeeded) {
this._eventListenersUpdateNeeded = false;
this.scheduleEventListenersFetch();
}
// Notify that event listeners were fetched and shown in the view,
// and callback to resume the active thread if necessary.
window.emit(EVENTS.EVENT_LISTENERS_FETCHED);