mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-01 06:35:42 +00:00
Bug 1290263 - Source maps in console don't work after first log; r=jsantell
This commit is contained in:
parent
65ab32a8bb
commit
38164de257
@ -19,7 +19,6 @@ const { LocationStore, serialize, deserialize } = require("./location-store");
|
||||
function SourceMapService(target) {
|
||||
this._target = target;
|
||||
this._locationStore = new LocationStore();
|
||||
this._isInitialResolve = true;
|
||||
|
||||
EventEmitter.decorate(this);
|
||||
|
||||
@ -41,7 +40,6 @@ function SourceMapService(target) {
|
||||
* Clears the store containing the cached resolved locations and promises
|
||||
*/
|
||||
SourceMapService.prototype.reset = function () {
|
||||
this._isInitialResolve = true;
|
||||
this._locationStore.clear();
|
||||
};
|
||||
|
||||
@ -51,7 +49,6 @@ SourceMapService.prototype.destroy = function () {
|
||||
this._target.off("navigate", this.reset);
|
||||
this._target.off("will-navigate", this.reset);
|
||||
this._target.off("close", this.destroy);
|
||||
this._isInitialResolve = null;
|
||||
this._target = this._locationStore = null;
|
||||
};
|
||||
|
||||
@ -63,10 +60,7 @@ SourceMapService.prototype.destroy = function () {
|
||||
SourceMapService.prototype.subscribe = function (location, callback) {
|
||||
this.on(serialize(location), callback);
|
||||
this._locationStore.set(location);
|
||||
if (this._isInitialResolve) {
|
||||
this._resolveAndUpdate(location);
|
||||
this._isInitialResolve = false;
|
||||
}
|
||||
this._resolveAndUpdate(location);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -76,7 +70,12 @@ SourceMapService.prototype.subscribe = function (location, callback) {
|
||||
*/
|
||||
SourceMapService.prototype.unsubscribe = function (location, callback) {
|
||||
this.off(serialize(location), callback);
|
||||
this._locationStore.clearByURL(location.url);
|
||||
// Check to see if the store exists before attempting to clear a location
|
||||
// Sometimes un-subscribe happens during the destruction cascades and this
|
||||
// condition is to protect against that. Could be looked into in the future.
|
||||
if (this._locationStore) {
|
||||
this._locationStore.clearByURL(location.url);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@ -87,16 +86,10 @@ SourceMapService.prototype.unsubscribe = function (location, callback) {
|
||||
*/
|
||||
SourceMapService.prototype._resolveAndUpdate = function (location) {
|
||||
this._resolveLocation(location).then(resolvedLocation => {
|
||||
// We try to source map the first console log to initiate the source-updated event from
|
||||
// target. The isSameLocation check is to make sure we don't update the frame, if the
|
||||
// location is not source-mapped.
|
||||
if (resolvedLocation) {
|
||||
if (this._isInitialResolve) {
|
||||
if (!isSameLocation(location, resolvedLocation)) {
|
||||
this.emit(serialize(location), location, resolvedLocation);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// We try to source map the first console log to initiate the source-updated
|
||||
// event from target. The isSameLocation check is to make sure we don't update
|
||||
// the frame, if the location is not source-mapped.
|
||||
if (resolvedLocation && !isSameLocation(location, resolvedLocation)) {
|
||||
this.emit(serialize(location), location, resolvedLocation);
|
||||
}
|
||||
});
|
||||
@ -182,7 +175,6 @@ function resolveLocation(target, location) {
|
||||
if (newLocation.error) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return newLocation;
|
||||
});
|
||||
}
|
||||
@ -197,4 +189,4 @@ function isSameLocation(location, resolvedLocation) {
|
||||
return location.url === resolvedLocation.url &&
|
||||
location.line === resolvedLocation.line &&
|
||||
location.column === resolvedLocation.column;
|
||||
};
|
||||
}
|
||||
|
@ -19,25 +19,22 @@ const PAGE_URL = `${DEBUGGER_ROOT}doc_empty-tab-01.html`;
|
||||
const JS_URL = `${URL_ROOT}code_binary_search.js`;
|
||||
const COFFEE_URL = `${URL_ROOT}code_binary_search.coffee`;
|
||||
const { SourceMapService } = require("devtools/client/framework/source-map-service");
|
||||
const { serialize } = require("devtools/client/framework/location-store");
|
||||
|
||||
add_task(function* () {
|
||||
const toolbox = yield openNewTabAndToolbox(PAGE_URL, "jsdebugger");
|
||||
|
||||
const service = new SourceMapService(toolbox.target);
|
||||
|
||||
const aggregator = [];
|
||||
let aggregator = new Map();
|
||||
|
||||
function onUpdate(e, oldLoc, newLoc) {
|
||||
if (oldLoc.line === 6) {
|
||||
checkLoc1(oldLoc, newLoc);
|
||||
} else if (oldLoc.line === 8) {
|
||||
checkLoc2(oldLoc, newLoc);
|
||||
} else if (oldLoc.line === 2) {
|
||||
checkLoc3(oldLoc, newLoc);
|
||||
} else {
|
||||
throw new Error(`Unexpected location update: ${JSON.stringify(oldLoc)}`);
|
||||
}
|
||||
aggregator.push(newLoc);
|
||||
aggregator.set(serialize(oldLoc), newLoc);
|
||||
}
|
||||
|
||||
let loc1 = { url: JS_URL, line: 6 };
|
||||
@ -51,7 +48,9 @@ add_task(function* () {
|
||||
yield createScript(JS_URL);
|
||||
yield sourceShown;
|
||||
|
||||
yield waitUntil(() => aggregator.length === 2);
|
||||
yield waitUntil(() => aggregator.size === 2);
|
||||
|
||||
aggregator = Array.from(aggregator.values());
|
||||
|
||||
ok(aggregator.find(i => i.url === COFFEE_URL && i.line === 4), "found first updated location");
|
||||
ok(aggregator.find(i => i.url === COFFEE_URL && i.line === 6), "found second updated location");
|
||||
|
Loading…
Reference in New Issue
Block a user