Modified: trunk/LayoutTests/inspector/debugger/compiler-source-mapping.html (95523 => 95524)
--- trunk/LayoutTests/inspector/debugger/compiler-source-mapping.html 2011-09-20 09:41:16 UTC (rev 95523)
+++ trunk/LayoutTests/inspector/debugger/compiler-source-mapping.html 2011-09-20 10:22:59 UTC (rev 95524)
@@ -14,31 +14,52 @@
InspectorTest.assertEquals(sourceColumnNumber, sourceLocation.columnNumber);
}
+ function checkReverseMapping(compiledLineNumber, compiledColumnNumber, sourceURL, sourceLineNumber, mapping)
+ {
+ var compiledLocation = mapping.sourceLocationToCompiledLocation(sourceURL, sourceLineNumber);
+ InspectorTest.assertEquals(compiledLineNumber, compiledLocation.lineNumber);
+ InspectorTest.assertEquals(compiledColumnNumber, compiledLocation.columnNumber);
+ }
+
InspectorTest.runTestSuite([
function testSimpleMapping(next)
{
- // example.js:
- // 0 1 2 3
- // 012345678901234567890123456789012345
- // function add(variable_x, variable_y)
- // {
- // return variable_x + variable_y;
- // }
- // example-compiled.js:
- // 0 1 2 3
- // 012345678901234567890123456789012345
- // function add(a,b){return a+b};
+ /*
+ example.js:
+ 0 1 2 3
+ 012345678901234567890123456789012345
+ function add(variable_x, variable_y)
+ {
+ return variable_x + variable_y;
+ }
+
+ var global = "foo";
+ ----------------------------------------
+ example-compiled.js:
+ 0 1 2 3
+ 012345678901234567890123456789012345
+ function add(a,b){return a+b}var global="foo";
+ */
var mappingPayload = {
- "mappings":"AAASA,QAAAA,IAAG,CAACC,CAAD,CAAaC,CAAb,CACZ,CACI,MAAOD,EAAP,CAAoBC,CADxB;",
+ "mappings":"AAASA,QAAAA,IAAG,CAACC,CAAD,CAAaC,CAAb,CACZ,CACI,MAAOD,EAAP,CAAoBC,CADxB,CAIA,IAAIC,OAAS;",
"sources":["example.js"]
};
var mapping = new WebInspector.ClosureCompilerSourceMapping(mappingPayload);
+
checkMapping(0, 9, "example.js", 0, 9, mapping);
checkMapping(0, 13, "example.js", 0, 13, mapping);
checkMapping(0, 15, "example.js", 0, 25, mapping);
checkMapping(0, 18, "example.js", 2, 4, mapping);
checkMapping(0, 25, "example.js", 2, 11, mapping);
checkMapping(0, 27, "example.js", 2, 24, mapping);
+
+ checkReverseMapping(0, 0, "example.js", 0, mapping);
+ checkReverseMapping(0, 17, "example.js", 1, mapping);
+ checkReverseMapping(0, 18, "example.js", 2, mapping);
+ checkReverseMapping(0, 29, "example.js", 4, mapping);
+ checkReverseMapping(0, 29, "example.js", 5, mapping);
+ InspectorTest.assertTrue(!mapping.sourceLocationToCompiledLocation("example.js", 6));
+
next();
}
]);
Modified: trunk/Source/WebCore/inspector/front-end/CompilerSourceMapping.js (95523 => 95524)
--- trunk/Source/WebCore/inspector/front-end/CompilerSourceMapping.js 2011-09-20 09:41:16 UTC (rev 95523)
+++ trunk/Source/WebCore/inspector/front-end/CompilerSourceMapping.js 2011-09-20 10:22:59 UTC (rev 95524)
@@ -68,19 +68,28 @@
}
this._sources = payload.sources;
- this._mappings = this._parsePayload(payload);
+ this._mappings = [];
+ this._reverseMappingsBySourceURL = {};
+ for (var i = 0; i < this._sources.length; ++i)
+ this._reverseMappingsBySourceURL[this._sources[i]] = [];
+ this._parseMappings(payload.mappings);
}
WebInspector.ClosureCompilerSourceMapping.prototype = {
compiledLocationToSourceLocation: function(lineNumber, columnNumber)
{
var mapping = this._findMapping(lineNumber, columnNumber);
- var sourceURL = this._sources[mapping[2]];
- return { sourceURL: sourceURL, lineNumber: mapping[3], columnNumber: mapping[4] };
+ return { sourceURL: mapping[2], lineNumber: mapping[3], columnNumber: mapping[4] };
},
- sourceLocationToCompiledLocation: function(sourceURL, lineNumber, columnNumber)
+ sourceLocationToCompiledLocation: function(sourceURL, lineNumber)
{
+ var mappings = this._reverseMappingsBySourceURL[sourceURL];
+ for ( ; lineNumber < mappings.length; ++lineNumber) {
+ var mapping = mappings[lineNumber];
+ if (mapping)
+ return { lineNumber: mapping[0], columnNumber: mapping[1] };
+ }
},
sources: function()
@@ -106,10 +115,9 @@
return this._mappings[first];
},
- _parsePayload: function(payload)
+ _parseMappings: function(mappingsPayload)
{
- var mappings = [];
- var stringCharIterator = new WebInspector.ClosureCompilerSourceMapping.StringCharIterator(payload.mappings);
+ var stringCharIterator = new WebInspector.ClosureCompilerSourceMapping.StringCharIterator(mappingsPayload);
var lineNumber = 0;
var columnNumber = 0;
@@ -117,25 +125,34 @@
var sourceLineNumber = 0;
var sourceColumnNumber = 0;
var nameIndex = 0;
+
+ var sourceURL = this._sources[0];
+ var reverseMappings = this._reverseMappingsBySourceURL[sourceURL];
+
do {
columnNumber += this._decodeVLQ(stringCharIterator);
if (this._isSeparator(stringCharIterator.peek()))
continue;
- sourceIndex += this._decodeVLQ(stringCharIterator);
+ var sourceIndexDelta = this._decodeVLQ(stringCharIterator);
+ if (sourceIndexDelta) {
+ sourceIndex += sourceIndexDelta;
+ sourceURL = this._sources[sourceIndex];
+ reverseMappings = this._reverseMappingsBySourceURL[sourceURL];
+ }
sourceLineNumber += this._decodeVLQ(stringCharIterator);
sourceColumnNumber += this._decodeVLQ(stringCharIterator);
- var mapping = [lineNumber, columnNumber, sourceIndex, sourceLineNumber, sourceColumnNumber];
- if (!this._isSeparator(stringCharIterator.peek())) {
+ if (!this._isSeparator(stringCharIterator.peek()))
nameIndex += this._decodeVLQ(stringCharIterator);
- mapping.push(nameIndex);
- }
- mappings.push(mapping);
+
+ this._mappings.push([lineNumber, columnNumber, sourceURL, sourceLineNumber, sourceColumnNumber]);
+ if (!reverseMappings[sourceLineNumber])
+ reverseMappings[sourceLineNumber] = [lineNumber, columnNumber];
+
if (stringCharIterator.next() === ";") {
lineNumber += 1;
columnNumber = 0;
}
} while(stringCharIterator.hasNext());
- return mappings;
},
_isSeparator: function(char)