--- a/testing/xpcshell/xpcshell.ini
+++ b/testing/xpcshell/xpcshell.ini
@@ -18,16 +18,17 @@
[include:dom/indexedDB/test/unit/xpcshell.ini]
[include:content/xtf/test/unit/xpcshell.ini]
[include:docshell/test/unit/xpcshell.ini]
[include:docshell/test/unit_ipc/xpcshell.ini]
[include:embedding/tests/unit/xpcshell.ini]
[include:toolkit/components/commandlines/test/unit/xpcshell.ini]
[include:toolkit/components/contentprefs/tests/unit/xpcshell.ini]
[include:toolkit/devtools/debugger/tests/unit/xpcshell.ini]
+[include:toolkit/devtools/sourcemap/tests/unit/xpcshell.ini]
[include:toolkit/components/passwordmgr/test/unit/xpcshell.ini]
# Bug 676989: tests hang on Android
skip-if = os == "android"
[include:toolkit/components/places/tests/migration/xpcshell.ini]
[include:toolkit/components/places/tests/autocomplete/xpcshell.ini]
[include:toolkit/components/places/tests/inline/xpcshell.ini]
[include:toolkit/components/places/tests/expiration/xpcshell.ini]
[include:toolkit/components/places/tests/favicons/xpcshell.ini]
--- a/toolkit/devtools/Makefile.in
+++ b/toolkit/devtools/Makefile.in
@@ -6,11 +6,12 @@ DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(topsrcdir)/config/config.mk
PARALLEL_DIRS += \
debugger \
+ sourcemap \
$(NULL)
include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/sourcemap/Makefile.in
@@ -0,0 +1,19 @@
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+DEPTH = ../../..
+topsrcdir = @top_srcdir@
+srcdir = @srcdir@
+VPATH = @srcdir@
+
+include $(DEPTH)/config/autoconf.mk
+
+# No tests yet
+TEST_DIRS += tests
+
+include $(topsrcdir)/config/rules.mk
+
+libs::
+ $(NSINSTALL) $(srcdir)/*.jsm $(FINAL_TARGET)/modules/devtools
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/sourcemap/SourceMap.jsm
@@ -0,0 +1,1045 @@
+/* -*- 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
+ */
+
+/*
+ * WARNING!
+ *
+ * Do not edit this file directly, it is built from the sources at
+ * https://github.com/mozilla/source-map/
+ */
+
+///////////////////////////////////////////////////////////////////////////////
+
+
+var EXPORTED_SYMBOLS = [ "SourceMapConsumer", "SourceMapGenerator", "SourceNode" ];
+
+Components.utils.import('resource:///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) {
+
+ 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');
+
+ // TODO: bug 673487
+ //
+ // Sometime in the future, if we decide we need to be able to query where in
+ // the generated source a piece of the original code came from, we may want to
+ // add a slot `_originalMappings` which would be an object keyed by the
+ // original source and whose value would be an array of mappings ordered by
+ // original line/col rather than generated (which is what we have now in
+ // `_generatedMappings`).
+
+ /**
+ * A SourceMapConsumer instance represents a parsed source map which we can
+ * query for information about the original file positions by giving it a file
+ * position in the generated source.
+ *
+ * The only parameter is the raw source map (either as a JSON string, or
+ * already parsed to an object). According to the spec, source maps have the
+ * following attributes:
+ *
+ * - version: Which version of the source map spec this map is following.
+ * - sources: An array of URLs to the original source files.
+ * - names: An array of identifiers which can be referrenced by individual mappings.
+ * - sourceRoot: Optional. The URL root from which all sources are relative.
+ * - mappings: A string of base64 VLQs which contain the actual mappings.
+ * - file: The generated file this source map is associated with.
+ *
+ * Here is an example source map, taken from the source map spec[0]:
+ *
+ * {
+ * version : 3,
+ * file: "out.js",
+ * sourceRoot : "",
+ * sources: ["foo.js", "bar.js"],
+ * names: ["src", "maps", "are", "fun"],
+ * mappings: "AA,AB;;ABCDE;"
+ * }
+ *
+ * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
+ */
+ function SourceMapConsumer(aSourceMap) {
+ var sourceMap = aSourceMap;
+ if (typeof aSourceMap === 'string') {
+ sourceMap = JSON.parse(aSourceMap);
+ }
+
+ var version = util.getArg(sourceMap, 'version');
+ var sources = util.getArg(sourceMap, 'sources');
+ var names = util.getArg(sourceMap, 'names');
+ var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null);
+ var mappings = util.getArg(sourceMap, 'mappings');
+ var file = util.getArg(sourceMap, 'file');
+
+ if (version !== this._version) {
+ throw new Error('Unsupported version: ' + version);
+ }
+
+ this._names = ArraySet.fromArray(names);
+ this._sources = ArraySet.fromArray(sources);
+
+ // `this._generatedMappings` hold the parsed mapping coordinates from the
+ // source map's "mappings" attribute. Each object in the array is of the
+ // form
+ //
+ // {
+ // generatedLine: The line number in the generated code,
+ // generatedColumn: The column number in the generated code,
+ // source: The path to the original source file that generated this
+ // chunk of code,
+ // originalLine: The line number in the original source that
+ // corresponds to this chunk of generated code,
+ // originalColumn: The column number in the original source that
+ // corresponds to this chunk of generated code,
+ // name: The name of the original symbol which generated this chunk of
+ // code.
+ // }
+ //
+ // All properties except for `generatedLine` and `generatedColumn` can be
+ // `null`.
+ this._generatedMappings = [];
+ this._parseMappings(mappings, sourceRoot);
+ }
+
+ /**
+ * The version of the source mapping spec that we are consuming.
+ */
+ SourceMapConsumer.prototype._version = 3;
+
+ /**
+ * Parse the mappings in a string in to a data structure which we can easily
+ * query (an ordered list in this._generatedMappings).
+ */
+ SourceMapConsumer.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 mappingSeparator = /^[,;]/;
+ var str = aStr;
+ var mapping;
+ var temp;
+
+ while (str.length > 0) {
+ if (str.charAt(0) === ';') {
+ generatedLine++;
+ str = str.slice(1);
+ previousGeneratedColumn = 0;
+ }
+ else if (str.charAt(0) === ',') {
+ str = str.slice(1);
+ }
+ else {
+ mapping = {};
+ mapping.generatedLine = generatedLine;
+
+ // Generated column.
+ temp = base64VLQ.decode(str);
+ mapping.generatedColumn = previousGeneratedColumn + temp.value;
+ previousGeneratedColumn = mapping.generatedColumn;
+ str = temp.rest;
+
+ if (str.length > 0 && !mappingSeparator.test(str.charAt(0))) {
+ // Original source.
+ temp = base64VLQ.decode(str);
+ if (aSourceRoot) {
+ mapping.source = util.join(aSourceRoot, this._sources.at(previousSource + temp.value));
+ }
+ else {
+ mapping.source = this._sources.at(previousSource + temp.value);
+ }
+ previousSource += temp.value;
+ str = temp.rest;
+ if (str.length === 0 || mappingSeparator.test(str.charAt(0))) {
+ throw new Error('Found a source, but no line and column');
+ }
+
+ // Original line.
+ temp = base64VLQ.decode(str);
+ mapping.originalLine = previousOriginalLine + temp.value;
+ previousOriginalLine = mapping.originalLine;
+ // Lines are stored 0-based
+ mapping.originalLine += 1;
+ str = temp.rest;
+ if (str.length === 0 || mappingSeparator.test(str.charAt(0))) {
+ throw new Error('Found a source and line, but no column');
+ }
+
+ // Original column.
+ temp = base64VLQ.decode(str);
+ mapping.originalColumn = previousOriginalColumn + temp.value;
+ previousOriginalColumn = mapping.originalColumn;
+ str = temp.rest;
+
+ if (str.length > 0 && !mappingSeparator.test(str.charAt(0))) {
+ // Original name.
+ temp = base64VLQ.decode(str);
+ mapping.name = this._names.at(previousName + temp.value);
+ previousName += temp.value;
+ str = temp.rest;
+ }
+ }
+
+ this._generatedMappings.push(mapping);
+ }
+ }
+ };
+
+ /**
+ * Returns the original source, line, and column information for the generated
+ * source's line and column positions provided. The only argument is an object
+ * with the following properties:
+ *
+ * - line: The line number in the generated source.
+ * - column: The column number in the generated source.
+ *
+ * and an object is returned with the following properties:
+ *
+ * - source: The original source file, or null.
+ * - line: The line number in the original source, or null.
+ * - column: The column number in the original source, or null.
+ * - name: The original identifier, or null.
+ */
+ SourceMapConsumer.prototype.originalPositionFor =
+ function SourceMapConsumer_originalPositionFor(aArgs) {
+ // To return the original position, we must first find the mapping for the
+ // given generated position and then return the original position it
+ // points to. Because the mappings are sorted by generated line/column, we
+ // can use binary search to find the best mapping.
+
+ // To perform a binary search on the mappings, we must be able to compare
+ // two mappings.
+ function compare(mappingA, mappingB) {
+ var cmp = mappingA.generatedLine - mappingB.generatedLine;
+ return cmp === 0
+ ? mappingA.generatedColumn - mappingB.generatedColumn
+ : cmp;
+ }
+
+ // This is the mock of the mapping we are looking for: the needle in the
+ // haystack of mappings.
+ var needle = {
+ generatedLine: util.getArg(aArgs, 'line'),
+ generatedColumn: util.getArg(aArgs, 'column')
+ };
+
+ if (needle.generatedLine <= 0) {
+ throw new TypeError('Line must be greater than or equal to 1.');
+ }
+ if (needle.generatedColumn < 0) {
+ throw new TypeError('Column must be greater than or equal to 0.');
+ }
+
+ var mapping = binarySearch.search(needle, this._generatedMappings, compare);
+
+ if (mapping) {
+ return {
+ source: util.getArg(mapping, 'source', null),
+ line: util.getArg(mapping, 'originalLine', null),
+ column: util.getArg(mapping, 'originalColumn', null),
+ name: util.getArg(mapping, 'name', null)
+ };
+ }
+
+ return {
+ source: null,
+ line: null,
+ column: null,
+ name: null
+ };
+
+ };
+
+ exports.SourceMapConsumer = SourceMapConsumer;
+
+});
+/* -*- 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/util', ['require', 'exports', 'module' ], function(require, exports, module) {
+
+ /**
+ * This is a helper function for getting values from parameter/options
+ * objects.
+ *
+ * @param args The object we are extracting values from
+ * @param name The name of the property we are getting.
+ * @param defaultValue An optional value to return if the property is missing
+ * from the object. If this is not specified and the property is missing, an
+ * error will be thrown.
+ */
+ function getArg(aArgs, aName, aDefaultValue) {
+ if (aName in aArgs) {
+ return aArgs[aName];
+ } else if (arguments.length === 3) {
+ return aDefaultValue;
+ } else {
+ throw new Error('"' + aName + '" is a required argument.');
+ }
+ }
+ exports.getArg = getArg;
+
+ function join(aRoot, aPath) {
+ return aPath.charAt(0) === '/'
+ ? aPath
+ : aRoot.replace(/\/*$/, '') + '/' + aPath;
+ }
+ exports.join = join;
+
+});
+/* -*- 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/binary-search', ['require', 'exports', 'module' ], function(require, exports, module) {
+
+ /**
+ * Recursive implementation of binary search.
+ *
+ * @param aLow Indices here and lower do not contain the needle.
+ * @param aHigh Indices here and higher do not contain the needle.
+ * @param aNeedle The element being searched for.
+ * @param aHaystack The non-empty array being searched.
+ * @param aCompare Function which takes two elements and returns -1, 0, or 1.
+ */
+ function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare) {
+ // This function terminates when one of the following is true:
+ //
+ // 1. We find the exact element we are looking for.
+ //
+ // 2. We did not find the exact element, but we can return the next
+ // closest element that is less than that element.
+ //
+ // 3. We did not find the exact element, and there is no next-closest
+ // element which is less than the one we are searching for, so we
+ // return null.
+ var mid = Math.floor((aHigh - aLow) / 2) + aLow;
+ var cmp = aCompare(aNeedle, aHaystack[mid]);
+ if (cmp === 0) {
+ // Found the element we are looking for.
+ return aHaystack[mid];
+ }
+ else if (cmp > 0) {
+ // aHaystack[mid] is greater than our needle.
+ if (aHigh - mid > 1) {
+ // The element is in the upper half.
+ return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare);
+ }
+ // We did not find an exact match, return the next closest one
+ // (termination case 2).
+ return aHaystack[mid];
+ }
+ else {
+ // aHaystack[mid] is less than our needle.
+ if (mid - aLow > 1) {
+ // The element is in the lower half.
+ return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare);
+ }
+ // The exact needle element was not found in this haystack. Determine if
+ // we are in termination case (2) or (3) and return the appropriate thing.
+ return aLow < 0
+ ? null
+ : aHaystack[aLow];
+ }
+ }
+
+ /**
+ * This is an implementation of binary search which will always try and return
+ * the next lowest value checked if there is no exact hit. This is because
+ * mappings between original and generated line/col pairs are single points,
+ * and there is an implicit region between each of them, so a miss just means
+ * that you aren't on the very start of a region.
+ *
+ * @param aNeedle The element you are looking for.
+ * @param aHaystack The array that is being searched.
+ * @param aCompare A function which takes the needle and an element in the
+ * array and returns -1, 0, or 1 depending on whether the needle is less
+ * than, equal to, or greater than the element, respectively.
+ */
+ exports.search = function search(aNeedle, aHaystack, aCompare) {
+ return aHaystack.length > 0
+ ? recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, aCompare)
+ : null;
+ };
+
+});
+/* -*- 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/array-set', ['require', 'exports', 'module' ], function(require, exports, module) {
+
+ /**
+ * A data structure which is a combination of an array and a set. Adding a new
+ * member is O(1), testing for membership is O(1), and finding the index of an
+ * element is O(1). Removing elements from the set is not supported. Only
+ * strings are supported for membership.
+ */
+ function ArraySet() {
+ this._array = [];
+ this._set = {};
+ }
+
+ /**
+ * Static method for creating ArraySet instances from an existing array.
+ */
+ ArraySet.fromArray = function ArraySet_fromArray(aArray) {
+ var set = new ArraySet();
+ for (var i = 0, len = aArray.length; i < len; i++) {
+ set.add(aArray[i]);
+ }
+ return set;
+ };
+
+ /**
+ * Add the given string to this set.
+ *
+ * @param String str
+ */
+ ArraySet.prototype.add = function ArraySet_add(aStr) {
+ if (this.has(aStr)) {
+ // Already a member; nothing to do.
+ return;
+ }
+ var idx = this._array.length;
+ this._array.push(aStr);
+ this._set[aStr] = idx;
+ };
+
+ /**
+ * Is the given string a member of this set?
+ *
+ * @param String str
+ */
+ ArraySet.prototype.has = function ArraySet_has(aStr) {
+ return Object.prototype.hasOwnProperty.call(this._set, aStr);
+ };
+
+ /**
+ * What is the index of the given string in the array?
+ *
+ * @param String str
+ */
+ ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) {
+ if (this.has(aStr)) {
+ return this._set[aStr];
+ }
+ throw new Error('"' + aStr + '" is not in the set.');
+ };
+
+ /**
+ * What is the element at the given index?
+ *
+ * @param Number idx
+ */
+ ArraySet.prototype.at = function ArraySet_at(aIdx) {
+ if (aIdx >= 0 && aIdx < this._array.length) {
+ return this._array[aIdx];
+ }
+ throw new Error('No element indexed by ' + aIdx);
+ };
+
+ /**
+ * Returns the array representation of this set (which has the proper indices
+ * indicated by indexOf). Note that this is a copy of the internal array used
+ * for storing the members so that no one can mess with internal state.
+ */
+ ArraySet.prototype.toArray = function ArraySet_toArray() {
+ return this._array.slice();
+ };
+
+ exports.ArraySet = ArraySet;
+
+});
+/* -*- 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
+ *
+ * Based on the Base 64 VLQ implementation in Closure Compiler:
+ * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
+ *
+ * Copyright 2011 The Closure Compiler Authors. All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+define('source-map/base64-vlq', ['require', 'exports', 'module' , 'source-map/base64'], function(require, exports, module) {
+
+ var base64 = require('source-map/base64');
+
+ // A single base 64 digit can contain 6 bits of data. For the base 64 variable
+ // length quantities we use in the source map spec, the first bit is the sign,
+ // the next four bits are the actual value, and the 6th bit is the
+ // continuation bit. The continuation bit tells us whether there are more
+ // digits in this value following this digit.
+ //
+ // Continuation
+ // | Sign
+ // | |
+ // V V
+ // 101011
+
+ var VLQ_BASE_SHIFT = 5;
+
+ // binary: 100000
+ var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
+
+ // binary: 011111
+ var VLQ_BASE_MASK = VLQ_BASE - 1;
+
+ // binary: 100000
+ var VLQ_CONTINUATION_BIT = VLQ_BASE;
+
+ /**
+ * Converts from a two-complement value to a value where the sign bit is
+ * is placed in the least significant bit. For example, as decimals:
+ * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
+ * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
+ */
+ function toVLQSigned(aValue) {
+ return aValue < 0
+ ? ((-aValue) << 1) + 1
+ : (aValue << 1) + 0;
+ }
+
+ /**
+ * Converts to a two-complement value from a value where the sign bit is
+ * is placed in the least significant bit. For example, as decimals:
+ * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
+ * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
+ */
+ function fromVLQSigned(aValue) {
+ var isNegative = (aValue & 1) === 1;
+ var shifted = aValue >> 1;
+ return isNegative
+ ? -shifted
+ : shifted;
+ }
+
+ /**
+ * Returns the base 64 VLQ encoded value.
+ */
+ exports.encode = function base64VLQ_encode(aValue) {
+ var encoded = "";
+ var digit;
+
+ var vlq = toVLQSigned(aValue);
+
+ do {
+ digit = vlq & VLQ_BASE_MASK;
+ vlq >>>= VLQ_BASE_SHIFT;
+ if (vlq > 0) {
+ // There are still more digits in this value, so we must make sure the
+ // continuation bit is marked.
+ digit |= VLQ_CONTINUATION_BIT;
+ }
+ encoded += base64.encode(digit);
+ } while (vlq > 0);
+
+ return encoded;
+ };
+
+ /**
+ * Decodes the next base 64 VLQ value from the given string and returns the
+ * value and the rest of the string.
+ */
+ exports.decode = function base64VLQ_decode(aStr) {
+ var i = 0;
+ var strLen = aStr.length;
+ var result = 0;
+ var shift = 0;
+ var continuation, digit;
+
+ do {
+ if (i >= strLen) {
+ throw new Error("Expected more digits in base 64 VLQ value.");
+ }
+ digit = base64.decode(aStr.charAt(i++));
+ continuation = !!(digit & VLQ_CONTINUATION_BIT);
+ digit &= VLQ_BASE_MASK;
+ result = result + (digit << shift);
+ shift += VLQ_BASE_SHIFT;
+ } while (continuation);
+
+ return {
+ value: fromVLQSigned(result),
+ rest: aStr.slice(i)
+ };
+ };
+
+});
+/* -*- 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;
+ });
+
+ /**
+ * 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];
+ }
+ throw new TypeError("Must be between 0 and 63: " + aNumber);
+ };
+
+ /**
+ * Decode a single base 64 digit to an integer.
+ */
+ exports.decode = function base64_decode(aChar) {
+ if (aChar in charToIntMap) {
+ return charToIntMap[aChar];
+ }
+ throw new TypeError("Not a valid base 64 digit: " + aChar);
+ };
+
+});
+/* -*- 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-generator', ['require', 'exports', 'module' , 'source-map/base64-vlq', 'source-map/util', 'source-map/array-set'], function(require, exports, module) {
+
+ var base64VLQ = require('source-map/base64-vlq');
+ var util = require('source-map/util');
+ var ArraySet = require('source-map/array-set').ArraySet;
+
+ /**
+ * An instance of the SourceMapGenerator represents a source map which is
+ * being built incrementally. To create a new one, you must pass an object
+ * with the following properties:
+ *
+ * - file: The filename of the generated source.
+ * - sourceRoot: An optional root for all URLs in this source map.
+ */
+ function SourceMapGenerator(aArgs) {
+ this._file = util.getArg(aArgs, 'file');
+ this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null);
+ this._sources = new ArraySet();
+ this._names = new ArraySet();
+ this._mappings = [];
+ }
+
+ SourceMapGenerator.prototype._version = 3;
+
+ /**
+ * Add a single mapping from original source line and column to the generated
+ * source's line and column for this source map being created. The mapping
+ * object should have the following properties:
+ *
+ * - generated: An object with the generated line and column positions.
+ * - original: An object with the original line and column positions.
+ * - source: The original source file (relative to the sourceRoot).
+ * - name: An optional original token name for this mapping.
+ */
+ SourceMapGenerator.prototype.addMapping =
+ function SourceMapGenerator_addMapping(aArgs) {
+ var generated = util.getArg(aArgs, 'generated');
+ var original = util.getArg(aArgs, 'original', null);
+ var source = util.getArg(aArgs, 'source', null);
+ var name = util.getArg(aArgs, 'name', null);
+
+ this._validateMapping(generated, original, source, name);
+
+ if (source && !this._sources.has(source)) {
+ this._sources.add(source);
+ }
+
+ if (name && !this._names.has(name)) {
+ this._names.add(name);
+ }
+
+ this._mappings.push({
+ generated: generated,
+ original: original,
+ source: source,
+ name: name
+ });
+ };
+
+ /**
+ * A mapping can have one of the three levels of data:
+ *
+ * 1. Just the generated position.
+ * 2. The Generated position, original position, and original source.
+ * 3. Generated and original position, original source, as well as a name
+ * token.
+ *
+ * To maintain consistency, we validate that any new mapping being added falls
+ * in to one of these categories.
+ */
+ SourceMapGenerator.prototype._validateMapping =
+ function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
+ aName) {
+ if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
+ && aGenerated.line > 0 && aGenerated.column >= 0
+ && !aOriginal && !aSource && !aName) {
+ // Case 1.
+ return;
+ }
+ else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
+ && aOriginal && 'line' in aOriginal && 'column' in aOriginal
+ && aGenerated.line > 0 && aGenerated.column >= 0
+ && aOriginal.line > 0 && aOriginal.column >= 0
+ && aSource) {
+ // Cases 2 and 3.
+ return;
+ }
+ else {
+ throw new Error('Invalid mapping.');
+ }
+ };
+
+ /**
+ * Serialize the accumulated mappings in to the stream of base 64 VLQs
+ * specified by the source map format.
+ */
+ SourceMapGenerator.prototype._serializeMappings =
+ function SourceMapGenerator_serializeMappings() {
+ var previousGeneratedColumn = 0;
+ var previousGeneratedLine = 1;
+ var previousOriginalColumn = 0;
+ var previousOriginalLine = 0;
+ var previousName = 0;
+ var previousSource = 0;
+ var result = '';
+ var mapping;
+
+ // The mappings must be guarenteed to be in sorted order before we start
+ // serializing them or else the generated line numbers (which are defined
+ // via the ';' separators) will be all messed up. Note: it might be more
+ // performant to maintain the sorting as we insert them, rather than as we
+ // serialize them, but the big O is the same either way.
+ this._mappings.sort(function (mappingA, mappingB) {
+ var cmp = mappingA.generated.line - mappingB.generated.line;
+ return cmp === 0
+ ? mappingA.generated.column - mappingB.generated.column
+ : cmp;
+ });
+
+ for (var i = 0, len = this._mappings.length; i < len; i++) {
+ mapping = this._mappings[i];
+
+ if (mapping.generated.line !== previousGeneratedLine) {
+ previousGeneratedColumn = 0;
+ while (mapping.generated.line !== previousGeneratedLine) {
+ result += ';';
+ previousGeneratedLine++;
+ }
+ }
+ else {
+ if (i > 0) {
+ result += ',';
+ }
+ }
+
+ result += base64VLQ.encode(mapping.generated.column
+ - previousGeneratedColumn);
+ previousGeneratedColumn = mapping.generated.column;
+
+ if (mapping.source && mapping.original) {
+ result += base64VLQ.encode(this._sources.indexOf(mapping.source)
+ - previousSource);
+ previousSource = this._sources.indexOf(mapping.source);
+
+ // lines are stored 0-based in SourceMap spec version 3
+ result += base64VLQ.encode(mapping.original.line - 1
+ - previousOriginalLine);
+ previousOriginalLine = mapping.original.line - 1;
+
+ result += base64VLQ.encode(mapping.original.column
+ - previousOriginalColumn);
+ previousOriginalColumn = mapping.original.column;
+
+ if (mapping.name) {
+ result += base64VLQ.encode(this._names.indexOf(mapping.name)
+ - previousName);
+ previousName = this._names.indexOf(mapping.name);
+ }
+ }
+ }
+
+ return result;
+ };
+
+ /**
+ * Render the source map being generated to a string.
+ */
+ SourceMapGenerator.prototype.toString =
+ function SourceMapGenerator_toString() {
+ var map = {
+ version: this._version,
+ file: this._file,
+ sources: this._sources.toArray(),
+ names: this._names.toArray(),
+ mappings: this._serializeMappings()
+ };
+ if (this._sourceRoot) {
+ map.sourceRoot = this._sourceRoot;
+ }
+ return JSON.stringify(map);
+ };
+
+ exports.SourceMapGenerator = SourceMapGenerator;
+
+});
+/* -*- 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-node', ['require', 'exports', 'module' , 'source-map/source-map-generator'], function(require, exports, module) {
+
+ var SourceMapGenerator = require('source-map/source-map-generator').SourceMapGenerator;
+
+ /**
+ * SourceNodes provide a way to abstract over interpolating/concatenating
+ * snippets of generated JavaScript source code while maintaining the line and
+ * column information associated with the original source code.
+ *
+ * @param aLine The original line number.
+ * @param aColumn The original column number.
+ * @param aSource The original source's filename.
+ * @param aChunks Optional. An array of strings which are snippets of
+ * generated JS, or other SourceNodes.
+ */
+ function SourceNode(aLine, aColumn, aSource, aChunks) {
+ this.children = [];
+ this.line = aLine;
+ this.column = aColumn;
+ this.source = aSource;
+ if (aChunks != null) this.add(aChunks);
+ }
+
+ /**
+ * Add a chunk of generated JS to this source node.
+ *
+ * @param aChunk A string snippet of generated JS code, another instance of
+ * SourceNode, or an array where each member is one of those things.
+ */
+ SourceNode.prototype.add = function SourceNode_add(aChunk) {
+ if (Array.isArray(aChunk)) {
+ aChunk.forEach(function (chunk) {
+ this.add(chunk);
+ }, this);
+ }
+ else if (aChunk instanceof SourceNode || typeof aChunk === "string") {
+ this.children.push(aChunk);
+ }
+ else {
+ throw new TypeError(
+ "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
+ );
+ }
+ return this;
+ };
+
+ /**
+ * Add a chunk of generated JS to the beginning of this source node.
+ *
+ * @param aChunk A string snippet of generated JS code, another instance of
+ * SourceNode, or an array where each member is one of those things.
+ */
+ SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
+ if (Array.isArray(aChunk)) {
+ for (var i = aChunk.length-1; i >= 0; i--) {
+ this.prepend(aChunk[i]);
+ }
+ }
+ else if (aChunk instanceof SourceNode || typeof aChunk === "string") {
+ this.children.unshift(aChunk);
+ }
+ else {
+ throw new TypeError(
+ "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
+ );
+ }
+ return this;
+ };
+
+ /**
+ * Walk over the tree of JS snippets in this node and its children. The
+ * walking function is called once for each snippet of JS and is passed that
+ * snippet and the its original associated source's line/column location.
+ *
+ * @param aFn The traversal function.
+ */
+ SourceNode.prototype.walk = function SourceNode_walk(aFn) {
+ this.children.forEach(function (chunk) {
+ if (chunk instanceof SourceNode) {
+ chunk.walk(aFn);
+ }
+ else {
+ if (chunk !== '') {
+ aFn(chunk, { source: this.source, line: this.line, column: this.column });
+ }
+ }
+ }, this);
+ };
+
+ /**
+ * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
+ * each of `this.children`.
+ *
+ * @param aSep The separator.
+ */
+ SourceNode.prototype.join = function SourceNode_join(aSep) {
+ var newChildren;
+ var i;
+ var len = this.children.length
+ if (len > 0) {
+ newChildren = [];
+ for (i = 0; i < len-1; i++) {
+ newChildren.push(this.children[i]);
+ newChildren.push(aSep);
+ }
+ newChildren.push(this.children[i]);
+ this.children = newChildren;
+ }
+ return this;
+ };
+
+ /**
+ * Call String.prototype.replace on the very right-most source snippet. Useful
+ * for trimming whitespace from the end of a source node, etc.
+ *
+ * @param aPattern The pattern to replace.
+ * @param aReplacement The thing to replace the pattern with.
+ */
+ SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
+ var lastChild = this.children[this.children.length - 1];
+ if (lastChild instanceof SourceNode) {
+ lastChild.replaceRight(aPattern, aReplacement);
+ }
+ else if (typeof lastChild === 'string') {
+ this.children[this.children.lenth - 1] = lastChild.replace(aPattern, aReplacement);
+ }
+ else {
+ this.children.push(''.replace(aPattern, aReplacement));
+ }
+ return this;
+ };
+
+ /**
+ * Return the string representation of this source node. Walks over the tree
+ * and concatenates all the various snippets together to one string.
+ */
+ SourceNode.prototype.toString = function SourceNode_toString() {
+ var str = "";
+ this.walk(function (chunk) {
+ str += chunk;
+ });
+ return str;
+ };
+
+ /**
+ * Returns the string representation of this source node along with a source
+ * map.
+ */
+ SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
+ var generated = {
+ code: "",
+ line: 1,
+ column: 0
+ };
+ var map = new SourceMapGenerator(aArgs);
+ this.walk(function (chunk, original) {
+ generated.code += chunk;
+ if (original.source != null
+ && original.line != null
+ && original.column != null) {
+ map.addMapping({
+ source: original.source,
+ original: {
+ line: original.line,
+ column: original.column
+ },
+ generated: {
+ line: generated.line,
+ column: generated.column
+ }
+ });
+ }
+ chunk.split('').forEach(function (char) {
+ if (char === '\n') {
+ generated.line++;
+ generated.column = 0;
+ } else {
+ generated.column++;
+ }
+ });
+ });
+
+ return { code: generated.code, map: map };
+ };
+
+ exports.SourceNode = SourceNode;
+
+});
+/* -*- Mode: js; js-indent-level: 2; -*- */
+///////////////////////////////////////////////////////////////////////////////
+
+let SourceMapConsumer = require('source-map/source-map-consumer').SourceMapConsumer;
+let SourceMapGenerator = require('source-map/source-map-generator').SourceMapGenerator;
+let SourceNode = require('source-map/source-node').SourceNode;
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/sourcemap/tests/Makefile.in
@@ -0,0 +1,17 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+DEPTH = ../../../..
+topsrcdir = @top_srcdir@
+srcdir = @srcdir@
+VPATH = @srcdir@
+relativesrcdir = toolkit/devtools/sourcemap/tests
+
+include $(DEPTH)/config/autoconf.mk
+
+MODULE = test_sourcemap
+
+XPCSHELL_TESTS = unit
+
+include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/sourcemap/tests/unit/Utils.jsm
@@ -0,0 +1,152 @@
+/* -*- 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
+ */
+
+/*
+ * WARNING!
+ *
+ * Do not edit this file directly, it is built from the sources at
+ * https://github.com/mozilla/source-map/
+ */
+
+Components.utils.import('resource:///modules/devtools/Require.jsm');
+Components.utils.import('resource:///modules/devtools/SourceMap.jsm');
+
+let EXPORTED_SYMBOLS = [ "define", "runSourceMapTests" ];
+/* -*- 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/assert', ['exports'], function (exports) {
+
+ let do_throw = function (msg) {
+ throw new Error(msg);
+ };
+
+ exports.init = function (throw_fn) {
+ do_throw = throw_fn;
+ };
+
+ exports.doesNotThrow = function (fn) {
+ try {
+ fn();
+ }
+ catch (e) {
+ do_throw(e.message);
+ }
+ };
+
+ exports.equal = function (actual, expected, msg) {
+ msg = msg || String(actual) + ' != ' + String(expected);
+ if (actual != expected) {
+ do_throw(msg);
+ }
+ };
+
+ exports.ok = function (val, msg) {
+ msg = msg || String(val) + ' is falsey';
+ if (!Boolean(val)) {
+ do_throw(msg);
+ }
+ };
+
+ exports.strictEqual = function (actual, expected, msg) {
+ msg = msg || String(actual) + ' !== ' + String(expected);
+ if (actual !== expected) {
+ do_throw(msg);
+ }
+ };
+
+ exports.throws = function (fn) {
+ try {
+ fn();
+ do_throw('Expected an error to be thrown, but it wasn\'t.');
+ }
+ catch (e) {
+ }
+ };
+
+});
+/* -*- 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/util', ['require', 'exports', 'module' ], function(require, exports, module) {
+
+ // This is a test mapping which maps functions from two different files
+ // (one.js and two.js) to a minified generated source.
+ //
+ // Here is one.js:
+ //
+ // ONE.foo = function (bar) {
+ // return baz(bar);
+ // };
+ //
+ // Here is two.js:
+ //
+ // TWO.inc = function (n) {
+ // return n + 1;
+ // };
+ //
+ // And here is the generated code (min.js):
+ //
+ // ONE.foo=function(a){return baz(a);};
+ // TWO.inc=function(a){return a+1;};
+ exports.testMap = {
+ version: 3,
+ file: 'min.js',
+ names: ['bar', 'baz', 'n'],
+ sources: ['one.js', 'two.js'],
+ sourceRoot: '/the/root',
+ mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA'
+ };
+
+ function assertMapping(generatedLine, generatedColumn, originalSource,
+ originalLine, originalColumn, name, map, assert) {
+ var mapping = map.originalPositionFor({
+ line: generatedLine,
+ column: generatedColumn
+ });
+ assert.equal(mapping.name, name,
+ 'Incorrect name, expected ' + JSON.stringify(name)
+ + ', got ' + JSON.stringify(mapping.name));
+ assert.equal(mapping.line, originalLine,
+ 'Incorrect line, expected ' + JSON.stringify(originalLine)
+ + ', got ' + JSON.stringify(mapping.line));
+ assert.equal(mapping.column, originalColumn,
+ 'Incorrect column, expected ' + JSON.stringify(originalColumn)
+ + ', got ' + JSON.stringify(mapping.column));
+ assert.equal(mapping.source, originalSource,
+ 'Incorrect source, expected ' + JSON.stringify(originalSource)
+ + ', got ' + JSON.stringify(mapping.source));
+ }
+ exports.assertMapping = assertMapping;
+
+});
+/* -*- 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
+ */
+function runSourceMapTests(modName, do_throw) {
+ let mod = require(modName);
+ let assert = require('test/source-map/assert');
+ let util = require('test/source-map/util');
+
+ assert.init(do_throw);
+
+ for (let k in mod) {
+ if (/^test/.test(k)) {
+ mod[k](assert, util);
+ }
+ }
+
+}
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/sourcemap/tests/unit/head_sourcemap.js
@@ -0,0 +1,8 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+const Cu = Components.utils;
+const Cr = Components.results;
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/sourcemap/tests/unit/test_array_set.js
@@ -0,0 +1,71 @@
+/*
+ * 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-array-set", ["require", "exports", "module"], function (require, exports, module) {
+
+ var ArraySet = require('source-map/array-set').ArraySet;
+
+ function makeTestSet() {
+ var set = new ArraySet();
+ for (var i = 0; i < 100; i++) {
+ set.add(String(i));
+ }
+ return set;
+ }
+
+ exports['test .has() membership'] = function (assert, util) {
+ var set = makeTestSet();
+ for (var i = 0; i < 100; i++) {
+ assert.ok(set.has(String(i)));
+ }
+ };
+
+ exports['test .indexOf() elements'] = function (assert, util) {
+ var set = makeTestSet();
+ for (var i = 0; i < 100; i++) {
+ assert.strictEqual(set.indexOf(String(i)), i);
+ }
+ };
+
+ exports['test .at() indexing'] = function (assert, util) {
+ var set = makeTestSet();
+ for (var i = 0; i < 100; i++) {
+ assert.strictEqual(set.at(i), String(i));
+ }
+ };
+
+ exports['test creating from an array'] = function (assert, util) {
+ var set = ArraySet.fromArray(['foo', 'bar', 'baz', 'quux', 'hasOwnProperty']);
+
+ assert.ok(set.has('foo'));
+ assert.ok(set.has('bar'));
+ assert.ok(set.has('baz'));
+ assert.ok(set.has('quux'));
+ assert.ok(set.has('hasOwnProperty'));
+
+ assert.strictEqual(set.indexOf('foo'), 0);
+ assert.strictEqual(set.indexOf('bar'), 1);
+ assert.strictEqual(set.indexOf('baz'), 2);
+ assert.strictEqual(set.indexOf('quux'), 3);
+
+ assert.strictEqual(set.at(0), 'foo');
+ assert.strictEqual(set.at(1), 'bar');
+ assert.strictEqual(set.at(2), 'baz');
+ assert.strictEqual(set.at(3), 'quux');
+ };
+
+});
+function run_test() {
+ runSourceMapTests('test/source-map/test-array-set', do_throw);
+}
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/sourcemap/tests/unit/test_base64.js
@@ -0,0 +1,43 @@
+/*
+ * 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-base64", ["require", "exports", "module"], function (require, exports, module) {
+
+ var base64 = require('source-map/base64');
+
+ exports['test out of range encoding'] = function (assert, util) {
+ assert.throws(function () {
+ base64.encode(-1);
+ });
+ assert.throws(function () {
+ base64.encode(64);
+ });
+ };
+
+ exports['test out of range decoding'] = function (assert, util) {
+ assert.throws(function () {
+ base64.decode('=');
+ });
+ };
+
+ exports['test normal encoding and decoding'] = function (assert, util) {
+ for (var i = 0; i < 64; i++) {
+ assert.equal(base64.decode(base64.encode(i)), 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_base64_vlq.js
@@ -0,0 +1,32 @@
+/*
+ * 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-base64-vlq", ["require", "exports", "module"], function (require, exports, module) {
+
+ var base64VLQ = require('source-map/base64-vlq');
+
+ exports['test normal encoding and decoding'] = function (assert, util) {
+ var result;
+ for (var i = -255; i < 256; i++) {
+ result = base64VLQ.decode(base64VLQ.encode(i));
+ assert.ok(result);
+ assert.equal(result.value, i);
+ assert.equal(result.rest, "");
+ }
+ };
+
+});
+function run_test() {
+ runSourceMapTests('test/source-map/test-base64-vlq', do_throw);
+}
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/sourcemap/tests/unit/test_binary_search.js
@@ -0,0 +1,62 @@
+/*
+ * 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-binary-search", ["require", "exports", "module"], function (require, exports, module) {
+
+ var binarySearch = require('source-map/binary-search');
+
+ function numberCompare(a, b) {
+ return a - b;
+ }
+
+ exports['test too high'] = function (assert, util) {
+ var needle = 30;
+ var haystack = [2,4,6,8,10,12,14,16,18,20];
+
+ assert.doesNotThrow(function () {
+ binarySearch.search(needle, haystack, numberCompare);
+ });
+
+ assert.equal(binarySearch.search(needle, haystack, numberCompare), 20);
+ };
+
+ exports['test too low'] = function (assert, util) {
+ var needle = 1;
+ var haystack = [2,4,6,8,10,12,14,16,18,20];
+
+ assert.doesNotThrow(function () {
+ binarySearch.search(needle, haystack, numberCompare);
+ });
+
+ assert.equal(binarySearch.search(needle, haystack, numberCompare), null);
+ };
+
+ exports['test exact search'] = function (assert, util) {
+ var needle = 4;
+ var haystack = [2,4,6,8,10,12,14,16,18,20];
+
+ assert.equal(binarySearch.search(needle, haystack, numberCompare), 4);
+ };
+
+ exports['test fuzzy search'] = function (assert, util) {
+ var needle = 19;
+ var haystack = [2,4,6,8,10,12,14,16,18,20];
+
+ assert.equal(binarySearch.search(needle, haystack, numberCompare), 18);
+ };
+
+});
+function run_test() {
+ runSourceMapTests('test/source-map/test-binary-search', do_throw);
+}
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/sourcemap/tests/unit/test_dog_fooding.js
@@ -0,0 +1,72 @@
+/*
+ * 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-dog-fooding", ["require", "exports", "module"], function (require, exports, module) {
+
+ var SourceMapConsumer = require('source-map/source-map-consumer').SourceMapConsumer;
+ var SourceMapGenerator = require('source-map/source-map-generator').SourceMapGenerator;
+
+ exports['test eating our own dog food'] = function (assert, util) {
+ var smg = new SourceMapGenerator({
+ file: 'testing.js',
+ sourceRoot: '/wu/tang'
+ });
+
+ smg.addMapping({
+ source: 'gza.coffee',
+ original: { line: 1, column: 0 },
+ generated: { line: 2, column: 2 }
+ });
+
+ smg.addMapping({
+ source: 'gza.coffee',
+ original: { line: 2, column: 0 },
+ generated: { line: 3, column: 2 }
+ });
+
+ smg.addMapping({
+ source: 'gza.coffee',
+ original: { line: 3, column: 0 },
+ generated: { line: 4, column: 2 }
+ });
+
+ smg.addMapping({
+ source: 'gza.coffee',
+ original: { line: 4, column: 0 },
+ generated: { line: 5, column: 2 }
+ });
+
+ var smc = new SourceMapConsumer(smg.toString());
+
+ // Exact
+ util.assertMapping(2, 2, '/wu/tang/gza.coffee', 1, 0, null, smc, assert);
+ util.assertMapping(3, 2, '/wu/tang/gza.coffee', 2, 0, null, smc, assert);
+ util.assertMapping(4, 2, '/wu/tang/gza.coffee', 3, 0, null, smc, assert);
+ util.assertMapping(5, 2, '/wu/tang/gza.coffee', 4, 0, null, smc, assert);
+
+ // Fuzzy
+ util.assertMapping(2, 0, null, null, null, null, smc, assert);
+ util.assertMapping(2, 9, '/wu/tang/gza.coffee', 1, 0, null, smc, assert);
+ util.assertMapping(3, 0, '/wu/tang/gza.coffee', 1, 0, null, smc, assert);
+ util.assertMapping(3, 9, '/wu/tang/gza.coffee', 2, 0, null, smc, assert);
+ util.assertMapping(4, 0, '/wu/tang/gza.coffee', 2, 0, null, smc, assert);
+ util.assertMapping(4, 9, '/wu/tang/gza.coffee', 3, 0, null, smc, assert);
+ util.assertMapping(5, 0, '/wu/tang/gza.coffee', 3, 0, null, smc, assert);
+ util.assertMapping(5, 9, '/wu/tang/gza.coffee', 4, 0, null, smc, assert);
+ };
+
+});
+function run_test() {
+ runSourceMapTests('test/source-map/test-dog-fooding', do_throw);
+}
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/sourcemap/tests/unit/test_source_map_consumer.js
@@ -0,0 +1,75 @@
+/*
+ * 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-source-map-consumer", ["require", "exports", "module"], function (require, exports, module) {
+
+ var SourceMapConsumer = require('source-map/source-map-consumer').SourceMapConsumer;
+
+ exports['test that we can instantiate with a string or an objects'] = function (assert, util) {
+ assert.doesNotThrow(function () {
+ var map = new SourceMapConsumer(util.testMap);
+ });
+ assert.doesNotThrow(function () {
+ var map = new SourceMapConsumer(JSON.stringify(util.testMap));
+ });
+ };
+
+ exports['test that the source root is reflected in a mapping\'s source field'] = function (assert, util) {
+ var map = new SourceMapConsumer(util.testMap);
+ var mapping;
+
+ mapping = map.originalPositionFor({
+ line: 2,
+ column: 1
+ });
+ assert.equal(mapping.source, '/the/root/two.js');
+
+ mapping = map.originalPositionFor({
+ line: 1,
+ column: 1
+ });
+ assert.equal(mapping.source, '/the/root/one.js');
+ };
+
+ exports['test mapping tokens back exactly'] = function (assert, util) {
+ var map = new SourceMapConsumer(util.testMap);
+
+ util.assertMapping(1, 1, '/the/root/one.js', 1, 1, null, map, assert);
+ util.assertMapping(1, 5, '/the/root/one.js', 1, 5, null, map, assert);
+ util.assertMapping(1, 9, '/the/root/one.js', 1, 11, null, map, assert);
+ util.assertMapping(1, 18, '/the/root/one.js', 1, 21, 'bar', map, assert);
+ util.assertMapping(1, 21, '/the/root/one.js', 2, 3, null, map, assert);
+ util.assertMapping(1, 28, '/the/root/one.js', 2, 10, 'baz', map, assert);
+ util.assertMapping(1, 32, '/the/root/one.js', 2, 14, 'bar', map, assert);
+
+ util.assertMapping(2, 1, '/the/root/two.js', 1, 1, null, map, assert);
+ util.assertMapping(2, 5, '/the/root/two.js', 1, 5, null, map, assert);
+ util.assertMapping(2, 9, '/the/root/two.js', 1, 11, null, map, assert);
+ util.assertMapping(2, 18, '/the/root/two.js', 1, 21, 'n', map, assert);
+ util.assertMapping(2, 21, '/the/root/two.js', 2, 3, null, map, assert);
+ util.assertMapping(2, 28, '/the/root/two.js', 2, 10, 'n', map, assert);
+ };
+
+ exports['test mapping tokens back fuzzy'] = function (assert, util) {
+ var map = new SourceMapConsumer(util.testMap);
+
+ util.assertMapping(1, 20, '/the/root/one.js', 1, 21, 'bar', map, assert);
+ util.assertMapping(1, 30, '/the/root/one.js', 2, 10, 'baz', map, assert);
+ util.assertMapping(2, 12, '/the/root/two.js', 1, 11, null, map, assert);
+ };
+
+});
+function run_test() {
+ runSourceMapTests('test/source-map/test-source-map-consumer', do_throw);
+}
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/sourcemap/tests/unit/test_source_map_generator.js
@@ -0,0 +1,187 @@
+/*
+ * 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-source-map-generator", ["require", "exports", "module"], function (require, exports, module) {
+
+ var SourceMapGenerator = require('source-map/source-map-generator').SourceMapGenerator;
+
+ exports['test some simple stuff'] = function (assert, util) {
+ var map = new SourceMapGenerator({
+ file: 'foo.js',
+ sourceRoot: '.'
+ });
+ assert.ok(true);
+ };
+
+ exports['test adding mappings (case 1)'] = function (assert, util) {
+ var map = new SourceMapGenerator({
+ file: 'generated-foo.js',
+ sourceRoot: '.'
+ });
+
+ assert.doesNotThrow(function () {
+ map.addMapping({
+ generated: { line: 1, column: 1 }
+ });
+ });
+ };
+
+ exports['test adding mappings (case 2)'] = function (assert, util) {
+ var map = new SourceMapGenerator({
+ file: 'generated-foo.js',
+ sourceRoot: '.'
+ });
+
+ assert.doesNotThrow(function () {
+ map.addMapping({
+ generated: { line: 1, column: 1 },
+ source: 'bar.js',
+ original: { line: 1, column: 1 }
+ });
+ });
+ };
+
+ exports['test adding mappings (case 3)'] = function (assert, util) {
+ var map = new SourceMapGenerator({
+ file: 'generated-foo.js',
+ sourceRoot: '.'
+ });
+
+ assert.doesNotThrow(function () {
+ map.addMapping({
+ generated: { line: 1, column: 1 },
+ source: 'bar.js',
+ original: { line: 1, column: 1 },
+ name: 'someToken'
+ });
+ });
+ };
+
+ exports['test adding mappings (invalid)'] = function (assert, util) {
+ var map = new SourceMapGenerator({
+ file: 'generated-foo.js',
+ sourceRoot: '.'
+ });
+
+ // Not enough info.
+ assert.throws(function () {
+ map.addMapping({});
+ });
+
+ // Original file position, but no source.
+ assert.throws(function () {
+ map.addMapping({
+ generated: { line: 1, column: 1 },
+ original: { line: 1, column: 1 }
+ });
+ });
+ };
+
+ exports['test that the correct mappings are being generated'] = function (assert, util) {
+ var map = new SourceMapGenerator({
+ file: 'min.js',
+ sourceRoot: '/the/root'
+ });
+
+ map.addMapping({
+ generated: { line: 1, column: 1 },
+ original: { line: 1, column: 1 },
+ source: 'one.js'
+ });
+ map.addMapping({
+ generated: { line: 1, column: 5 },
+ original: { line: 1, column: 5 },
+ source: 'one.js'
+ });
+ map.addMapping({
+ generated: { line: 1, column: 9 },
+ original: { line: 1, column: 11 },
+ source: 'one.js'
+ });
+ map.addMapping({
+ generated: { line: 1, column: 18 },
+ original: { line: 1, column: 21 },
+ source: 'one.js',
+ name: 'bar'
+ });
+ map.addMapping({
+ generated: { line: 1, column: 21 },
+ original: { line: 2, column: 3 },
+ source: 'one.js'
+ });
+ map.addMapping({
+ generated: { line: 1, column: 28 },
+ original: { line: 2, column: 10 },
+ source: 'one.js',
+ name: 'baz'
+ });
+ map.addMapping({
+ generated: { line: 1, column: 32 },
+ original: { line: 2, column: 14 },
+ source: 'one.js',
+ name: 'bar'
+ });
+
+ map.addMapping({
+ generated: { line: 2, column: 1 },
+ original: { line: 1, column: 1 },
+ source: 'two.js'
+ });
+ map.addMapping({
+ generated: { line: 2, column: 5 },
+ original: { line: 1, column: 5 },
+ source: 'two.js'
+ });
+ map.addMapping({
+ generated: { line: 2, column: 9 },
+ original: { line: 1, column: 11 },
+ source: 'two.js'
+ });
+ map.addMapping({
+ generated: { line: 2, column: 18 },
+ original: { line: 1, column: 21 },
+ source: 'two.js',
+ name: 'n'
+ });
+ map.addMapping({
+ generated: { line: 2, column: 21 },
+ original: { line: 2, column: 3 },
+ source: 'two.js'
+ });
+ map.addMapping({
+ generated: { line: 2, column: 28 },
+ original: { line: 2, column: 10 },
+ source: 'two.js',
+ name: 'n'
+ });
+
+ map = JSON.parse(map.toString());
+
+ assert.equal(map.version, 3);
+ assert.equal(map.file, 'min.js');
+ assert.equal(map.names.length, 3);
+ assert.equal(map.names[0], 'bar');
+ assert.equal(map.names[1], 'baz');
+ assert.equal(map.names[2], 'n');
+ assert.equal(map.sources.length, 2);
+ assert.equal(map.sources[0], 'one.js');
+ assert.equal(map.sources[1], 'two.js');
+ assert.equal(map.sourceRoot, '/the/root');
+ assert.equal(map.mappings, 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA');
+ };
+
+});
+function run_test() {
+ runSourceMapTests('test/source-map/test-source-map-generator', do_throw);
+}
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/sourcemap/tests/unit/test_source_node.js
@@ -0,0 +1,155 @@
+/*
+ * 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-source-node", ["require", "exports", "module"], function (require, exports, module) {
+
+ var SourceMapGenerator = require('source-map/source-map-generator').SourceMapGenerator;
+ var SourceMapConsumer = require('source-map/source-map-consumer').SourceMapConsumer;
+ var SourceNode = require('source-map/source-node').SourceNode;
+
+ exports['test .add()'] = function (assert, util) {
+ var node = new SourceNode(null, null, null);
+
+ // Adding a string works.
+ node.add('function noop() {}');
+
+ // Adding another source node works.
+ node.add(new SourceNode(null, null, null));
+
+ // Adding an array works.
+ node.add(['function foo() {',
+ new SourceNode(null, null, null,
+ 'return 10;'),
+ '}']);
+
+ // Adding other stuff doesn't.
+ assert.throws(function () {
+ node.add({});
+ });
+ assert.throws(function () {
+ node.add(function () {});
+ });
+ };
+
+ exports['test .prepend()'] = function (assert, util) {
+ var node = new SourceNode(null, null, null);
+
+ // Prepending a string works.
+ node.prepend('function noop() {}');
+ assert.equal(node.children[0], 'function noop() {}');
+ assert.equal(node.children.length, 1);
+
+ // Prepending another source node works.
+ node.prepend(new SourceNode(null, null, null));
+ assert.equal(node.children[0], '');
+ assert.equal(node.children[1], 'function noop() {}');
+ assert.equal(node.children.length, 2);
+
+ // Prepending an array works.
+ node.prepend(['function foo() {',
+ new SourceNode(null, null, null,
+ 'return 10;'),
+ '}']);
+ assert.equal(node.children[0], 'function foo() {');
+ assert.equal(node.children[1], 'return 10;');
+ assert.equal(node.children[2], '}');
+ assert.equal(node.children[3], '');
+ assert.equal(node.children[4], 'function noop() {}');
+ assert.equal(node.children.length, 5);
+
+ // Prepending other stuff doesn't.
+ assert.throws(function () {
+ node.prepend({});
+ });
+ assert.throws(function () {
+ node.prepend(function () {});
+ });
+ };
+
+ exports['test .toString()'] = function (assert, util) {
+ assert.equal((new SourceNode(null, null, null,
+ ['function foo() {',
+ new SourceNode(null, null, null, 'return 10;'),
+ '}'])).toString(),
+ 'function foo() {return 10;}');
+ };
+
+ exports['test .join()'] = function (assert, util) {
+ assert.equal((new SourceNode(null, null, null,
+ ['a', 'b', 'c', 'd'])).join(', ').toString(),
+ 'a, b, c, d');
+ };
+
+ exports['test .walk()'] = function (assert, util) {
+ var node = new SourceNode(null, null, null,
+ ['(function () {\n',
+ ' ', new SourceNode(1, 0, 'a.js', ['someCall()']), ';\n',
+ ' ', new SourceNode(2, 0, 'b.js', ['if (foo) bar()']), ';\n',
+ '}());']);
+ var expected = [
+ { str: '(function () {\n', source: null, line: null, column: null },
+ { str: ' ', source: null, line: null, column: null },
+ { str: 'someCall()', source: 'a.js', line: 1, column: 0 },
+ { str: ';\n', source: null, line: null, column: null },
+ { str: ' ', source: null, line: null, column: null },
+ { str: 'if (foo) bar()', source: 'b.js', line: 2, column: 0 },
+ { str: ';\n', source: null, line: null, column: null },
+ { str: '}());', source: null, line: null, column: null },
+ ];
+ var i = 0;
+ node.walk(function (chunk, loc) {
+ assert.equal(expected[i].str, chunk);
+ assert.equal(expected[i].source, loc.source);
+ assert.equal(expected[i].line, loc.line);
+ assert.equal(expected[i].column, loc.column);
+ i++;
+ });
+ };
+
+ exports['test .toStringWithSourceMap()'] = function (assert, util) {
+ var node = new SourceNode(null, null, null,
+ ['(function () {\n',
+ ' ', new SourceNode(1, 0, 'a.js', ['someCall()']), ';\n',
+ ' ', new SourceNode(2, 0, 'b.js', ['if (foo) bar()']), ';\n',
+ '}());']);
+ var map = node.toStringWithSourceMap({
+ file: 'foo.js'
+ }).map;
+
+ assert.ok(map instanceof SourceMapGenerator, 'map instanceof SourceMapGenerator');
+ map = new SourceMapConsumer(map.toString());
+
+ var actual;
+
+ actual = map.originalPositionFor({
+ line: 2,
+ column: 2
+ });
+ assert.equal(actual.source, 'a.js');
+ assert.equal(actual.line, 1);
+ assert.equal(actual.column, 0);
+
+ actual = map.originalPositionFor({
+ line: 3,
+ column: 2
+ });
+ assert.equal(actual.source, 'b.js');
+ assert.equal(actual.line, 2);
+ assert.equal(actual.column, 0);
+ };
+
+});
+function run_test() {
+ runSourceMapTests('test/source-map/test-source-node', do_throw);
+}
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/sourcemap/tests/unit/xpcshell.ini
@@ -0,0 +1,12 @@
+[DEFAULT]
+head = head_sourcemap.js
+tail =
+
+[test_source_node.js]
+[test_source_map_generator.js]
+[test_source_map_consumer.js]
+[test_dog_fooding.js]
+[test_binary_search.js]
+[test_base64_vlq.js]
+[test_base64.js]
+[test_array_set.js]