Bug 1166048 - Part 0: Upgrade the tree's copy of the mozilla/source-map library. r=jlongster, a=sylvestre
authorNick Fitzgerald <fitzgen@gmail.com>
Wed, 08 Jul 2015 14:40:14 -0700
changeset 275337 357649efb20886f8b46fd63aa44f7711667ae9c1
parent 275336 34bd36c882163c41a5a2563c0bb4071b34ac7fbf
child 275338 7c965ad0f7e7c0dc40343d02a13b653e5ee4ff65
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjlongster, sylvestre
bugs1166048
milestone40.0
Bug 1166048 - Part 0: Upgrade the tree's copy of the mozilla/source-map library. r=jlongster, a=sylvestre
toolkit/devtools/sourcemap/SourceMap.jsm
toolkit/devtools/sourcemap/tests/unit/Utils.jsm
toolkit/devtools/sourcemap/tests/unit/test_array_set.js
toolkit/devtools/sourcemap/tests/unit/test_base64.js
toolkit/devtools/sourcemap/tests/unit/test_quick_sort.js
toolkit/devtools/sourcemap/tests/unit/test_source_map_consumer.js
toolkit/devtools/sourcemap/tests/unit/test_util.js
--- a/toolkit/devtools/sourcemap/SourceMap.jsm
+++ b/toolkit/devtools/sourcemap/SourceMap.jsm
@@ -12,29 +12,31 @@
  * https://github.com/mozilla/source-map/
  */
 
 ///////////////////////////////////////////////////////////////////////////////
 
 
 this.EXPORTED_SYMBOLS = [ "SourceMapConsumer", "SourceMapGenerator", "SourceNode" ];
 
+Components.utils.import("resource://gre/modules/devtools/Console.jsm");
 Components.utils.import('resource://gre/modules/devtools/Require.jsm');
 /* -*- Mode: js; js-indent-level: 2; -*- */
 /*
  * Copyright 2011 Mozilla Foundation and contributors
  * Licensed under the New BSD license. See LICENSE or:
  * http://opensource.org/licenses/BSD-3-Clause
  */
-define('source-map/source-map-consumer', ['require', 'exports', 'module' ,  'source-map/util', 'source-map/binary-search', 'source-map/array-set', 'source-map/base64-vlq'], function(require, exports, module) {
+define('source-map/source-map-consumer', ['require', 'exports', 'module' ,  'source-map/util', 'source-map/binary-search', 'source-map/array-set', 'source-map/base64-vlq', 'source-map/quick-sort'], function(require, exports, module) {
 
   var util = require('source-map/util');
   var binarySearch = require('source-map/binary-search');
   var ArraySet = require('source-map/array-set').ArraySet;
   var base64VLQ = require('source-map/base64-vlq');
+  var quickSort = require('source-map/quick-sort').quickSort;
 
   function SourceMapConsumer(aSourceMap) {
     var sourceMap = aSourceMap;
     if (typeof aSourceMap === 'string') {
       sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, ''));
     }
 
     return sourceMap.sections != null
@@ -80,40 +82,36 @@ define('source-map/source-map-consumer',
   // `_generatedMappings` is ordered by the generated positions.
   //
   // `_originalMappings` is ordered by the original positions.
 
   SourceMapConsumer.prototype.__generatedMappings = null;
   Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {
     get: function () {
       if (!this.__generatedMappings) {
-        this.__generatedMappings = [];
-        this.__originalMappings = [];
         this._parseMappings(this._mappings, this.sourceRoot);
       }
 
       return this.__generatedMappings;
     }
   });
 
   SourceMapConsumer.prototype.__originalMappings = null;
   Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', {
     get: function () {
       if (!this.__originalMappings) {
-        this.__generatedMappings = [];
-        this.__originalMappings = [];
         this._parseMappings(this._mappings, this.sourceRoot);
       }
 
       return this.__originalMappings;
     }
   });
 
-  SourceMapConsumer.prototype._nextCharIsMappingSeparator =
-    function SourceMapConsumer_nextCharIsMappingSeparator(aStr, index) {
+  SourceMapConsumer.prototype._charIsMappingSeparator =
+    function SourceMapConsumer_charIsMappingSeparator(aStr, index) {
       var c = aStr.charAt(index);
       return c === ";" || c === ",";
     };
 
   /**
    * Parse the mappings in a string in to a data structure which we can easily
    * query (the ordered arrays in the `this.__generatedMappings` and
    * `this.__originalMappings` properties).
@@ -159,29 +157,29 @@ define('source-map/source-map-consumer',
         mappings = this._originalMappings;
         break;
       default:
         throw new Error("Unknown order of iteration.");
       }
 
       var sourceRoot = this.sourceRoot;
       mappings.map(function (mapping) {
-        var source = mapping.source;
+        var source = mapping.source === null ? null : this._sources.at(mapping.source);
         if (source != null && sourceRoot != null) {
           source = util.join(sourceRoot, source);
         }
         return {
           source: source,
           generatedLine: mapping.generatedLine,
           generatedColumn: mapping.generatedColumn,
           originalLine: mapping.originalLine,
           originalColumn: mapping.originalColumn,
-          name: mapping.name
+          name: mapping.name === null ? null : this._names.at(mapping.name)
         };
-      }).forEach(aCallback, context);
+      }, this).forEach(aCallback, context);
     };
 
   /**
    * Returns all generated line and column information for the original source,
    * line, and column provided. If no column is provided, returns all mappings
    * corresponding to a either the line we are searching for or the next
    * closest line that has any mappings. Otherwise, returns all mappings
    * corresponding to the given line and either the column we are searching for
@@ -210,16 +208,20 @@ define('source-map/source-map-consumer',
         source: util.getArg(aArgs, 'source'),
         originalLine: line,
         originalColumn: util.getArg(aArgs, 'column', 0)
       };
 
       if (this.sourceRoot != null) {
         needle.source = util.relative(this.sourceRoot, needle.source);
       }
+      if (!this._sources.has(needle.source)) {
+        return [];
+      }
+      needle.source = this._sources.indexOf(needle.source);
 
       var mappings = [];
 
       var index = this._findMapping(needle,
                                     this._originalMappings,
                                     "originalLine",
                                     "originalColumn",
                                     util.compareByOriginalPositions,
@@ -356,19 +358,27 @@ define('source-map/source-map-consumer',
       smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
       smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
       smc.sourceRoot = aSourceMap._sourceRoot;
       smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
                                                               smc.sourceRoot);
       smc.file = aSourceMap._file;
 
       smc.__generatedMappings = aSourceMap._mappings.toArray().slice();
-      smc.__originalMappings = aSourceMap._mappings.toArray().slice()
-        .sort(util.compareByOriginalPositions);
+      smc.__originalMappings = aSourceMap._mappings.toArray().slice().sort();
+
+      smc.__generatedMappings.forEach(function (m) {
+        if (m.source !== null) {
+          m.source = smc._sources.indexOf(m.source);
 
+          if (m.name !== null) {
+            m.name = smc._names.indexOf(m.name);
+          }
+        }
+      });
       return smc;
     };
 
   /**
    * The version of the source mapping spec that we are consuming.
    */
   BasicSourceMapConsumer.prototype._version = 3;
 
@@ -379,114 +389,134 @@ define('source-map/source-map-consumer',
     get: function () {
       return this._sources.toArray().map(function (s) {
         return this.sourceRoot != null ? util.join(this.sourceRoot, s) : s;
       }, this);
     }
   });
 
   /**
+   * Provide the JIT with a nice shape / hidden class.
+   */
+  function Mapping() {
+    this.generatedLine = 0;
+    this.generatedColumn = 0;
+    this.source = null;
+    this.originalLine = null;
+    this.originalColumn = null;
+    this.name = null;
+  }
+
+  /**
    * Parse the mappings in a string in to a data structure which we can easily
    * query (the ordered arrays in the `this.__generatedMappings` and
    * `this.__originalMappings` properties).
    */
   BasicSourceMapConsumer.prototype._parseMappings =
     function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
       var generatedLine = 1;
       var previousGeneratedColumn = 0;
       var previousOriginalLine = 0;
       var previousOriginalColumn = 0;
       var previousSource = 0;
       var previousName = 0;
       var length = aStr.length;
       var index = 0;
-      var cachedValues = {};
+      var cachedSegments = {};
       var temp = {};
-      var mapping, str, values, end, value;
+      var originalMappings = [];
+      var generatedMappings = [];
+      var mapping, str, segment, end, value;
 
       while (index < length) {
         if (aStr.charAt(index) === ';') {
           generatedLine++;
-          ++index;
+          index++;
           previousGeneratedColumn = 0;
         }
         else if (aStr.charAt(index) === ',') {
-          ++index;
+          index++;
         }
         else {
-          mapping = {};
+          mapping = new Mapping();
           mapping.generatedLine = generatedLine;
 
           // Because each offset is encoded relative to the previous one,
           // many segments often have the same encoding. We can exploit this
           // fact by caching the parsed variable length fields of each segment,
           // allowing us to avoid a second parse if we encounter the same
           // segment again.
-          for (end = index; end < length; ++end) {
-            if (this._nextCharIsMappingSeparator(aStr, end)) {
+          for (end = index; end < length; end++) {
+            if (this._charIsMappingSeparator(aStr, end)) {
               break;
             }
           }
           str = aStr.slice(index, end);
 
-          values = cachedValues[str];
-          if (values) {
+          segment = cachedSegments[str];
+          if (segment) {
             index += str.length;
           } else {
-            values = [];
+            segment = [];
             while (index < end) {
               base64VLQ.decode(aStr, index, temp);
               value = temp.value;
               index = temp.rest;
-              values.push(value);
+              segment.push(value);
             }
-            cachedValues[str] = values;
-          }
 
-          // Generated column.
-          mapping.generatedColumn = previousGeneratedColumn + values[0];
-          previousGeneratedColumn = mapping.generatedColumn;
-
-          if (values.length > 1) {
-            // Original source.
-            mapping.source = this._sources.at(previousSource + values[1]);
-            previousSource += values[1];
-            if (values.length === 2) {
+            if (segment.length === 2) {
               throw new Error('Found a source, but no line and column');
             }
 
-            // Original line.
-            mapping.originalLine = previousOriginalLine + values[2];
-            previousOriginalLine = mapping.originalLine;
-            // Lines are stored 0-based
-            mapping.originalLine += 1;
-            if (values.length === 3) {
+            if (segment.length === 3) {
               throw new Error('Found a source and line, but no column');
             }
 
+            cachedSegments[str] = segment;
+          }
+
+          // Generated column.
+          mapping.generatedColumn = previousGeneratedColumn + segment[0];
+          previousGeneratedColumn = mapping.generatedColumn;
+
+          if (segment.length > 1) {
+            // Original source.
+            mapping.source = previousSource + segment[1];
+            previousSource += segment[1];
+
+            // Original line.
+            mapping.originalLine = previousOriginalLine + segment[2];
+            previousOriginalLine = mapping.originalLine;
+            // Lines are stored 0-based
+            mapping.originalLine += 1;
+
             // Original column.
-            mapping.originalColumn = previousOriginalColumn + values[3];
+            mapping.originalColumn = previousOriginalColumn + segment[3];
             previousOriginalColumn = mapping.originalColumn;
 
-            if (values.length > 4) {
+            if (segment.length > 4) {
               // Original name.
-              mapping.name = this._names.at(previousName + values[4]);
-              previousName += values[4];
+              mapping.name = previousName + segment[4];
+              previousName += segment[4];
             }
           }
 
-          this.__generatedMappings.push(mapping);
+          generatedMappings.push(mapping);
           if (typeof mapping.originalLine === 'number') {
-            this.__originalMappings.push(mapping);
+            originalMappings.push(mapping);
           }
         }
       }
 
-      this.__generatedMappings.sort(util.compareByGeneratedPositions);
-      this.__originalMappings.sort(util.compareByOriginalPositions);
+      quickSort(generatedMappings, util.compareByGeneratedPositions);
+      this.__generatedMappings = generatedMappings;
+
+      quickSort(originalMappings, util.compareByOriginalPositions);
+      this.__originalMappings = originalMappings;
     };
 
   /**
    * Find the mapping that best matches the hypothetical "needle" mapping that
    * we are searching for in the given "haystack" of mappings.
    */
   BasicSourceMapConsumer.prototype._findMapping =
     function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
@@ -571,37 +601,57 @@ define('source-map/source-map-consumer',
         util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
       );
 
       if (index >= 0) {
         var mapping = this._generatedMappings[index];
 
         if (mapping.generatedLine === needle.generatedLine) {
           var source = util.getArg(mapping, 'source', null);
-          if (source != null && this.sourceRoot != null) {
-            source = util.join(this.sourceRoot, source);
+          if (source !== null) {
+            source = this._sources.at(source);
+            if (this.sourceRoot != null) {
+              source = util.join(this.sourceRoot, source);
+            }
+          }
+          var name = util.getArg(mapping, 'name', null);
+          if (name !== null) {
+            name = this._names.at(name);
           }
           return {
             source: source,
             line: util.getArg(mapping, 'originalLine', null),
             column: util.getArg(mapping, 'originalColumn', null),
-            name: util.getArg(mapping, 'name', null)
+            name: name
           };
         }
       }
 
       return {
         source: null,
         line: null,
         column: null,
         name: null
       };
     };
 
   /**
+   * Return true if we have the source content for every source in the source
+   * map, false otherwise.
+   */
+  BasicSourceMapConsumer.prototype.hasContentsOfAllSources =
+    function BasicSourceMapConsumer_hasContentsOfAllSources() {
+      if (!this.sourcesContent) {
+        return false;
+      }
+      return this.sourcesContent.length >= this._sources.size() &&
+        !this.sourcesContent.some(function (sc) { return sc == null; });
+    };
+
+  /**
    * Returns the original source content. The only argument is the url of the
    * original source file. Returns null if no original source content is
    * availible.
    */
   BasicSourceMapConsumer.prototype.sourceContentFor =
     function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
       if (!this.sourcesContent) {
         return null;
@@ -662,26 +712,35 @@ define('source-map/source-map-consumer',
    *
    * and an object is returned with the following properties:
    *
    *   - line: The line number in the generated source, or null.
    *   - column: The column number in the generated source, or null.
    */
   BasicSourceMapConsumer.prototype.generatedPositionFor =
     function SourceMapConsumer_generatedPositionFor(aArgs) {
+      var source = util.getArg(aArgs, 'source');
+      if (this.sourceRoot != null) {
+        source = util.relative(this.sourceRoot, source);
+      }
+      if (!this._sources.has(source)) {
+        return {
+          line: null,
+          column: null,
+          lastColumn: null
+        };
+      }
+      source = this._sources.indexOf(source);
+
       var needle = {
-        source: util.getArg(aArgs, 'source'),
+        source: source,
         originalLine: util.getArg(aArgs, 'line'),
         originalColumn: util.getArg(aArgs, 'column')
       };
 
-      if (this.sourceRoot != null) {
-        needle.source = util.relative(this.sourceRoot, needle.source);
-      }
-
       var index = this._findMapping(
         needle,
         this._originalMappings,
         "originalLine",
         "originalColumn",
         util.compareByOriginalPositions,
         util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
       );
@@ -760,16 +819,19 @@ define('source-map/source-map-consumer',
 
     var version = util.getArg(sourceMap, 'version');
     var sections = util.getArg(sourceMap, 'sections');
 
     if (version != this._version) {
       throw new Error('Unsupported version: ' + version);
     }
 
+    this._sources = new ArraySet();
+    this._names = new ArraySet();
+
     var lastOffset = {
       line: -1,
       column: 0
     };
     this._sections = sections.map(function (s) {
       if (s.url) {
         // The url field will require support for asynchronicity.
         // See https://github.com/mozilla/source-map/issues/16
@@ -872,16 +934,27 @@ define('source-map/source-map-consumer',
           (section.generatedOffset.generatedLine === needle.generatedLine
            ? section.generatedOffset.generatedColumn - 1
            : 0),
         bias: aArgs.bias
       });
     };
 
   /**
+   * Return true if we have the source content for every source in the source
+   * map, false otherwise.
+   */
+  IndexedSourceMapConsumer.prototype.hasContentsOfAllSources =
+    function IndexedSourceMapConsumer_hasContentsOfAllSources() {
+      return this._sections.every(function (s) {
+        return s.consumer.hasContentsOfAllSources();
+      });
+    };
+
+  /**
    * Returns the original source content. The only argument is the url of the
    * original source file. Returns null if no original source content is
    * available.
    */
   IndexedSourceMapConsumer.prototype.sourceContentFor =
     function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
       for (var i = 0; i < this._sections.length; i++) {
         var section = this._sections[i];
@@ -953,50 +1026,54 @@ define('source-map/source-map-consumer',
       this.__generatedMappings = [];
       this.__originalMappings = [];
       for (var i = 0; i < this._sections.length; i++) {
         var section = this._sections[i];
         var sectionMappings = section.consumer._generatedMappings;
         for (var j = 0; j < sectionMappings.length; j++) {
           var mapping = sectionMappings[i];
 
-          var source = mapping.source;
-          var sourceRoot = section.consumer.sourceRoot;
+          var source = section.consumer._sources.at(mapping.source);
+          if (section.consumer.sourceRoot !== null) {
+            source = util.join(section.consumer.sourceRoot, source);
+          }
+          this._sources.add(source);
+          source = this._sources.indexOf(source);
 
-          if (source != null && sourceRoot != null) {
-            source = util.join(sourceRoot, source);
-          }
+          var name = section.consumer._names.at(mapping.name);
+          this._names.add(name);
+          name = this._names.indexOf(name);
 
           // The mappings coming from the consumer for the section have
           // generated positions relative to the start of the section, so we
           // need to offset them to be relative to the start of the concatenated
           // generated file.
           var adjustedMapping = {
             source: source,
             generatedLine: mapping.generatedLine +
               (section.generatedOffset.generatedLine - 1),
             generatedColumn: mapping.column +
               (section.generatedOffset.generatedLine === mapping.generatedLine)
               ? section.generatedOffset.generatedColumn - 1
               : 0,
             originalLine: mapping.originalLine,
             originalColumn: mapping.originalColumn,
-            name: mapping.name
+            name: name
           };
 
           this.__generatedMappings.push(adjustedMapping);
           if (typeof adjustedMapping.originalLine === 'number') {
             this.__originalMappings.push(adjustedMapping);
           }
         };
       };
 
-    this.__generatedMappings.sort(util.compareByGeneratedPositions);
-    this.__originalMappings.sort(util.compareByOriginalPositions);
-  };
+      quickSort(this.__generatedMappings, util.compareByGeneratedPositions);
+      quickSort(this.__originalMappings, util.compareByOriginalPositions);
+    };
 
   exports.IndexedSourceMapConsumer = IndexedSourceMapConsumer;
 
 });
 /* -*- Mode: js; js-indent-level: 2; -*- */
 /*
  * Copyright 2011 Mozilla Foundation and contributors
  * Licensed under the New BSD license. See LICENSE or:
@@ -1203,17 +1280,17 @@ define('source-map/util', ['require', 'e
       if (index < 0) {
         return aPath;
       }
 
       // If the only part of the root that is left is the scheme (i.e. http://,
       // file:///, etc.), one or more slashes (/), or simply nothing at all, we
       // have exhausted all components, so the path is not relative to the root.
       aRoot = aRoot.slice(0, index);
-      if (aRoot.match(/^([^\/]+:\/)\/*$/)) {
+      if (aRoot.match(/^([^\/]+:\/)?\/*$/)) {
         return aPath;
       }
 
       ++level;
     }
 
     // Make sure we add a "../" for each component we removed from the root.
     return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1);
@@ -1234,100 +1311,90 @@ define('source-map/util', ['require', 'e
   }
   exports.toSetString = toSetString;
 
   function fromSetString(aStr) {
     return aStr.substr(1);
   }
   exports.fromSetString = fromSetString;
 
-  function strcmp(aStr1, aStr2) {
-    var s1 = aStr1 || "";
-    var s2 = aStr2 || "";
-    return (s1 > s2) - (s1 < s2);
-  }
-
   /**
    * Comparator between two mappings where the original positions are compared.
    *
    * Optionally pass in `true` as `onlyCompareGenerated` to consider two
    * mappings with the same original source/line/column, but different generated
    * line and column the same. Useful when searching for a mapping with a
    * stubbed out mapping.
    */
   function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
-    var cmp;
-
-    cmp = strcmp(mappingA.source, mappingB.source);
-    if (cmp) {
+    var cmp = mappingA.source - mappingB.source;
+    if (cmp !== 0) {
       return cmp;
     }
 
     cmp = mappingA.originalLine - mappingB.originalLine;
-    if (cmp) {
+    if (cmp !== 0) {
       return cmp;
     }
 
     cmp = mappingA.originalColumn - mappingB.originalColumn;
-    if (cmp || onlyCompareOriginal) {
+    if (cmp !== 0 || onlyCompareOriginal) {
       return cmp;
     }
 
     cmp = mappingA.generatedColumn - mappingB.generatedColumn;
-    if (cmp) {
+    if (cmp !== 0) {
       return cmp;
     }
 
     cmp = mappingA.generatedLine - mappingB.generatedLine;
-    if (cmp) {
+    if (cmp !== 0) {
       return cmp;
     }
 
-    return strcmp(mappingA.name, mappingB.name);
+    return mappingA.name - mappingB.name;
   };
   exports.compareByOriginalPositions = compareByOriginalPositions;
 
   /**
    * Comparator between two mappings where the generated positions are
    * compared.
    *
    * Optionally pass in `true` as `onlyCompareGenerated` to consider two
    * mappings with the same generated line and column, but different
    * source/name/original line and column the same. Useful when searching for a
    * mapping with a stubbed out mapping.
    */
   function compareByGeneratedPositions(mappingA, mappingB, onlyCompareGenerated) {
-    var cmp;
-
-    cmp = mappingA.generatedLine - mappingB.generatedLine;
-    if (cmp) {
+    var cmp = mappingA.generatedLine - mappingB.generatedLine;
+    if (cmp !== 0) {
       return cmp;
     }
 
     cmp = mappingA.generatedColumn - mappingB.generatedColumn;
-    if (cmp || onlyCompareGenerated) {
+    if (cmp !== 0 || onlyCompareGenerated) {
       return cmp;
     }
 
-    cmp = strcmp(mappingA.source, mappingB.source);
-    if (cmp) {
+    cmp = mappingA.source - mappingB.source;
+    if (cmp !== 0) {
       return cmp;
     }
 
     cmp = mappingA.originalLine - mappingB.originalLine;
-    if (cmp) {
+    if (cmp !== 0) {
       return cmp;
     }
 
     cmp = mappingA.originalColumn - mappingB.originalColumn;
-    if (cmp) {
+    if (cmp !== 0) {
       return cmp;
     }
 
-    return strcmp(mappingA.name, mappingB.name);
+    return mappingA.name - mappingB.name;
   };
   exports.compareByGeneratedPositions = compareByGeneratedPositions;
 
 });
 /* -*- Mode: js; js-indent-level: 2; -*- */
 /*
  * Copyright 2011 Mozilla Foundation and contributors
  * Licensed under the New BSD license. See LICENSE or:
@@ -1469,16 +1536,26 @@ define('source-map/array-set', ['require
     var set = new ArraySet();
     for (var i = 0, len = aArray.length; i < len; i++) {
       set.add(aArray[i], aAllowDuplicates);
     }
     return set;
   };
 
   /**
+   * Return how many unique items are in this ArraySet. If duplicates have been
+   * added, than those do not count towards the size.
+   *
+   * @returns Number
+   */
+  ArraySet.prototype.size = function ArraySet_size() {
+    return Object.getOwnPropertyNames(this._set).length;
+  };
+
+  /**
    * Add the given string to this set.
    *
    * @param String aStr
    */
   ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
     var isDuplicate = this.has(aStr);
     var idx = this._array.length;
     if (!isDuplicate || aAllowDuplicates) {
@@ -1656,17 +1733,22 @@ define('source-map/base64-vlq', ['requir
     var result = 0;
     var shift = 0;
     var continuation, digit;
 
     do {
       if (aIndex >= strLen) {
         throw new Error("Expected more digits in base 64 VLQ value.");
       }
-      digit = base64.decode(aStr.charAt(aIndex++));
+
+      digit = base64.decode(aStr.charCodeAt(aIndex++));
+      if (digit === -1) {
+        throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1));
+      }
+
       continuation = !!(digit & VLQ_CONTINUATION_BIT);
       digit &= VLQ_BASE_MASK;
       result = result + (digit << shift);
       shift += VLQ_BASE_SHIFT;
     } while (continuation);
 
     aOutParam.value = fromVLQSigned(result);
     aOutParam.rest = aIndex;
@@ -1676,44 +1758,192 @@ define('source-map/base64-vlq', ['requir
 /* -*- Mode: js; js-indent-level: 2; -*- */
 /*
  * Copyright 2011 Mozilla Foundation and contributors
  * Licensed under the New BSD license. See LICENSE or:
  * http://opensource.org/licenses/BSD-3-Clause
  */
 define('source-map/base64', ['require', 'exports', 'module' , ], function(require, exports, module) {
 
-  var charToIntMap = {};
-  var intToCharMap = {};
-
-  'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
-    .split('')
-    .forEach(function (ch, index) {
-      charToIntMap[ch] = index;
-      intToCharMap[index] = ch;
-    });
+  var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
 
   /**
    * Encode an integer in the range of 0 to 63 to a single base 64 digit.
    */
-  exports.encode = function base64_encode(aNumber) {
-    if (aNumber in intToCharMap) {
-      return intToCharMap[aNumber];
+  exports.encode = function (number) {
+    if (0 <= number && number < intToCharMap.length) {
+      return intToCharMap[number];
     }
     throw new TypeError("Must be between 0 and 63: " + aNumber);
   };
 
   /**
-   * Decode a single base 64 digit to an integer.
+   * Decode a single base 64 character code digit to an integer. Returns -1 on
+   * failure.
+   */
+  exports.decode = function (charCode) {
+    var bigA = 65;     // 'A'
+    var bigZ = 90;     // 'Z'
+
+    var littleA = 97;  // 'a'
+    var littleZ = 122; // 'z'
+
+    var zero = 48;     // '0'
+    var nine = 57;     // '9'
+
+    var plus = 43;     // '+'
+    var slash = 47;    // '/'
+
+    var littleOffset = 26;
+    var numberOffset = 52;
+
+    // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ
+    if (bigA <= charCode && charCode <= bigZ) {
+      return (charCode - bigA);
+    }
+
+    // 26 - 51: abcdefghijklmnopqrstuvwxyz
+    if (littleA <= charCode && charCode <= littleZ) {
+      return (charCode - littleA + littleOffset);
+    }
+
+    // 52 - 61: 0123456789
+    if (zero <= charCode && charCode <= nine) {
+      return (charCode - zero + numberOffset);
+    }
+
+    // 62: +
+    if (charCode == plus) {
+      return 62;
+    }
+
+    // 63: /
+    if (charCode == slash) {
+      return 63;
+    }
+
+    // Invalid base64 digit.
+    return -1;
+  };
+
+});
+/* -*- Mode: js; js-indent-level: 2; -*- */
+/*
+ * Copyright 2011 Mozilla Foundation and contributors
+ * Licensed under the New BSD license. See LICENSE or:
+ * http://opensource.org/licenses/BSD-3-Clause
+ */
+define('source-map/quick-sort', ['require', 'exports', 'module' , ], function(require, exports, module) {
+
+  // It turns out that some (most?) JavaScript engines don't self-host
+  // `Array.prototype.sort`. This makes sense because C++ will likely remain
+  // faster than JS when doing raw CPU-intensive sorting. However, when using a
+  // custom comparator function, calling back and forth between the VM's C++ and
+  // JIT'd JS is rather slow *and* loses JIT type information, resulting in
+  // worse generated code for the comparator function than would be optimal. In
+  // fact, when sorting with a comparator, these costs outweigh the benefits of
+  // sorting in C++. By using our own JS-implemented Quick Sort (below), we get
+  // a ~3500ms mean speed-up in `bench/bench.html`.
+
+  /**
+   * Swap the elements indexed by `x` and `y` in the array `ary`.
+   *
+   * @param {Array} ary
+   *        The array.
+   * @param {Number} x
+   *        The index of the first item.
+   * @param {Number} y
+   *        The index of the second item.
    */
-  exports.decode = function base64_decode(aChar) {
-    if (aChar in charToIntMap) {
-      return charToIntMap[aChar];
+  function swap(ary, x, y) {
+    var temp = ary[x];
+    ary[x] = ary[y];
+    ary[y] = temp;
+  }
+
+  /**
+   * Returns a random integer within the range `low .. high` inclusive.
+   *
+   * @param {Number} low
+   *        The lower bound on the range.
+   * @param {Number} high
+   *        The upper bound on the range.
+   */
+  function randomIntInRange(low, high) {
+    return Math.round(low + (Math.random() * (high - low)));
+  }
+
+  /**
+   * The Quick Sort algorithm.
+   *
+   * @param {Array} ary
+   *        An array to sort.
+   * @param {function} comparator
+   *        Function to use to compare two items.
+   * @param {Number} p
+   *        Start index of the array
+   * @param {Number} r
+   *        End index of the array
+   */
+  function doQuickSort(ary, comparator, p, r) {
+    // If our lower bound is less than our upper bound, we (1) partition the
+    // array into two pieces and (2) recurse on each half. If it is not, this is
+    // the empty array and our base case.
+
+    if (p < r) {
+      // (1) Partitioning.
+      //
+      // The partitioning chooses a pivot between `p` and `r` and moves all
+      // elements that are less than or equal to the pivot to the before it, and
+      // all the elements that are greater than it after it. The effect is that
+      // once partition is done, the pivot is in the exact place it will be when
+      // the array is put in sorted order, and it will not need to be moved
+      // again. This runs in O(n) time.
+
+      // Always choose a random pivot so that an input array which is reverse
+      // sorted does not cause O(n^2) running time.
+      var pivotIndex = randomIntInRange(p, r);
+      var i = p - 1;
+
+      swap(ary, pivotIndex, r);
+      var pivot = ary[r];
+
+      // Immediately after `j` is incremented in this loop, the following hold
+      // true:
+      //
+      //   * Every element in `ary[p .. i]` is less than or equal to the pivot.
+      //
+      //   * Every element in `ary[i+1 .. j-1]` is greater than the pivot.
+      for (var j = p; j < r; j++) {
+        if (comparator(ary[j], pivot) <= 0) {
+          i += 1;
+          swap(ary, i, j);
+        }
+      }
+
+      swap(ary, i + 1, j);
+      var q = i + 1;
+
+      // (2) Recurse on each half.
+
+      doQuickSort(ary, comparator, p, q - 1);
+      doQuickSort(ary, comparator, q + 1, r);
     }
-    throw new TypeError("Not a valid base 64 digit: " + aChar);
+  }
+
+  /**
+   * Sort the given array in-place with the given comparator function.
+   *
+   * @param {Array} ary
+   *        An array to sort.
+   * @param {function} comparator
+   *        Function to use to compare two items.
+   */
+  exports.quickSort = function (ary, comparator) {
+    doQuickSort(ary, comparator, 0, ary.length - 1);
   };
 
 });
 /* -*- Mode: js; js-indent-level: 2; -*- */
 /*
  * Copyright 2011 Mozilla Foundation and contributors
  * Licensed under the New BSD license. See LICENSE or:
  * http://opensource.org/licenses/BSD-3-Clause
--- a/toolkit/devtools/sourcemap/tests/unit/Utils.jsm
+++ b/toolkit/devtools/sourcemap/tests/unit/Utils.jsm
@@ -577,17 +577,17 @@ define('lib/source-map/util', ['require'
       if (index < 0) {
         return aPath;
       }
 
       // If the only part of the root that is left is the scheme (i.e. http://,
       // file:///, etc.), one or more slashes (/), or simply nothing at all, we
       // have exhausted all components, so the path is not relative to the root.
       aRoot = aRoot.slice(0, index);
-      if (aRoot.match(/^([^\/]+:\/)\/*$/)) {
+      if (aRoot.match(/^([^\/]+:\/)?\/*$/)) {
         return aPath;
       }
 
       ++level;
     }
 
     // Make sure we add a "../" for each component we removed from the root.
     return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1);
@@ -608,100 +608,90 @@ define('lib/source-map/util', ['require'
   }
   exports.toSetString = toSetString;
 
   function fromSetString(aStr) {
     return aStr.substr(1);
   }
   exports.fromSetString = fromSetString;
 
-  function strcmp(aStr1, aStr2) {
-    var s1 = aStr1 || "";
-    var s2 = aStr2 || "";
-    return (s1 > s2) - (s1 < s2);
-  }
-
   /**
    * Comparator between two mappings where the original positions are compared.
    *
    * Optionally pass in `true` as `onlyCompareGenerated` to consider two
    * mappings with the same original source/line/column, but different generated
    * line and column the same. Useful when searching for a mapping with a
    * stubbed out mapping.
    */
   function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
-    var cmp;
-
-    cmp = strcmp(mappingA.source, mappingB.source);
-    if (cmp) {
+    var cmp = mappingA.source - mappingB.source;
+    if (cmp !== 0) {
       return cmp;
     }
 
     cmp = mappingA.originalLine - mappingB.originalLine;
-    if (cmp) {
+    if (cmp !== 0) {
       return cmp;
     }
 
     cmp = mappingA.originalColumn - mappingB.originalColumn;
-    if (cmp || onlyCompareOriginal) {
+    if (cmp !== 0 || onlyCompareOriginal) {
       return cmp;
     }
 
     cmp = mappingA.generatedColumn - mappingB.generatedColumn;
-    if (cmp) {
+    if (cmp !== 0) {
       return cmp;
     }
 
     cmp = mappingA.generatedLine - mappingB.generatedLine;
-    if (cmp) {
+    if (cmp !== 0) {
       return cmp;
     }
 
-    return strcmp(mappingA.name, mappingB.name);
+    return mappingA.name - mappingB.name;
   };
   exports.compareByOriginalPositions = compareByOriginalPositions;
 
   /**
    * Comparator between two mappings where the generated positions are
    * compared.
    *
    * Optionally pass in `true` as `onlyCompareGenerated` to consider two
    * mappings with the same generated line and column, but different
    * source/name/original line and column the same. Useful when searching for a
    * mapping with a stubbed out mapping.
    */
   function compareByGeneratedPositions(mappingA, mappingB, onlyCompareGenerated) {
-    var cmp;
-
-    cmp = mappingA.generatedLine - mappingB.generatedLine;
-    if (cmp) {
+    var cmp = mappingA.generatedLine - mappingB.generatedLine;
+    if (cmp !== 0) {
       return cmp;
     }
 
     cmp = mappingA.generatedColumn - mappingB.generatedColumn;
-    if (cmp || onlyCompareGenerated) {
+    if (cmp !== 0 || onlyCompareGenerated) {
       return cmp;
     }
 
-    cmp = strcmp(mappingA.source, mappingB.source);
-    if (cmp) {
+    cmp = mappingA.source - mappingB.source;
+    if (cmp !== 0) {
       return cmp;
     }
 
     cmp = mappingA.originalLine - mappingB.originalLine;
-    if (cmp) {
+    if (cmp !== 0) {
       return cmp;
     }
 
     cmp = mappingA.originalColumn - mappingB.originalColumn;
-    if (cmp) {
+    if (cmp !== 0) {
       return cmp;
     }
 
-    return strcmp(mappingA.name, mappingB.name);
+    return mappingA.name - mappingB.name;
   };
   exports.compareByGeneratedPositions = compareByGeneratedPositions;
 
 });
 /* -*- Mode: js; js-indent-level: 2; -*- */
 /*
  * Copyright 2011 Mozilla Foundation and contributors
  * Licensed under the New BSD license. See LICENSE or:
--- a/toolkit/devtools/sourcemap/tests/unit/test_array_set.js
+++ b/toolkit/devtools/sourcemap/tests/unit/test_array_set.js
@@ -101,12 +101,50 @@ define("test/source-map/test-array-set",
     set.add('foo', true);
     assert.ok(set.has('foo'));
     assert.strictEqual(set.at(0), 'foo');
     assert.strictEqual(set.at(1), 'foo');
     assert.strictEqual(set.indexOf('foo'), 0);
     assert.strictEqual(set.toArray().length, 2);
   };
 
+  exports['test .size()'] = function (assert, util) {
+    var set = new ArraySet();
+    set.add('foo');
+    set.add('bar');
+    set.add('baz');
+    assert.strictEqual(set.size(), 3);
+  };
+
+  exports['test .size() with disallowed duplicates'] = function (assert, util) {
+    var set = new ArraySet();
+
+    set.add('foo');
+    set.add('foo');
+
+    set.add('bar');
+    set.add('bar');
+
+    set.add('baz');
+    set.add('baz');
+
+    assert.strictEqual(set.size(), 3);
+  };
+
+  exports['test .size() with allowed duplicates'] = function (assert, util) {
+    var set = new ArraySet();
+
+    set.add('foo');
+    set.add('foo', true);
+
+    set.add('bar');
+    set.add('bar', true);
+
+    set.add('baz');
+    set.add('baz', true);
+
+    assert.strictEqual(set.size(), 3);
+  };
+
 });
 function run_test() {
   runSourceMapTests('test/source-map/test-array-set', do_throw);
 }
--- a/toolkit/devtools/sourcemap/tests/unit/test_base64.js
+++ b/toolkit/devtools/sourcemap/tests/unit/test_base64.js
@@ -21,23 +21,21 @@ define("test/source-map/test-base64", ["
       base64.encode(-1);
     });
     assert.throws(function () {
       base64.encode(64);
     });
   };
 
   exports['test out of range decoding'] = function (assert, util) {
-    assert.throws(function () {
-      base64.decode('=');
-    });
+    assert.equal(base64.decode('='.charCodeAt(0)), -1);
   };
 
   exports['test normal encoding and decoding'] = function (assert, util) {
     for (var i = 0; i < 64; i++) {
-      assert.equal(base64.decode(base64.encode(i)), i);
+      assert.equal(base64.decode(base64.encode(i).charCodeAt(0)), i);
     }
   };
 
 });
 function run_test() {
   runSourceMapTests('test/source-map/test-base64', do_throw);
 }
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/sourcemap/tests/unit/test_quick_sort.js
@@ -0,0 +1,59 @@
+/*
+ * WARNING!
+ *
+ * Do not edit this file directly, it is built from the sources at
+ * https://github.com/mozilla/source-map/
+ */
+
+Components.utils.import('resource://test/Utils.jsm');
+/* -*- Mode: js; js-indent-level: 2; -*- */
+/*
+ * Copyright 2011 Mozilla Foundation and contributors
+ * Licensed under the New BSD license. See LICENSE or:
+ * http://opensource.org/licenses/BSD-3-Clause
+ */
+define("test/source-map/test-quick-sort", ["require", "exports", "module"], function (require, exports, module) {
+
+  var quickSort = require('source-map/quick-sort').quickSort;
+
+  function numberCompare(a, b) {
+    return a - b;
+  }
+
+  exports['test sorting sorted array'] = function (assert, util) {
+    var ary = [0,1,2,3,4,5,6,7,8,9];
+
+    var quickSorted = ary.slice();
+    quickSort(quickSorted, numberCompare);
+
+    assert.equal(JSON.stringify(ary),
+                 JSON.stringify(quickSorted));
+  };
+
+  exports['test sorting reverse-sorted array'] = function (assert, util) {
+    var ary = [9,8,7,6,5,4,3,2,1,0];
+
+    var quickSorted = ary.slice();
+    quickSort(quickSorted, numberCompare);
+
+    assert.equal(JSON.stringify(ary.sort(numberCompare)),
+                 JSON.stringify(quickSorted));
+  };
+
+  exports['test sorting unsorted array'] = function (assert, util) {
+    var ary = [];
+    for (var i = 0; i < 10; i++) {
+      ary.push(Math.random());
+    }
+
+    var quickSorted = ary.slice();
+    quickSort(quickSorted, numberCompare);
+
+    assert.equal(JSON.stringify(ary.sort(numberCompare)),
+                 JSON.stringify(quickSorted));
+  };
+
+});
+function run_test() {
+  runSourceMapTests('test/source-map/test-quick-sort', do_throw);
+}
--- a/toolkit/devtools/sourcemap/tests/unit/test_source_map_consumer.js
+++ b/toolkit/devtools/sourcemap/tests/unit/test_source_map_consumer.js
@@ -456,16 +456,65 @@ define("test/source-map/test-source-map-
     assert.throws(function () {
       map.sourceContentFor("/the/root/three.js");
     }, Error);
     assert.throws(function () {
       map.sourceContentFor("three.js");
     }, Error);
   };
 
+  exports['test hasContentsOfAllSources, single source with contents'] = function (assert, util) {
+    // Has one source: foo.js (with contents).
+    var mapWithContents = new SourceMapGenerator();
+    mapWithContents.addMapping({ source: 'foo.js',
+                                 original: { line: 1, column: 10 },
+                                 generated: { line: 1, column: 10 } });
+    mapWithContents.setSourceContent('foo.js', 'content of foo.js');
+    var consumer = new SourceMapConsumer(mapWithContents.toJSON());
+    assert.ok(consumer.hasContentsOfAllSources());
+  };
+
+  exports['test hasContentsOfAllSources, single source without contents'] = function (assert, util) {
+    // Has one source: foo.js (without contents).
+    var mapWithoutContents = new SourceMapGenerator();
+    mapWithoutContents.addMapping({ source: 'foo.js',
+                                    original: { line: 1, column: 10 },
+                                    generated: { line: 1, column: 10 } });
+    var consumer = new SourceMapConsumer(mapWithoutContents.toJSON());
+    assert.ok(!consumer.hasContentsOfAllSources());
+  };
+
+  exports['test hasContentsOfAllSources, two sources with contents'] = function (assert, util) {
+    // Has two sources: foo.js (with contents) and bar.js (with contents).
+    var mapWithBothContents = new SourceMapGenerator();
+    mapWithBothContents.addMapping({ source: 'foo.js',
+                                     original: { line: 1, column: 10 },
+                                     generated: { line: 1, column: 10 } });
+    mapWithBothContents.addMapping({ source: 'bar.js',
+                                     original: { line: 1, column: 10 },
+                                     generated: { line: 1, column: 10 } });
+    mapWithBothContents.setSourceContent('foo.js', 'content of foo.js');
+    mapWithBothContents.setSourceContent('bar.js', 'content of bar.js');
+    var consumer = new SourceMapConsumer(mapWithBothContents.toJSON());
+    assert.ok(consumer.hasContentsOfAllSources());
+  };
+
+  exports['test hasContentsOfAllSources, two sources one with and one without contents'] = function (assert, util) {
+    // Has two sources: foo.js (with contents) and bar.js (without contents).
+    var mapWithoutSomeContents = new SourceMapGenerator();
+    mapWithoutSomeContents.addMapping({ source: 'foo.js',
+                                        original: { line: 1, column: 10 },
+                                        generated: { line: 1, column: 10 } });
+    mapWithoutSomeContents.addMapping({ source: 'bar.js',
+                                        original: { line: 1, column: 10 },
+                                        generated: { line: 1, column: 10 } });
+    mapWithoutSomeContents.setSourceContent('foo.js', 'content of foo.js');
+    var consumer = new SourceMapConsumer(mapWithoutSomeContents.toJSON());
+    assert.ok(!consumer.hasContentsOfAllSources());
+};
 
   exports['test sourceRoot + generatedPositionFor'] = function (assert, util) {
     var map = new SourceMapGenerator({
       sourceRoot: 'foo/bar',
       file: 'baz.js'
     });
     map.addMapping({
       original: { line: 1, column: 1 },
@@ -495,16 +544,39 @@ define("test/source-map/test-source-map-
       column: 1,
       source: 'foo/bar/bang.coffee'
     });
 
     assert.equal(pos.line, 2);
     assert.equal(pos.column, 2);
   };
 
+  exports['test sourceRoot + generatedPositionFor for path above the root'] = function (assert, util) {
+    var map = new SourceMapGenerator({
+      sourceRoot: 'foo/bar',
+      file: 'baz.js'
+    });
+    map.addMapping({
+      original: { line: 1, column: 1 },
+      generated: { line: 2, column: 2 },
+      source: '../bang.coffee'
+    });
+    map = new SourceMapConsumer(map.toString());
+
+    // Should handle with sourceRoot.
+    var pos = map.generatedPositionFor({
+      line: 1,
+      column: 1,
+      source: 'foo/bang.coffee'
+    });
+
+    assert.equal(pos.line, 2);
+    assert.equal(pos.column, 2);
+  };
+
   exports['test allGeneratedPositionsFor for line'] = function (assert, util) {
     var map = new SourceMapGenerator({
       file: 'generated.js'
     });
     map.addMapping({
       original: { line: 1, column: 1 },
       generated: { line: 2, column: 2 },
       source: 'foo.coffee'
@@ -984,12 +1056,13 @@ define("test/source-map/test-source-map-
     pos = smc.generatedPositionFor({
       line: 2,
       column: 2,
       source: 'http://example.com/baz.js'
     });
     assert.equal(pos.line, 4);
     assert.equal(pos.column, 4);
   };
+
 });
 function run_test() {
   runSourceMapTests('test/source-map/test-source-map-consumer', do_throw);
 }
--- a/toolkit/devtools/sourcemap/tests/unit/test_util.js
+++ b/toolkit/devtools/sourcemap/tests/unit/test_util.js
@@ -202,17 +202,21 @@ define("test/source-map/test-util", ["re
 
     assert.equal(libUtil.join('http://www.example.com', '//foo.org/bar'), 'http://foo.org/bar');
     assert.equal(libUtil.join('//www.example.com', '//foo.org/bar'), '//foo.org/bar');
   };
 
   // TODO Issue #128: Define and test this function properly.
   exports['test relative()'] = function (assert, util) {
     assert.equal(libUtil.relative('/the/root', '/the/root/one.js'), 'one.js');
+    assert.equal(libUtil.relative('http://the/root', 'http://the/root/one.js'), 'one.js');
     assert.equal(libUtil.relative('/the/root', '/the/rootone.js'), '../rootone.js');
+    assert.equal(libUtil.relative('http://the/root', 'http://the/rootone.js'), '../rootone.js');
+    assert.equal(libUtil.relative('/the/root', '/therootone.js'), '/therootone.js');
+    assert.equal(libUtil.relative('http://the/root', '/therootone.js'), '/therootone.js');
 
     assert.equal(libUtil.relative('', '/the/root/one.js'), '/the/root/one.js');
     assert.equal(libUtil.relative('.', '/the/root/one.js'), '/the/root/one.js');
     assert.equal(libUtil.relative('', 'the/root/one.js'), 'the/root/one.js');
     assert.equal(libUtil.relative('.', 'the/root/one.js'), 'the/root/one.js');
 
     assert.equal(libUtil.relative('/', '/the/root/one.js'), 'the/root/one.js');
     assert.equal(libUtil.relative('/', 'the/root/one.js'), 'the/root/one.js');