Bug 1188697 - Update the tree's copy of the mozilla/source-map library; r=jryans
authorNick Fitzgerald <fitzgen@gmail.com>
Fri, 07 Aug 2015 13:49:16 -0700
changeset 288563 799742085c189b128d6cdb44454a2acb563be87f
parent 288562 f6a62807987dfc0ed86f3d752beb767efdd6d3cf
child 288564 30e0c3f20f2d7a8a8e75f191fe414ef57441bad6
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjryans
bugs1188697
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1188697 - Update the tree's copy of the mozilla/source-map library; r=jryans This update contains a fix for loadSourceError in the debugger when a source map has an absolute sourceRoot and one or more of its sources are absolute rather than relative to the sourceRoot.
toolkit/devtools/sourcemap/source-map.js
toolkit/devtools/sourcemap/tests/unit/Utils.jsm
toolkit/devtools/sourcemap/tests/unit/test_source_map_consumer.js
--- a/toolkit/devtools/sourcemap/source-map.js
+++ b/toolkit/devtools/sourcemap/source-map.js
@@ -843,17 +843,17 @@ define('source-map/util', ['require', 'e
     var path = aPath;
     var url = urlParse(aPath);
     if (url) {
       if (!url.path) {
         return aPath;
       }
       path = url.path;
     }
-    var isAbsolute = (path.charAt(0) === '/');
+    var isAbsolute = exports.isAbsolute(path);
 
     var parts = path.split(/\/+/);
     for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
       part = parts[i];
       if (part === '.') {
         parts.splice(i, 1);
       } else if (part === '..') {
         up++;
@@ -938,16 +938,20 @@ define('source-map/util', ['require', 'e
     if (aRootUrl) {
       aRootUrl.path = joined;
       return urlGenerate(aRootUrl);
     }
     return joined;
   }
   exports.join = join;
 
+  exports.isAbsolute = function (aPath) {
+    return aPath.charAt(0) === '/' || !!aPath.match(urlRegexp);
+  };
+
   /**
    * Make a path relative to a URL or another path.
    *
    * @param aRoot The root path or URL.
    * @param aPath The path or URL to be made relative to aRoot.
    */
   function relative(aRoot, aPath) {
     if (aRoot === "") {
@@ -1612,20 +1616,30 @@ define('source-map/source-map-consumer',
     var file = util.getArg(sourceMap, 'file', null);
 
     // Once again, Sass deviates from the spec and supplies the version as a
     // string rather than a number, so we use loose equality checking here.
     if (version != this._version) {
       throw new Error('Unsupported version: ' + version);
     }
 
-    // Some source maps produce relative source paths like "./foo.js" instead of
-    // "foo.js".  Normalize these first so that future comparisons will succeed.
-    // See bugzil.la/1090768.
-    sources = sources.map(util.normalize);
+    sources = sources
+      // Some source maps produce relative source paths like "./foo.js" instead of
+      // "foo.js".  Normalize these first so that future comparisons will succeed.
+      // See bugzil.la/1090768.
+      .map(util.normalize)
+      // Always ensure that absolute sources are internally stored relative to
+      // the source root, if the source root is absolute. Not doing this would
+      // be particularly problematic when the source root is a prefix of the
+      // source (valid, but why??). See github issue #199 and bugzil.la/1188982.
+      .map(function (source) {
+        return sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source)
+          ? util.relative(sourceRoot, source)
+          : source;
+      });
 
     // Pass `true` below to allow duplicate names and sources. While source maps
     // are intended to be compressed and deduplicated, the TypeScript compiler
     // sometimes generates source maps with duplicates in them. See Github issue
     // #72 and bugzil.la/889492.
     this._names = ArraySet.fromArray(names, true);
     this._sources = ArraySet.fromArray(sources, true);
 
--- a/toolkit/devtools/sourcemap/tests/unit/Utils.jsm
+++ b/toolkit/devtools/sourcemap/tests/unit/Utils.jsm
@@ -461,17 +461,17 @@ define('lib/source-map/util', ['require'
     var path = aPath;
     var url = urlParse(aPath);
     if (url) {
       if (!url.path) {
         return aPath;
       }
       path = url.path;
     }
-    var isAbsolute = (path.charAt(0) === '/');
+    var isAbsolute = exports.isAbsolute(path);
 
     var parts = path.split(/\/+/);
     for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
       part = parts[i];
       if (part === '.') {
         parts.splice(i, 1);
       } else if (part === '..') {
         up++;
@@ -556,16 +556,20 @@ define('lib/source-map/util', ['require'
     if (aRootUrl) {
       aRootUrl.path = joined;
       return urlGenerate(aRootUrl);
     }
     return joined;
   }
   exports.join = join;
 
+  exports.isAbsolute = function (aPath) {
+    return aPath.charAt(0) === '/' || !!aPath.match(urlRegexp);
+  };
+
   /**
    * Make a path relative to a URL or another path.
    *
    * @param aRoot The root path or URL.
    * @param aPath The path or URL to be made relative to aRoot.
    */
   function relative(aRoot, aPath) {
     if (aRoot === "") {
--- a/toolkit/devtools/sourcemap/tests/unit/test_source_map_consumer.js
+++ b/toolkit/devtools/sourcemap/tests/unit/test_source_map_consumer.js
@@ -1081,12 +1081,53 @@ define("test/source-map/test-source-map-
     // ... and then try and use the SourceMapGenerator again. This should not
     // throw.
     generator.toJSON();
 
     assert.ok(true, "Using a SourceMapGenerator again after creating a " +
                     "SourceMapConsumer from it should not throw");
   };
 
+  exports['test sources where their prefix is the source root: issue #199'] = function (assert, util) {
+    var testSourceMap = {
+      "version": 3,
+      "sources": ["/source/app/app/app.js"],
+      "names": ["System"],
+      "mappings": "AAAAA",
+      "file": "app/app.js",
+      "sourcesContent": ["'use strict';"],
+      "sourceRoot":"/source/"
+    };
+
+    var consumer = new SourceMapConsumer(testSourceMap);
+
+    function consumerHasSource(s) {
+      assert.ok(consumer.sourceContentFor(s));
+    }
+
+    consumer.sources.forEach(consumerHasSource);
+    testSourceMap.sources.forEach(consumerHasSource);
+  };
+
+  exports['test sources where their prefix is the source root and the source root is a url: issue #199'] = function (assert, util) {
+    var testSourceMap = {
+      "version": 3,
+      "sources": ["http://example.com/source/app/app/app.js"],
+      "names": ["System"],
+      "mappings": "AAAAA",
+      "sourcesContent": ["'use strict';"],
+      "sourceRoot":"http://example.com/source/"
+    };
+
+    var consumer = new SourceMapConsumer(testSourceMap);
+
+    function consumerHasSource(s) {
+      assert.ok(consumer.sourceContentFor(s));
+    }
+
+    consumer.sources.forEach(consumerHasSource);
+    testSourceMap.sources.forEach(consumerHasSource);
+  };
+
 });
 function run_test() {
   runSourceMapTests('test/source-map/test-source-map-consumer', do_throw);
 }