Backout c49d5912c0de on a CLOSED TREE due to pushing the wrong version of the patch.

This commit is contained in:
Nick Fitzgerald 2013-09-24 15:16:25 -07:00
parent ac441cfae8
commit 48f6a3c421
6 changed files with 127 additions and 361 deletions

View File

@ -46,7 +46,7 @@ function testSetBreakpoint() {
let deferred = promise.defer();
gDebugger.gThreadClient.interrupt(aResponse => {
gDebugger.gThreadClient.setBreakpoint({ url: JS_URL, line: 30, column: 21 }, aResponse => {
gDebugger.gThreadClient.setBreakpoint({ url: JS_URL, line: 30, column: 10 }, aResponse => {
ok(!aResponse.error,
"Should be able to set a breakpoint in a js file.");
ok(!aResponse.actualLocation,

View File

@ -2401,7 +2401,6 @@ SourceActor.prototype = {
* Handler for the "prettyPrint" packet.
*/
onPrettyPrint: function ({ indent }) {
console.time('pretty print');
return this._getSourceText()
.then(this._parseAST)
.then(this._generatePrettyCodeAndMap(indent))
@ -2412,11 +2411,7 @@ SourceActor.prototype = {
from: this.actorID,
error: "prettyPrintError",
message: DevToolsUtils.safeErrorString(error)
}))
.then(p => {
console.timeEnd('pretty print');
return p;
});
}));
},
/**
@ -2441,8 +2436,8 @@ SourceActor.prototype = {
style: indent
}
},
// sourceMap: this._url,
// sourceMapWithCode: true
sourceMap: this._url,
sourceMapWithCode: true
});
},
@ -2451,37 +2446,37 @@ SourceActor.prototype = {
* source map from b to a. We need to do this because the source map we get
* from _generatePrettyCodeAndMap goes the opposite way we want it to for
* debugging.
*
* Note that the source map is modified in place.
*/
_invertSourceMap: function SA__invertSourceMap({ code, map }) {
// XXX bug 918802: Monkey punch the source map consumer, because iterating
// over all mappings and inverting each of them, and then creating a new
// SourceMapConsumer is *way* too slow.
map.setSourceContent(this._url, code);
const consumer = new SourceMapConsumer.fromSourceMap(map);
const getOrigPos = consumer.originalPositionFor.bind(consumer);
const getGenPos = consumer.generatedPositionFor.bind(consumer);
consumer.originalPositionFor = ({ line, column }) => {
const location = getGenPos({
line: line,
column: column,
source: this._url
const smc = new SourceMapConsumer(map.toJSON());
const invertedMap = new SourceMapGenerator({
file: this._url
});
location.source = this._url;
return location;
smc.eachMapping(m => {
if (!m.originalLine || !m.originalColumn) {
return;
}
const invertedMapping = {
source: m.source,
name: m.name,
original: {
line: m.generatedLine,
column: m.generatedColumn
},
generated: {
line: m.originalLine,
column: m.originalColumn
}
};
consumer.generatedPositionFor = ({ line, column }) => getOrigPos({
line: line,
column: column
invertedMap.addMapping(invertedMapping);
});
invertedMap.setSourceContent(this._url, code);
return {
code: code,
map: consumer
map: new SourceMapConsumer(invertedMap.toJSON())
};
},
@ -2496,7 +2491,7 @@ SourceActor.prototype = {
// Compose the source maps
this._sourceMap = SourceMapGenerator.fromSourceMap(this._sourceMap);
this._sourceMap.applySourceMap(map, this._url);
this._sourceMap = SourceMapConsumer.fromSourceMap(this._sourceMap);
this._sourceMap = new SourceMapConsumer(this._sourceMap.toJSON());
this._threadActor.sources.saveSourceMap(this._sourceMap,
this._generatedSource);
} else {

View File

@ -117,32 +117,6 @@ define('source-map/source-map-consumer', ['require', 'exports', 'module' , 'sou
this._parseMappings(mappings, sourceRoot);
}
/**
* Create a SourceMapConsumer from a SourceMapGenerator.
*
* @param SourceMapGenerator aSourceMap
* The source map that will be consumed.
* @returns SourceMapConsumer
*/
SourceMapConsumer.fromSourceMap =
function SourceMapConsumer_fromSourceMap(aSourceMap) {
var smc = Object.create(SourceMapConsumer.prototype);
smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
smc.sourceRoot = aSourceMap._sourceRoot;
smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
smc.sourceRoot);
smc.file = aSourceMap._file;
smc._generatedMappings = aSourceMap._mappings.slice()
.sort(util.compareByGeneratedPositions);
smc._originalMappings = aSourceMap._mappings.slice()
.sort(util.compareByOriginalPositions);
return smc;
};
/**
* The version of the source mapping spec that we are consuming.
*/
@ -238,7 +212,37 @@ define('source-map/source-map-consumer', ['require', 'exports', 'module' , 'sou
}
}
this._originalMappings.sort(util.compareByOriginalPositions);
this._originalMappings.sort(this._compareOriginalPositions);
};
/**
* Comparator between two mappings where the original positions are compared.
*/
SourceMapConsumer.prototype._compareOriginalPositions =
function SourceMapConsumer_compareOriginalPositions(mappingA, mappingB) {
if (mappingA.source > mappingB.source) {
return 1;
}
else if (mappingA.source < mappingB.source) {
return -1;
}
else {
var cmp = mappingA.originalLine - mappingB.originalLine;
return cmp === 0
? mappingA.originalColumn - mappingB.originalColumn
: cmp;
}
};
/**
* Comparator between two mappings where the generated positions are compared.
*/
SourceMapConsumer.prototype._compareGeneratedPositions =
function SourceMapConsumer_compareGeneratedPositions(mappingA, mappingB) {
var cmp = mappingA.generatedLine - mappingB.generatedLine;
return cmp === 0
? mappingA.generatedColumn - mappingB.generatedColumn
: cmp;
};
/**
@ -291,7 +295,7 @@ define('source-map/source-map-consumer', ['require', 'exports', 'module' , 'sou
this._generatedMappings,
"generatedLine",
"generatedColumn",
util.compareByGeneratedPositions);
this._compareGeneratedPositions);
if (mapping) {
var source = util.getArg(mapping, 'source', null);
@ -385,7 +389,7 @@ define('source-map/source-map-consumer', ['require', 'exports', 'module' , 'sou
this._originalMappings,
"originalLine",
"originalColumn",
util.compareByOriginalPositions);
this._compareOriginalPositions);
if (mapping) {
return {
@ -570,93 +574,6 @@ define('source-map/util', ['require', 'exports', 'module' , ], function(require,
}
exports.relative = relative;
function strcmp(aStr1, aStr2) {
var s1 = aStr1 || "";
var s2 = aStr2 || "";
return (s1 > s2) - (s1 < s2);
}
/**
* Comparator between two mappings where the original positions are compared.
*
* Optionally pass in `true` as `onlyCompareGenerated` to consider two
* mappings with the same original source/line/column, but different generated
* line and column the same. Useful when searching for a mapping with a
* stubbed out mapping.
*/
function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
var cmp;
cmp = strcmp(mappingA.source, mappingB.source);
if (cmp) {
return cmp;
}
cmp = mappingA.originalLine - mappingB.originalLine;
if (cmp) {
return cmp;
}
cmp = mappingA.originalColumn - mappingB.originalColumn;
if (cmp || onlyCompareOriginal) {
return cmp;
}
cmp = strcmp(mappingA.name, mappingB.name);
if (cmp) {
return cmp;
}
cmp = mappingA.generatedLine - mappingB.generatedLine;
if (cmp) {
return cmp;
}
return mappingA.generatedColumn - mappingB.generatedColumn;
};
exports.compareByOriginalPositions = compareByOriginalPositions;
/**
* Comparator between two mappings where the generated positions are
* compared.
*
* Optionally pass in `true` as `onlyCompareGenerated` to consider two
* mappings with the same generated line and column, but different
* source/name/original line and column the same. Useful when searching for a
* mapping with a stubbed out mapping.
*/
function compareByGeneratedPositions(mappingA, mappingB, onlyCompareGenerated) {
var cmp;
cmp = mappingA.generatedLine - mappingB.generatedLine;
if (cmp) {
return cmp;
}
cmp = mappingA.generatedColumn - mappingB.generatedColumn;
if (cmp || onlyCompareGenerated) {
return cmp;
}
cmp = strcmp(mappingA.source, mappingB.source);
if (cmp) {
return cmp;
}
cmp = mappingA.originalLine - mappingB.originalLine;
if (cmp) {
return cmp;
}
cmp = mappingA.originalColumn - mappingB.originalColumn;
if (cmp) {
return cmp;
}
return strcmp(mappingA.name, mappingB.name);
};
exports.compareByGeneratedPositions = compareByGeneratedPositions;
});
/* -*- Mode: js; js-indent-level: 2; -*- */
/*
@ -687,7 +604,7 @@ define('source-map/binary-search', ['require', 'exports', 'module' , ], function
// 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], true);
var cmp = aCompare(aNeedle, aHaystack[mid]);
if (cmp === 0) {
// Found the element we are looking for.
return aHaystack[mid];
@ -1116,10 +1033,8 @@ define('source-map/source-map-generator', ['require', 'exports', 'module' , 'so
}
this._mappings.push({
generatedLine: generated.line,
generatedColumn: generated.column,
originalLine: original != null && original.line,
originalColumn: original != null && original.column,
generated: generated,
original: original,
source: source,
name: name
});
@ -1168,11 +1083,13 @@ define('source-map/source-map-generator', ['require', 'exports', 'module' , 'so
if (!aSourceFile) {
aSourceFile = aSourceMapConsumer.file;
}
var sourceRoot = this._sourceRoot;
// Make "aSourceFile" relative if an absolute Url is passed.
if (sourceRoot) {
aSourceFile = util.relative(sourceRoot, aSourceFile);
}
// Applying the SourceMap can add and remove items from the sources and
// the names array.
var newSources = new ArraySet();
@ -1180,12 +1097,13 @@ define('source-map/source-map-generator', ['require', 'exports', 'module' , 'so
// Find mappings for the "aSourceFile"
this._mappings.forEach(function (mapping) {
if (mapping.source === aSourceFile && mapping.originalLine) {
if (mapping.source === aSourceFile && mapping.original) {
// Check if it can be mapped by the source map, then update the mapping.
var original = aSourceMapConsumer.originalPositionFor({
line: mapping.originalLine,
column: mapping.originalColumn
line: mapping.original.line,
column: mapping.original.column
});
if (original.source !== null) {
// Copy mapping
if (sourceRoot) {
@ -1193,8 +1111,8 @@ define('source-map/source-map-generator', ['require', 'exports', 'module' , 'so
} else {
mapping.source = original.source;
}
mapping.originalLine = original.line;
mapping.originalColumn = original.column;
mapping.original.line = original.line;
mapping.original.column = original.column;
if (original.name !== null && mapping.name !== null) {
// Only use the identifier name if it's an identifier
// in both SourceMaps
@ -1262,6 +1180,24 @@ define('source-map/source-map-generator', ['require', 'exports', 'module' , 'so
}
};
function cmpLocation(loc1, loc2) {
var cmp = (loc1 && loc1.line) - (loc2 && loc2.line);
return cmp ? cmp : (loc1 && loc1.column) - (loc2 && loc2.column);
}
function strcmp(str1, str2) {
str1 = str1 || '';
str2 = str2 || '';
return (str1 > str2) - (str1 < str2);
}
function cmpMapping(mappingA, mappingB) {
return cmpLocation(mappingA.generated, mappingB.generated) ||
cmpLocation(mappingA.original, mappingB.original) ||
strcmp(mappingA.source, mappingB.source) ||
strcmp(mappingA.name, mappingB.name);
}
/**
* Serialize the accumulated mappings in to the stream of base 64 VLQs
* specified by the source map format.
@ -1282,44 +1218,44 @@ define('source-map/source-map-generator', ['require', 'exports', 'module' , 'so
// 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(util.compareByGeneratedPositions);
this._mappings.sort(cmpMapping);
for (var i = 0, len = this._mappings.length; i < len; i++) {
mapping = this._mappings[i];
if (mapping.generatedLine !== previousGeneratedLine) {
if (mapping.generated.line !== previousGeneratedLine) {
previousGeneratedColumn = 0;
while (mapping.generatedLine !== previousGeneratedLine) {
while (mapping.generated.line !== previousGeneratedLine) {
result += ';';
previousGeneratedLine++;
}
}
else {
if (i > 0) {
if (!util.compareByGeneratedPositions(mapping, this._mappings[i - 1])) {
if (!cmpMapping(mapping, this._mappings[i - 1])) {
continue;
}
result += ',';
}
}
result += base64VLQ.encode(mapping.generatedColumn
result += base64VLQ.encode(mapping.generated.column
- previousGeneratedColumn);
previousGeneratedColumn = mapping.generatedColumn;
previousGeneratedColumn = mapping.generated.column;
if (mapping.source) {
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.originalLine - 1
result += base64VLQ.encode(mapping.original.line - 1
- previousOriginalLine);
previousOriginalLine = mapping.originalLine - 1;
previousOriginalLine = mapping.original.line - 1;
result += base64VLQ.encode(mapping.originalColumn
result += base64VLQ.encode(mapping.original.column
- previousOriginalColumn);
previousOriginalColumn = mapping.originalColumn;
previousOriginalColumn = mapping.original.column;
if (mapping.name) {
result += base64VLQ.encode(this._names.indexOf(mapping.name)
@ -1332,20 +1268,6 @@ define('source-map/source-map-generator', ['require', 'exports', 'module' , 'so
return result;
};
SourceMapGenerator.prototype._generateSourcesContent =
function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
return aSources.map(function (source) {
if (aSourceRoot) {
source = util.relative(aSourceRoot, source);
}
var key = util.toSetString(source);
return Object.prototype.hasOwnProperty.call(this._sourcesContents,
key)
? this._sourcesContents[key]
: null;
}, this);
};
/**
* Externalize the source map.
*/
@ -1362,9 +1284,16 @@ define('source-map/source-map-generator', ['require', 'exports', 'module' , 'so
map.sourceRoot = this._sourceRoot;
}
if (this._sourcesContents) {
map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
map.sourcesContent = map.sources.map(function (source) {
if (map.sourceRoot) {
source = util.relative(map.sourceRoot, source);
}
return Object.prototype.hasOwnProperty.call(
this._sourcesContents, util.toSetString(source))
? this._sourcesContents[util.toSetString(source)]
: null;
}, this);
}
return map;
};
@ -1571,9 +1500,7 @@ define('source-map/source-node', ['require', 'exports', 'module' , 'source-map/
* @param aFn The traversal function.
*/
SourceNode.prototype.walk = function SourceNode_walk(aFn) {
var chunk;
for (var i = 0, len = this.children.length; i < len; i++) {
chunk = this.children[i];
this.children.forEach(function (chunk) {
if (chunk instanceof SourceNode) {
chunk.walk(aFn);
}
@ -1585,7 +1512,7 @@ define('source-map/source-node', ['require', 'exports', 'module' , 'source-map/
name: this.name });
}
}
}
}, this);
};
/**
@ -1651,16 +1578,14 @@ define('source-map/source-node', ['require', 'exports', 'module' , 'source-map/
*/
SourceNode.prototype.walkSourceContents =
function SourceNode_walkSourceContents(aFn) {
for (var i = 0, len = this.children.length; i < len; i++) {
if (this.children[i] instanceof SourceNode) {
this.children[i].walkSourceContents(aFn);
}
}
var sources = Object.keys(this.sourceContents);
for (var i = 0, len = sources.length; i < len; i++) {
aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
this.children.forEach(function (chunk) {
if (chunk instanceof SourceNode) {
chunk.walkSourceContents(aFn);
}
}, this);
Object.keys(this.sourceContents).forEach(function (sourceFileKey) {
aFn(util.fromSetString(sourceFileKey), this.sourceContents[sourceFileKey]);
}, this);
};
/**

View File

@ -214,8 +214,7 @@ define('test/source-map/util', ['require', 'exports', 'module' , 'lib/source-ma
expectedMap.sourceRoot,
"sourceRoot mismatch: " +
actualMap.sourceRoot + " != " + expectedMap.sourceRoot);
assert.equal(actualMap.mappings, expectedMap.mappings,
"mappings mismatch:\nActual: " + actualMap.mappings + "\nExpected: " + expectedMap.mappings);
assert.equal(actualMap.mappings, expectedMap.mappings, "mappings mismatch");
if (actualMap.sourcesContent) {
assert.equal(actualMap.sourcesContent.length,
expectedMap.sourcesContent.length,
@ -344,93 +343,6 @@ define('lib/source-map/util', ['require', 'exports', 'module' , ], function(requ
}
exports.relative = relative;
function strcmp(aStr1, aStr2) {
var s1 = aStr1 || "";
var s2 = aStr2 || "";
return (s1 > s2) - (s1 < s2);
}
/**
* Comparator between two mappings where the original positions are compared.
*
* Optionally pass in `true` as `onlyCompareGenerated` to consider two
* mappings with the same original source/line/column, but different generated
* line and column the same. Useful when searching for a mapping with a
* stubbed out mapping.
*/
function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
var cmp;
cmp = strcmp(mappingA.source, mappingB.source);
if (cmp) {
return cmp;
}
cmp = mappingA.originalLine - mappingB.originalLine;
if (cmp) {
return cmp;
}
cmp = mappingA.originalColumn - mappingB.originalColumn;
if (cmp || onlyCompareOriginal) {
return cmp;
}
cmp = strcmp(mappingA.name, mappingB.name);
if (cmp) {
return cmp;
}
cmp = mappingA.generatedLine - mappingB.generatedLine;
if (cmp) {
return cmp;
}
return mappingA.generatedColumn - mappingB.generatedColumn;
};
exports.compareByOriginalPositions = compareByOriginalPositions;
/**
* Comparator between two mappings where the generated positions are
* compared.
*
* Optionally pass in `true` as `onlyCompareGenerated` to consider two
* mappings with the same generated line and column, but different
* source/name/original line and column the same. Useful when searching for a
* mapping with a stubbed out mapping.
*/
function compareByGeneratedPositions(mappingA, mappingB, onlyCompareGenerated) {
var cmp;
cmp = mappingA.generatedLine - mappingB.generatedLine;
if (cmp) {
return cmp;
}
cmp = mappingA.generatedColumn - mappingB.generatedColumn;
if (cmp || onlyCompareGenerated) {
return cmp;
}
cmp = strcmp(mappingA.source, mappingB.source);
if (cmp) {
return cmp;
}
cmp = mappingA.originalLine - mappingB.originalLine;
if (cmp) {
return cmp;
}
cmp = mappingA.originalColumn - mappingB.originalColumn;
if (cmp) {
return cmp;
}
return strcmp(mappingA.name, mappingB.name);
};
exports.compareByGeneratedPositions = compareByGeneratedPositions;
});
/* -*- Mode: js; js-indent-level: 2; -*- */
/*

View File

@ -393,66 +393,6 @@ define("test/source-map/test-source-map-consumer", ["require", "exports", "modul
assert.equal(pos.column, 5);
};
exports['test SourceMapConsumer.fromSourceMap'] = function (assert, util) {
var smg = new SourceMapGenerator({
sourceRoot: 'http://example.com/',
file: 'foo.js'
});
smg.addMapping({
original: { line: 1, column: 1 },
generated: { line: 2, column: 2 },
source: 'bar.js'
});
smg.addMapping({
original: { line: 2, column: 2 },
generated: { line: 4, column: 4 },
source: 'baz.js',
name: 'dirtMcGirt'
});
smg.setSourceContent('baz.js', 'baz.js content');
var smc = SourceMapConsumer.fromSourceMap(smg);
assert.equal(smc.file, 'foo.js');
assert.equal(smc.sourceRoot, 'http://example.com/');
assert.equal(smc.sources.length, 2);
assert.equal(smc.sources[0], 'http://example.com/bar.js');
assert.equal(smc.sources[1], 'http://example.com/baz.js');
assert.equal(smc.sourceContentFor('baz.js'), 'baz.js content');
var pos = smc.originalPositionFor({
line: 2,
column: 2
});
assert.equal(pos.line, 1);
assert.equal(pos.column, 1);
assert.equal(pos.source, 'http://example.com/bar.js');
assert.equal(pos.name, null);
pos = smc.generatedPositionFor({
line: 1,
column: 1,
source: 'http://example.com/bar.js'
});
assert.equal(pos.line, 2);
assert.equal(pos.column, 2);
pos = smc.originalPositionFor({
line: 4,
column: 4
});
assert.equal(pos.line, 2);
assert.equal(pos.column, 2);
assert.equal(pos.source, 'http://example.com/baz.js');
assert.equal(pos.name, 'dirtMcGirt');
pos = smc.generatedPositionFor({
line: 2,
column: 2,
source: 'http://example.com/baz.js'
});
assert.equal(pos.line, 4);
assert.equal(pos.column, 4);
};
});
function run_test() {
runSourceMapTests('test/source-map/test-source-map-consumer', do_throw);

View File

@ -262,17 +262,11 @@ define("test/source-map/test-source-node", ["require", "exports", "module"], fun
exports['test .fromStringWithSourceMap() merging duplicate mappings'] = function (assert, util) {
var input = new SourceNode(null, null, null, [
new SourceNode(1, 0, "a.js", "(function"),
new SourceNode(1, 0, "a.js", "() {\n"),
" ",
new SourceNode(1, 0, "a.js", "var Test = "),
new SourceNode(1, 0, "b.js", "{};\n"),
new SourceNode(2, 0, "b.js", "Test"),
new SourceNode(2, 0, "b.js", ".A", "A"),
new SourceNode(2, 20, "b.js", " = { value: 1234 };\n", "A"),
new SourceNode(1, 0, "a.js", "(function"), new SourceNode(1, 0, "a.js", "() {\n"),
" ", new SourceNode(1, 0, "a.js", "var Test = "), new SourceNode(1, 0, "b.js", "{};\n"),
new SourceNode(2, 0, "b.js", "Test"), new SourceNode(2, 0, "b.js", ".A", "A"), new SourceNode(2, 20, "b.js", " = { value: 1234 };\n", "A"),
"}());\n",
"/* Generated Source */"
]);
"/* Generated Source */"]);
input = input.toStringWithSourceMap({
file: 'foo.js'
});