mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 669999 - Add a library for parsing and consuming source map files to Firefox; r=joe_walker,rcampbell
This commit is contained in:
parent
d208f39475
commit
7087aa3913
@ -23,6 +23,7 @@
|
||||
[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"
|
||||
|
@ -11,6 +11,7 @@ include $(topsrcdir)/config/config.mk
|
||||
|
||||
PARALLEL_DIRS += \
|
||||
debugger \
|
||||
sourcemap \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
19
toolkit/devtools/sourcemap/Makefile.in
Normal file
19
toolkit/devtools/sourcemap/Makefile.in
Normal file
@ -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
|
1045
toolkit/devtools/sourcemap/SourceMap.jsm
Normal file
1045
toolkit/devtools/sourcemap/SourceMap.jsm
Normal file
File diff suppressed because it is too large
Load Diff
17
toolkit/devtools/sourcemap/tests/Makefile.in
Normal file
17
toolkit/devtools/sourcemap/tests/Makefile.in
Normal file
@ -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
|
152
toolkit/devtools/sourcemap/tests/unit/Utils.jsm
Normal file
152
toolkit/devtools/sourcemap/tests/unit/Utils.jsm
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
8
toolkit/devtools/sourcemap/tests/unit/head_sourcemap.js
Normal file
8
toolkit/devtools/sourcemap/tests/unit/head_sourcemap.js
Normal file
@ -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;
|
71
toolkit/devtools/sourcemap/tests/unit/test_array_set.js
Normal file
71
toolkit/devtools/sourcemap/tests/unit/test_array_set.js
Normal file
@ -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);
|
||||
}
|
43
toolkit/devtools/sourcemap/tests/unit/test_base64.js
Normal file
43
toolkit/devtools/sourcemap/tests/unit/test_base64.js
Normal file
@ -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);
|
||||
}
|
32
toolkit/devtools/sourcemap/tests/unit/test_base64_vlq.js
Normal file
32
toolkit/devtools/sourcemap/tests/unit/test_base64_vlq.js
Normal file
@ -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);
|
||||
}
|
62
toolkit/devtools/sourcemap/tests/unit/test_binary_search.js
Normal file
62
toolkit/devtools/sourcemap/tests/unit/test_binary_search.js
Normal file
@ -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);
|
||||
}
|
72
toolkit/devtools/sourcemap/tests/unit/test_dog_fooding.js
Normal file
72
toolkit/devtools/sourcemap/tests/unit/test_dog_fooding.js
Normal file
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
155
toolkit/devtools/sourcemap/tests/unit/test_source_node.js
Normal file
155
toolkit/devtools/sourcemap/tests/unit/test_source_node.js
Normal file
@ -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);
|
||||
}
|
12
toolkit/devtools/sourcemap/tests/unit/xpcshell.ini
Normal file
12
toolkit/devtools/sourcemap/tests/unit/xpcshell.ini
Normal file
@ -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]
|
Loading…
Reference in New Issue
Block a user