Bug 1388855 - Simplify source map URL extraction in stylesheet actor; r=gl

MozReview-Commit-ID: 3WeNugNx7M

--HG--
extra : rebase_source : 972c3faa9b2636f059043fbb3b12f7fbe922c6c4
This commit is contained in:
Tom Tromey 2017-08-09 13:47:23 -06:00
Родитель c355a3b8b9
Коммит eabdd82c6a
1 изменённых файлов: 30 добавлений и 52 удалений

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

@ -548,42 +548,40 @@ var StyleSheetActor = protocol.ActorClassWithSpec(styleSheetSpec, {
_fetchSourceMap: function () {
let deferred = defer();
this._getText().then(sheetContent => {
let url = this._extractSourceMapUrl(sheetContent);
if (!url) {
// no source map for this stylesheet
deferred.resolve(null);
return;
let url = this.rawSheet.sourceMapURL;
if (!url) {
// no source map for this stylesheet
deferred.resolve(null);
return deferred.promise;
}
url = normalize(url, this.safeHref);
let options = {
loadFromCache: false,
policy: Ci.nsIContentPolicy.TYPE_INTERNAL_STYLESHEET,
window: this.window
};
let map = fetch(url, options).then(({content}) => {
// Fetching the source map might have failed with a 404 or other. When
// this happens, SourceMapConsumer may fail with a JSON.parse error.
let consumer;
try {
consumer = new SourceMapConsumer(content);
} catch (e) {
deferred.reject(new Error(
`Source map at ${url} not found or invalid`));
return null;
}
this._setSourceMapRoot(consumer, url, this.safeHref);
this._sourceMap = promise.resolve(consumer);
url = normalize(url, this.safeHref);
let options = {
loadFromCache: false,
policy: Ci.nsIContentPolicy.TYPE_INTERNAL_STYLESHEET,
window: this.window
};
let map = fetch(url, options).then(({content}) => {
// Fetching the source map might have failed with a 404 or other. When
// this happens, SourceMapConsumer may fail with a JSON.parse error.
let consumer;
try {
consumer = new SourceMapConsumer(content);
} catch (e) {
deferred.reject(new Error(
`Source map at ${url} not found or invalid`));
return null;
}
this._setSourceMapRoot(consumer, url, this.safeHref);
this._sourceMap = promise.resolve(consumer);
deferred.resolve(consumer);
return consumer;
}, deferred.reject);
this._sourceMap = map;
deferred.resolve(consumer);
return consumer;
}, deferred.reject);
this._sourceMap = map;
return deferred.promise;
},
@ -613,26 +611,6 @@ var StyleSheetActor = protocol.ActorClassWithSpec(styleSheetSpec, {
: base;
},
/**
* Get the source map url specified in the text of a stylesheet.
*
* @param {string} content
* The text of the style sheet.
* @return {string}
* Url of source map.
*/
_extractSourceMapUrl: function (content) {
// If a SourceMap response header was saved on the style sheet, use it.
if (this.rawSheet.sourceMapURL) {
return this.rawSheet.sourceMapURL;
}
let matches = /sourceMappingURL\=([^\s\*]*)/.exec(content);
if (matches) {
return matches[1];
}
return null;
},
/**
* Protocol method that gets the location in the original source of a
* line, column pair in this stylesheet, if its source mapped, otherwise