Bug 1620280 - [devtools] Simplify things around sourceLoading promise. r=jdescottes

This was relevant before as we were calling "ThreadActor.getSources"/"StyleSheets.getStyleSheets",
and by the time these requests resolved, we would have navigated to a new URL and need to ignore their response.
I think it is safe to drop this now as these requests may still be pending if we use legacy listeners,
but the call to unwatchResources should immediately unregister _onResourceAvailable and ignore any pending data
coming late.

Differential Revision: https://phabricator.services.mozilla.com/D90428
This commit is contained in:
Alexandre Poirot 2020-10-05 08:28:58 +00:00
Родитель b44cfc42a0
Коммит 09ffba351a
1 изменённых файлов: 23 добавлений и 24 удалений

Просмотреть файл

@ -28,11 +28,11 @@ class SourceMapURLService {
this._urlToIDMap = new Map(); this._urlToIDMap = new Map();
this._mapsById = new Map(); this._mapsById = new Map();
this._sourcesLoading = null; this._sourcesLoading = null;
this._onResourceAvailable = this._onResourceAvailable.bind(this);
this._runningCallback = false; this._runningCallback = false;
this._syncPrevValue = this._syncPrevValue.bind(this); this._syncPrevValue = this._syncPrevValue.bind(this);
this._clearAllState = this._clearAllState.bind(this); this._clearAllState = this._clearAllState.bind(this);
this._onNewStyleSheet = this._onNewStyleSheet.bind(this);
this._target.on("will-navigate", this._clearAllState); this._target.on("will-navigate", this._clearAllState);
@ -416,33 +416,20 @@ class SourceMapURLService {
if (!this._prefValue) { if (!this._prefValue) {
return null; return null;
} }
if (this._target.isWorkerTarget) {
return;
}
if (!this._sourcesLoading) { if (!this._sourcesLoading) {
const sourcesLoading = (async () => { const { resourceWatcher } = this._toolbox;
if (this._target.isWorkerTarget) { const { STYLESHEET, SOURCE } = resourceWatcher.TYPES;
return;
}
const { resourceWatcher } = this._toolbox; this._sourcesLoading = resourceWatcher.watchResources(
const { STYLESHEET, SOURCE } = resourceWatcher.TYPES; [STYLESHEET, SOURCE],
{
this._onResourceAvailable = resources => {
if (this._sourcesLoading === sourcesLoading) {
for (const resource of resources) {
if (resource.resourceType == STYLESHEET) {
this._onNewStyleSheet(resource);
} else if (resource.resourceType == SOURCE) {
this._onNewJavascript(resource);
}
}
}
};
await resourceWatcher.watchResources([STYLESHEET, SOURCE], {
onAvailable: this._onResourceAvailable, onAvailable: this._onResourceAvailable,
}); }
})(); );
this._sourcesLoading = sourcesLoading;
} }
return this._sourcesLoading; return this._sourcesLoading;
@ -455,6 +442,18 @@ class SourceMapURLService {
return Promise.resolve(); return Promise.resolve();
} }
_onResourceAvailable(resources) {
const { resourceWatcher } = this._toolbox;
const { STYLESHEET, SOURCE } = resourceWatcher.TYPES;
for (const resource of resources) {
if (resource.resourceType == STYLESHEET) {
this._onNewStyleSheet(resource);
} else if (resource.resourceType == SOURCE) {
this._onNewJavascript(resource);
}
}
}
_convertPendingURLSubscriptionsToID(url, id) { _convertPendingURLSubscriptionsToID(url, id) {
const urlSubscriptions = this._pendingURLSubscriptions.get(url); const urlSubscriptions = this._pendingURLSubscriptions.get(url);
if (!urlSubscriptions) { if (!urlSubscriptions) {