mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-12 00:50:40 +00:00
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:
parent
3290f20402
commit
60057fbfab
@ -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,23 +189,25 @@ 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();
|
||||
|
||||
const map = this._mapsById.get(id);
|
||||
if (!map) {
|
||||
// State could have been cleared.
|
||||
return;
|
||||
}
|
||||
for (const id of ids) {
|
||||
const map = this._mapsById.get(id);
|
||||
if (!map) {
|
||||
// State could have been cleared.
|
||||
continue;
|
||||
}
|
||||
|
||||
map.loaded = Promise.resolve();
|
||||
for (const query of map.queries.values()) {
|
||||
query.action = null;
|
||||
query.result = null;
|
||||
if (this._prefValue) {
|
||||
this._dispatchQuery(query);
|
||||
map.loaded = Promise.resolve();
|
||||
for (const query of map.queries.values()) {
|
||||
query.action = null;
|
||||
query.result = null;
|
||||
if (this._prefValue) {
|
||||
this._dispatchQuery(query);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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,14 +484,16 @@ 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);
|
||||
setSourceMap(generatedId, Promise.resolve(sourceMapConsumer));
|
||||
for (const generatedId of generatedSourceIds) {
|
||||
setSourceMap(generatedId, Promise.resolve(sourceMapConsumer));
|
||||
}
|
||||
}
|
||||
|
||||
function clearSourceMaps() {
|
||||
@ -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,
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user