mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-31 22:25:30 +00:00
Bug 1291877 - Source map optimization in console due to Unique Locations. r=jsantell
--HG-- extra : rebase_source : 890ed6da1a3ea2406334ed7565e9b1a79a14ebee
This commit is contained in:
parent
358c4a1bf6
commit
8bcb67462f
@ -19,6 +19,7 @@ const { LocationStore, serialize, deserialize } = require("./location-store");
|
||||
function SourceMapService(target) {
|
||||
this._target = target;
|
||||
this._locationStore = new LocationStore();
|
||||
this._isNotSourceMapped = new Map();
|
||||
|
||||
EventEmitter.decorate(this);
|
||||
|
||||
@ -37,10 +38,11 @@ function SourceMapService(target) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the store containing the cached resolved locations and promises
|
||||
* Clears the store containing the cached promised locations
|
||||
*/
|
||||
SourceMapService.prototype.reset = function () {
|
||||
this._locationStore.clear();
|
||||
this._isNotSourceMapped.clear();
|
||||
};
|
||||
|
||||
SourceMapService.prototype.destroy = function () {
|
||||
@ -49,15 +51,24 @@ SourceMapService.prototype.destroy = function () {
|
||||
this._target.off("navigate", this.reset);
|
||||
this._target.off("will-navigate", this.reset);
|
||||
this._target.off("close", this.destroy);
|
||||
this._target = this._locationStore = null;
|
||||
this._target = this._locationStore = this._isNotSourceMapped = null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets up listener for the callback to update the FrameView and tries to resolve location
|
||||
* Sets up listener for the callback to update the FrameView
|
||||
* and tries to resolve location, if it is source-mappable
|
||||
* @param location
|
||||
* @param callback
|
||||
*/
|
||||
SourceMapService.prototype.subscribe = function (location, callback) {
|
||||
// A valid candidate location for source-mapping should have a url and line.
|
||||
// Abort if there's no `url`, which means it's unsourcemappable anyway,
|
||||
// like an eval script.
|
||||
// From previous attempts to source-map locations, we also determine if a location
|
||||
// is not source-mapped.
|
||||
if (!location.url || !location.line || this._isNotSourceMapped.get(location.url)) {
|
||||
return;
|
||||
}
|
||||
this.on(serialize(location), callback);
|
||||
this._locationStore.set(location);
|
||||
this._resolveAndUpdate(location);
|
||||
@ -80,7 +91,7 @@ SourceMapService.prototype.unsubscribe = function (location, callback) {
|
||||
|
||||
/**
|
||||
* Tries to resolve the location and if successful,
|
||||
* emits the resolved location and caches it
|
||||
* emits the resolved location
|
||||
* @param location
|
||||
* @private
|
||||
*/
|
||||
@ -96,46 +107,48 @@ SourceMapService.prototype._resolveAndUpdate = function (location) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Validates the location model,
|
||||
* checks if there is existing promise to resolve location, if so returns cached promise
|
||||
* if not promised to resolve,
|
||||
* tries to resolve location and returns a promised location
|
||||
* Checks if there is existing promise to resolve location, if so returns cached promise
|
||||
* if not, tries to resolve location and returns a promised location
|
||||
* @param location
|
||||
* @return Promise<Object>
|
||||
* @private
|
||||
*/
|
||||
SourceMapService.prototype._resolveLocation = Task.async(function* (location) {
|
||||
// Location must have a url and a line
|
||||
if (!location.url || !location.line) {
|
||||
return null;
|
||||
}
|
||||
let resolvedLocation;
|
||||
const cachedLocation = this._locationStore.get(location);
|
||||
if (cachedLocation) {
|
||||
return cachedLocation;
|
||||
resolvedLocation = cachedLocation;
|
||||
} else {
|
||||
const promisedLocation = resolveLocation(this._target, location);
|
||||
if (promisedLocation) {
|
||||
this._locationStore.set(location, promisedLocation);
|
||||
return promisedLocation;
|
||||
resolvedLocation = promisedLocation;
|
||||
}
|
||||
}
|
||||
return resolvedLocation;
|
||||
});
|
||||
|
||||
/**
|
||||
* Checks if the `source-updated` event is fired from the target.
|
||||
* Checks to see if location store has the source url in its cache,
|
||||
* if so, tries to update each stale location in the store.
|
||||
* Determines if the source should be source-mapped or not.
|
||||
* @param _
|
||||
* @param sourceEvent
|
||||
* @private
|
||||
*/
|
||||
SourceMapService.prototype._onSourceUpdated = function (_, sourceEvent) {
|
||||
let { type, source } = sourceEvent;
|
||||
|
||||
// If we get a new source, and it's not a source map, abort;
|
||||
// we can have no actionable updates as this is just a new normal source.
|
||||
// Also abort if there's no `url`, which means it's unsourcemappable anyway,
|
||||
// like an eval script.
|
||||
if (!source.url || type === "newSource" && !source.isSourceMapped) {
|
||||
// Check Source Actor for sourceMapURL property (after Firefox 48)
|
||||
// If not present, utilize isSourceMapped and isPrettyPrinted properties
|
||||
// to estimate if a source is not source-mapped.
|
||||
const isNotSourceMapped = !(source.sourceMapURL ||
|
||||
source.isSourceMapped || source.isPrettyPrinted);
|
||||
if (type === "newSource" && isNotSourceMapped) {
|
||||
this._isNotSourceMapped.set(source.url, true);
|
||||
return;
|
||||
}
|
||||
let sourceUrl = null;
|
||||
@ -180,7 +193,7 @@ function resolveLocation(target, location) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the original location and resolved location are the same
|
||||
* Returns true if the original location and resolved location are the same
|
||||
* @param location
|
||||
* @param resolvedLocation
|
||||
* @returns {boolean}
|
||||
|
Loading…
Reference in New Issue
Block a user