2011-05-05 Pavel Podivilov <podivilov@chromium.org>

        Reviewed by Yury Semikhatsky.

        Web Inspector: fix source mapping for formatted scripts.
        https://bugs.webkit.org/show_bug.cgi?id=60263

        * inspector/debugger/resources/obfuscated.js:
        (formatted1):
        (formatted2):
        * inspector/debugger/script-formatter.html:
2011-05-05  Pavel Podivilov  <podivilov@chromium.org>

        Reviewed by Yury Semikhatsky.

        Web Inspector: fix source mapping for formatted scripts.
        https://bugs.webkit.org/show_bug.cgi?id=60263

        Source mapping is broken for script chunks that are already formatted at the beginning
        and at the end of the script (see script-formatter.html).

        * inspector/front-end/ScriptFormatter.js:
        (WebInspector.ScriptFormatter.prototype._didFormatContent):
        (WebInspector.FormattedSourceMapping):
        (WebInspector.FormattedSourceMapping.prototype.originalToFormatted):
        (WebInspector.FormattedSourceMapping.prototype.formattedToOriginal):
        (WebInspector.FormattedSourceMapping.prototype._convertPosition):
        * inspector/front-end/ScriptFormatterWorker.js:
        (onmessage):
        (HTMLScriptFormatter.prototype.format):
        * inspector/front-end/SourceFile.js:
        (WebInspector.FormattedSourceFile.prototype._didRequestContent):
        (WebInspector.SourceMappingForFormattedSourceFile):
        (WebInspector.SourceMappingForFormattedSourceFile.prototype.scriptLocationToSourceLine):
        (WebInspector.SourceMappingForFormattedSourceFile.prototype.sourceLineToScriptLocation):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@86443 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 9f9a70a7
2011-05-05 Pavel Podivilov <podivilov@chromium.org>
Reviewed by Yury Semikhatsky.
Web Inspector: fix source mapping for formatted scripts.
https://bugs.webkit.org/show_bug.cgi?id=60263
* inspector/debugger/resources/obfuscated.js:
(formatted1):
(formatted2):
* inspector/debugger/script-formatter.html:
2011-05-13 Adam Roben <aroben@apple.com>
Add a test for windowed plugins inside iframes inside scrolled overflow areas
function formatted1()
{
var variable1 = 0;
}
try{onmessage=function(event){var source=event.data;var formattedSource=beautify(source);var mapping=buildMapping(source,formattedSource);postMessage({formattedSource:formattedSource,mapping:mapping})};function beautify(source){var ast=parse.parse(source);var beautifyOptions=
{indent_level:4,indent_start:0,quote_keys:false,space_colon:false};return process.gen_code(ast,beautifyOptions)}function buildMapping(source,formattedSource){var mapping={original:[],formatted:[]};var lastPosition=0;var regexp=/(^|[^\\])\b((?=\D)[\$\.\w]+)\b/g;while(true)
{var match=regexp.exec(formattedSource);if(!match)break;var position=source.indexOf(match[2],lastPosition);if(position===-1)throw"No match found in original source for "+match[2];mapping.original.push(position);mapping.formatted.push(match.index+match[1].length);
lastPosition=position+match[2].length}return mapping}function require(){return parse}var exports={};importScripts("UglifyJS/parse-js.js");var parse=exports;var exports={};importScripts("UglifyJS/process.js");var process=exports;}catch(e){}
function formatted2()
{
var variable2 = 0;
}
......@@ -44,41 +44,42 @@ var test = function()
function testSourceMapping(next)
{
worker.onmessage = InspectorTest.safeWrap(function(event)
var formatter = new WebInspector.ScriptFormatter();
InspectorTest.showScriptSource("obfuscated.js", didShowScriptSource);
function didShowScriptSource(sourceFrame)
{
formatter.formatContent("text/javascript", sourceFrame._content, didFormatContent);
}
function didFormatContent(content, mapping)
{
var source = WebInspector.panels.scripts.visibleView._content;
var formattedSource = event.data.content;
var mapping = event.data.mapping;
var formattedSource = content;
function testMapping(string)
{
var position = source.indexOf(string);
var index = mapping.original.upperBound(position) - 1;
var delta = position - mapping.original[index];
var formattedPosition = Math.min(mapping.formatted[index] + delta, mapping.formatted[index + 1]);
InspectorTest.assertEquals(string, formattedSource.substr(formattedPosition, string.length));
var originalLocation = WebInspector.ScriptFormatter.positionToLocation(source.lineEndings(), source.indexOf(string));
var formattedLocation = mapping.originalToFormatted(originalLocation);
var formattedPosition = WebInspector.ScriptFormatter.locationToPosition(formattedSource.lineEndings(), formattedLocation);
var expectedFormattedPosition = formattedSource.indexOf(string);
InspectorTest.assertEquals(expectedFormattedPosition, formattedPosition);
}
testMapping("function");
testMapping("formatted1");
testMapping("variable1");
testMapping("onmessage");
testMapping("indent_start");
testMapping("function require");
testMapping("var regexp");
testMapping("importScripts");
next();
});
testMapping("formatted2");
testMapping("variable2");
worker.onerror = function(event)
{
InspectorTest.addResult("Error in worker: " + event.data);
next();
};
InspectorTest.showScriptSource("obfuscated.js", didShowScriptSource);
function didShowScriptSource(sourceFrame)
{
worker.postMessage({ mimeType: "text/javascript", content: sourceFrame._content });
}
},
......
2011-05-05 Pavel Podivilov <podivilov@chromium.org>
Reviewed by Yury Semikhatsky.
Web Inspector: fix source mapping for formatted scripts.
https://bugs.webkit.org/show_bug.cgi?id=60263
Source mapping is broken for script chunks that are already formatted at the beginning
and at the end of the script (see script-formatter.html).
* inspector/front-end/ScriptFormatter.js:
(WebInspector.ScriptFormatter.prototype._didFormatContent):
(WebInspector.FormattedSourceMapping):
(WebInspector.FormattedSourceMapping.prototype.originalToFormatted):
(WebInspector.FormattedSourceMapping.prototype.formattedToOriginal):
(WebInspector.FormattedSourceMapping.prototype._convertPosition):
* inspector/front-end/ScriptFormatterWorker.js:
(onmessage):
(HTMLScriptFormatter.prototype.format):
* inspector/front-end/SourceFile.js:
(WebInspector.FormattedSourceFile.prototype._didRequestContent):
(WebInspector.SourceMappingForFormattedSourceFile):
(WebInspector.SourceMappingForFormattedSourceFile.prototype.scriptLocationToSourceLine):
(WebInspector.SourceMappingForFormattedSourceFile.prototype.sourceLineToScriptLocation):
2011-05-13 Adam Roben <aroben@apple.com>
Tell ScrollView's child Widgets that their frame rects have changed when its own frame rect
......@@ -41,11 +41,6 @@ WebInspector.ScriptFormatter.locationToPosition = function(lineEndings, location
return position + location.columnNumber;
}
WebInspector.ScriptFormatter.lineToPosition = function(lineEndings, lineNumber)
{
return this.locationToPosition(lineEndings, { lineNumber: lineNumber, columnNumber: 0 });
}
WebInspector.ScriptFormatter.positionToLocation = function(lineEndings, position)
{
var location = {};
......@@ -69,7 +64,41 @@ WebInspector.ScriptFormatter.prototype = {
_didFormatContent: function(event)
{
var task = this._tasks.shift();
event.data.mapping.originalLineEndings = task.data.content.lineEndings();
task.callback(event.data.content, event.data.mapping);
var originalContent = task.data.content;
var formattedContent = event.data.content;
var sourceMapping = new WebInspector.FormattedSourceMapping(originalContent.lineEndings(), formattedContent.lineEndings(), event.data.mapping);
task.callback(formattedContent, sourceMapping);
}
}
WebInspector.FormattedSourceMapping = function(originalLineEndings, formattedLineEndings, mapping)
{
this._originalLineEndings = originalLineEndings;
this._formattedLineEndings = formattedLineEndings;
this._mapping = mapping;
}
WebInspector.FormattedSourceMapping.prototype = {
originalToFormatted: function(location)
{
var originalPosition = WebInspector.ScriptFormatter.locationToPosition(this._originalLineEndings, location);
var formattedPosition = this._convertPosition(this._mapping.original, this._mapping.formatted, originalPosition);
return WebInspector.ScriptFormatter.positionToLocation(this._formattedLineEndings, formattedPosition);
},
formattedToOriginal: function(location)
{
var formattedPosition = WebInspector.ScriptFormatter.locationToPosition(this._formattedLineEndings, location);
var originalPosition = this._convertPosition(this._mapping.formatted, this._mapping.original, formattedPosition);
return WebInspector.ScriptFormatter.positionToLocation(this._originalLineEndings, originalPosition);
},
_convertPosition: function(positions1, positions2, position)
{
var index = positions1.upperBound(position) - 1;
var convertedPosition = positions2[index] + position - positions1[index];
if (index < positions2.length - 1 && convertedPosition > positions2[index + 1])
convertedPosition = positions2[index + 1];
return convertedPosition;
}
}
......@@ -34,7 +34,7 @@ onmessage = function(event) {
var formatter = new HTMLScriptFormatter();
result = formatter.format(event.data.content);
} else {
result.mapping = { original: [], formatted: [] };
result.mapping = { original: [0], formatted: [0] };
result.content = formatScript(event.data.content, result.mapping, 0, 0);
}
postMessage(result);
......@@ -70,7 +70,7 @@ HTMLScriptFormatter.prototype = {
this.line = content;
this._content = content;
this._formattedContent = "";
this._mapping = { original: [], formatted: [] };
this._mapping = { original: [0], formatted: [0] };
this._position = 0;
var cursor = 0;
......
......@@ -254,7 +254,7 @@ WebInspector.FormattedSourceFile.prototype = {
{
function didFormatContent(formattedText, mapping)
{
this._mapping = new WebInspector.FormattedSourceMapping(this._scripts, mapping.originalLineEndings, formattedText.lineEndings(), mapping);
this._mapping = new WebInspector.SourceMappingForFormattedSourceFile(this._scripts, mapping);
WebInspector.SourceFile.prototype._didRequestContent.call(this, mimeType, formattedText);
}
this._formatter.formatContent(mimeType, text, didFormatContent.bind(this));
......@@ -293,36 +293,23 @@ WebInspector.SourceMapping.prototype = {
}
}
WebInspector.FormattedSourceMapping = function(scripts, originalLineEndings, formattedLineEndings, mapping)
WebInspector.SourceMappingForFormattedSourceFile = function(scripts, mapping)
{
WebInspector.SourceMapping.call(this, scripts);
this._originalLineEndings = originalLineEndings;
this._formattedLineEndings = formattedLineEndings;
this._mapping = mapping;
}
WebInspector.FormattedSourceMapping.prototype = {
WebInspector.SourceMappingForFormattedSourceFile.prototype = {
scriptLocationToSourceLine: function(location)
{
var originalPosition = WebInspector.ScriptFormatter.locationToPosition(this._originalLineEndings, location);
var formattedPosition = this._convertPosition(this._mapping.original, this._mapping.formatted, originalPosition);
return WebInspector.ScriptFormatter.positionToLocation(this._formattedLineEndings, formattedPosition).lineNumber;
return this._mapping.originalToFormatted(location).lineNumber;
},
sourceLineToScriptLocation: function(lineNumber)
{
var formattedPosition = WebInspector.ScriptFormatter.lineToPosition(this._formattedLineEndings, lineNumber);
var originalPosition = this._convertPosition(this._mapping.formatted, this._mapping.original, formattedPosition);
var originalLocation = WebInspector.ScriptFormatter.positionToLocation(this._originalLineEndings, originalPosition);
var originalLocation = this._mapping.formattedToOriginal({ lineNumber: lineNumber, columnNumber: 0 });
return WebInspector.SourceMapping.prototype._sourceLocationToScriptLocation.call(this, originalLocation.lineNumber, originalLocation.columnNumber);
},
_convertPosition: function(positions1, positions2, position)
{
var index = positions1.upperBound(position) - 1;
var delta = position - positions1[index];
return Math.min(positions2[index] + delta, positions2[index + 1]);
}
}
WebInspector.FormattedSourceMapping.prototype.__proto__ = WebInspector.SourceMapping.prototype;
WebInspector.SourceMappingForFormattedSourceFile.prototype.__proto__ = WebInspector.SourceMapping.prototype;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment