Skip to content

Commit

Permalink
Bug 1403610 - update to source-map 0.6.1; r=bgrins
Browse files Browse the repository at this point in the history
Import the source-map 0.6.1 bundle.

MozReview-Commit-ID: AkVLlBJRD1l

--HG--
extra : rebase_source : 882b2ef4b2c3b2eac8733f408a4ce7a6aaa403d2
  • Loading branch information
tromey committed Sep 27, 2017
1 parent ef10ff5 commit 762c2f5
Show file tree
Hide file tree
Showing 18 changed files with 21,362 additions and 19,380 deletions.
29 changes: 11 additions & 18 deletions devtools/server/actors/stylesheets.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,13 +573,13 @@ var StyleSheetActor = protocol.ActorClassWithSpec(styleSheetSpec, {
// this happens, SourceMapConsumer may fail with a JSON.parse error.
let consumer;
try {
consumer = new SourceMapConsumer(content);
consumer = new SourceMapConsumer(content,
this._getSourceMapRoot(url, this.safeHref));
} 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);
Expand All @@ -602,19 +602,17 @@ var StyleSheetActor = protocol.ActorClassWithSpec(styleSheetSpec, {
},

/**
* Sets the source map's sourceRoot to be relative to the source map url.
* Compute the URL to pass to the SourceMapConsumer constructor as
* the "source map's URL".
*/
_setSourceMapRoot: function (sourceMap, absSourceMapURL, scriptURL) {
if (scriptURL.startsWith("blob:")) {
scriptURL = scriptURL.replace("blob:", "");
_getSourceMapRoot: function (absSourceMapURL, scriptURL) {
// Pass in the source map URL; except if it is a data: or blob:
// URL, fall back to using the source's URL, if possible.
if (scriptURL && (absSourceMapURL.startsWith("data:") ||
absSourceMapURL.startsWith("blob:"))) {
return scriptURL;
}
const base = dirname(
absSourceMapURL.startsWith("data:")
? scriptURL
: absSourceMapURL);
sourceMap.sourceRoot = sourceMap.sourceRoot
? normalize(sourceMap.sourceRoot, base)
: base;
return absSourceMapURL;
},

/**
Expand Down Expand Up @@ -1054,8 +1052,3 @@ function normalize(...urls) {
}
return base.spec;
}

function dirname(path) {
return Services.io.newURI(
".", null, Services.io.newURI(path)).spec;
}
33 changes: 10 additions & 23 deletions devtools/server/actors/utils/TabSources.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,8 @@ TabSources.prototype = {

let fetching = fetch(absSourceMapURL, { loadFromCache: false })
.then(({ content }) => {
let map = new SourceMapConsumer(content);
this._setSourceMapRoot(map, absSourceMapURL, sourceURL);
return map;
return new SourceMapConsumer(content,
this._getSourceMapRoot(absSourceMapURL, sourceURL));
})
.catch(error => {
if (!DevToolsUtils.reportingDisabled) {
Expand All @@ -480,28 +479,16 @@ TabSources.prototype = {
},

/**
* Sets the source map's sourceRoot to be relative to the source map url.
* Compute the URL to pass to the SourceMapConsumer constructor as
* the "source map's URL".
*/
_setSourceMapRoot: function (sourceMap, absSourceMapURL, scriptURL) {
// No need to do this fiddling if we won't be fetching any sources over the
// wire.
if (sourceMap.hasContentsOfAllSources()) {
return;
_getSourceMapRoot: function (absSourceMapURL, scriptURL) {
// Pass in the source map URL; except if it is a data: URL, fall
// back to using the source's URL, if possible.
if (scriptURL && absSourceMapURL.startsWith("data:")) {
return scriptURL;
}

const base = this._dirname(
absSourceMapURL.indexOf("data:") === 0
? scriptURL
: absSourceMapURL);
sourceMap.sourceRoot = sourceMap.sourceRoot
? joinURI(base, sourceMap.sourceRoot)
: base;
},

_dirname: function (path) {
let url = new URL(path);
let href = url.href;
return href.slice(0, href.lastIndexOf("/"));
return absSourceMapURL;
},

/**
Expand Down
2 changes: 1 addition & 1 deletion devtools/server/tests/unit/test_sourcemaps-06.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function testContents(sources, timesCalled, callback) {
do_check_true(!response.error,
"Should not get an error loading the source from sourcesContent");

let expectedContent = "content for " + source.url;
let expectedContent = "content for " + source.url.replace(/^.*\//, "");
do_check_eq(response.source, expectedContent,
"Should have the expected source content");

Expand Down
6 changes: 3 additions & 3 deletions devtools/server/tests/unit/test_sourcemaps-17.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ function test_source_map() {
do_check_true(!error);
do_check_eq(frames.length, 4);
// b.js should be skipped
do_check_eq(frames[0].where.source.url, "http://example.com/www/root/e.js");
do_check_eq(frames[1].where.source.url, "http://example.com/www/root/c.js");
do_check_eq(frames[2].where.source.url, "http://example.com/www/root/a.js");
do_check_eq(frames[0].where.source.url, "http://example.com/www/js/root/e.js");
do_check_eq(frames[1].where.source.url, "http://example.com/www/js/root/c.js");
do_check_eq(frames[2].where.source.url, "http://example.com/www/js/root/a.js");
do_check_eq(frames[3].where.source.url, null);

finishClient(gClient);
Expand Down
1 change: 0 additions & 1 deletion devtools/shared/sourcemap/UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ To upgrade the source-map library:
$ npm run-script build -or- nodejs Makefile.dryice.js (if you have issues with npm)
$ cp dist/source-map.js /path/to/mozilla-central/devtools/shared/sourcemap/source-map.js
$ cp dist/test/* /path/to/mozilla-central/devtools/shared/sourcemap/tests/unit/

Loading

0 comments on commit 762c2f5

Please sign in to comment.