Bug 1814652 - [devtools] Rename SourceMapLoader#applySourceMap and change its signature. r=ochameau.

Let's make it take an array of ids so we don't need
to create multiple SourceMapConsumer.

Differential Revision: https://phabricator.services.mozilla.com/D168685
This commit is contained in:
Nicolas Chevobbe 2023-02-07 15:05:36 +00:00
Родитель 3290f20402
Коммит 60057fbfab
5 изменённых файлов: 43 добавлений и 29 удалений

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

@ -59,13 +59,18 @@ export async function prettyPrintSource(
text: contentValue.value,
url,
});
await sourceMapLoader.applySourceMap(generatedSource.id, sourceMap);
// The source map URL service used by other devtools listens to changes to
// sources based on their actor IDs, so apply the sourceMap there too.
for (const { actor } of actors) {
await sourceMapLoader.applySourceMap(actor, sourceMap);
}
const generatedSourceIds = [
generatedSource.id,
...actors.map(item => item.actor),
];
await sourceMapLoader.setSourceMapForGeneratedSources(
generatedSourceIds,
sourceMap
);
return {
text: code,
contentType: "text/javascript",

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

@ -41,7 +41,7 @@ class SourceMapURLService {
// subscribers to that service can be updated as
// well.
this._sourceMapLoader.on(
"source-map-applied",
"source-map-created",
this.newSourceMapCreated.bind(this)
);
}
@ -189,15 +189,16 @@ class SourceMapURLService {
* Tell the URL service than some external entity has registered a sourcemap
* in the worker for one of the source files.
*
* @param {string} id The actor ID of the source that had the map registered.
* @param {Array<string>} ids The actor ids of the sources that had the map registered.
*/
async newSourceMapCreated(id) {
async newSourceMapCreated(ids) {
await this._ensureAllSourcesPopulated();
for (const id of ids) {
const map = this._mapsById.get(id);
if (!map) {
// State could have been cleared.
return;
continue;
}
map.loaded = Promise.resolve();
@ -209,6 +210,7 @@ class SourceMapURLService {
}
}
}
}
_syncPrevValue() {
this._prefValue = Services.prefs.getBoolPref(SOURCE_MAP_PREF);

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

@ -25,7 +25,9 @@ const {
} = require("resource://devtools/client/shared/source-map-loader/utils/index.js");
class SourceMapLoader extends WorkerDispatcher {
#_applySourceMap = this.task("applySourceMap");
#_setSourceMapForGeneratedSources = this.task(
"setSourceMapForGeneratedSources"
);
#_getOriginalURLs = this.task("getOriginalURLs");
#_getOriginalSourceText = this.task("getOriginalSourceText");
@ -93,12 +95,15 @@ class SourceMapLoader extends WorkerDispatcher {
clearSourceMaps = this.task("clearSourceMaps");
getOriginalStackFrames = this.task("getOriginalStackFrames");
async applySourceMap(generatedId, ...rest) {
const rv = await this.#_applySourceMap(generatedId, ...rest);
async setSourceMapForGeneratedSources(generatedIds, sourceMap) {
const rv = await this.#_setSourceMapForGeneratedSources(
generatedIds,
sourceMap
);
// Notify and ensure waiting for the SourceMapURLService to process the source map before resolving.
// Otherwise tests start failing because of pending request made by this component.
await this.emitAsync("source-map-applied", generatedId);
await this.emitAsync("source-map-created", generatedIds);
return rv;
}

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

@ -484,15 +484,17 @@ async function getFileGeneratedRange(originalSourceId) {
}
/**
* Apply a sourceMap to a given source id
* Set the sourceMap for multiple passed source ids.
*
* @param {string} generatedId
* @param {Array<string>} generatedSourceIds
* @param {Object} map: An actual sourcemap (as generated with SourceMapGenerator#toJSON)
*/
function applySourceMap(generatedId, map) {
function setSourceMapForGeneratedSources(generatedSourceIds, map) {
const sourceMapConsumer = new SourceMapConsumer(map);
for (const generatedId of generatedSourceIds) {
setSourceMap(generatedId, Promise.resolve(sourceMapConsumer));
}
}
function clearSourceMaps() {
clearSourceMapsRequests();
@ -511,6 +513,6 @@ module.exports = {
getOriginalSourceText,
getGeneratedRangesForOriginal,
getFileGeneratedRange,
applySourceMap,
setSourceMapForGeneratedSources,
clearSourceMaps,
};

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

@ -20,7 +20,7 @@ const {
getGeneratedRangesForOriginal,
getFileGeneratedRange,
clearSourceMaps,
applySourceMap,
setSourceMapForGeneratedSources,
} = require("resource://devtools/client/shared/source-map-loader/source-map.js");
const {
@ -45,6 +45,6 @@ self.onmessage = workerHandler({
getOriginalStackFrames,
getGeneratedRangesForOriginal,
getFileGeneratedRange,
applySourceMap,
setSourceMapForGeneratedSources,
clearSourceMaps,
});