Changeset 86443 in webkit
- Timestamp:
- May 13, 2011 10:25:57 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r86442 r86443 1 2011-05-05 Pavel Podivilov <podivilov@chromium.org> 2 3 Reviewed by Yury Semikhatsky. 4 5 Web Inspector: fix source mapping for formatted scripts. 6 https://bugs.webkit.org/show_bug.cgi?id=60263 7 8 * inspector/debugger/resources/obfuscated.js: 9 (formatted1): 10 (formatted2): 11 * inspector/debugger/script-formatter.html: 12 1 13 2011-05-13 Adam Roben <aroben@apple.com> 2 14 -
trunk/LayoutTests/inspector/debugger/resources/obfuscated.js
r84625 r86443 1 function formatted1() 2 { 3 var variable1 = 0; 4 } 5 1 6 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= 2 7 {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) 3 8 {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); 4 9 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){} 10 11 function formatted2() 12 { 13 var variable2 = 0; 14 } -
trunk/LayoutTests/inspector/debugger/script-formatter.html
r85321 r86443 45 45 function testSourceMapping(next) 46 46 { 47 worker.onmessage = InspectorTest.safeWrap(function(event) 47 var formatter = new WebInspector.ScriptFormatter(); 48 49 InspectorTest.showScriptSource("obfuscated.js", didShowScriptSource); 50 function didShowScriptSource(sourceFrame) 51 { 52 formatter.formatContent("text/javascript", sourceFrame._content, didFormatContent); 53 } 54 55 function didFormatContent(content, mapping) 48 56 { 49 57 var source = WebInspector.panels.scripts.visibleView._content; 50 var formattedSource = event.data.content; 51 var mapping = event.data.mapping; 58 var formattedSource = content; 52 59 53 60 function testMapping(string) 54 61 { 55 var position = source.indexOf(string);56 var index = mapping.original.upperBound(position) - 1;57 var delta = position - mapping.original[index];58 var formattedPosition = Math.min(mapping.formatted[index] + delta, mapping.formatted[index + 1]);59 InspectorTest.assertEquals( string, formattedSource.substr(formattedPosition, string.length));62 var originalLocation = WebInspector.ScriptFormatter.positionToLocation(source.lineEndings(), source.indexOf(string)); 63 var formattedLocation = mapping.originalToFormatted(originalLocation); 64 var formattedPosition = WebInspector.ScriptFormatter.locationToPosition(formattedSource.lineEndings(), formattedLocation); 65 var expectedFormattedPosition = formattedSource.indexOf(string); 66 InspectorTest.assertEquals(expectedFormattedPosition, formattedPosition); 60 67 } 68 69 testMapping("function"); 70 testMapping("formatted1"); 71 testMapping("variable1"); 61 72 62 73 testMapping("onmessage"); … … 66 77 testMapping("importScripts"); 67 78 79 testMapping("formatted2"); 80 testMapping("variable2"); 81 68 82 next(); 69 });70 71 worker.onerror = function(event)72 {73 InspectorTest.addResult("Error in worker: " + event.data);74 next();75 };76 77 InspectorTest.showScriptSource("obfuscated.js", didShowScriptSource);78 79 function didShowScriptSource(sourceFrame)80 {81 worker.postMessage({ mimeType: "text/javascript", content: sourceFrame._content });82 83 } 83 84 }, -
trunk/Source/WebCore/ChangeLog
r86442 r86443 1 2011-05-05 Pavel Podivilov <podivilov@chromium.org> 2 3 Reviewed by Yury Semikhatsky. 4 5 Web Inspector: fix source mapping for formatted scripts. 6 https://bugs.webkit.org/show_bug.cgi?id=60263 7 8 Source mapping is broken for script chunks that are already formatted at the beginning 9 and at the end of the script (see script-formatter.html). 10 11 * inspector/front-end/ScriptFormatter.js: 12 (WebInspector.ScriptFormatter.prototype._didFormatContent): 13 (WebInspector.FormattedSourceMapping): 14 (WebInspector.FormattedSourceMapping.prototype.originalToFormatted): 15 (WebInspector.FormattedSourceMapping.prototype.formattedToOriginal): 16 (WebInspector.FormattedSourceMapping.prototype._convertPosition): 17 * inspector/front-end/ScriptFormatterWorker.js: 18 (onmessage): 19 (HTMLScriptFormatter.prototype.format): 20 * inspector/front-end/SourceFile.js: 21 (WebInspector.FormattedSourceFile.prototype._didRequestContent): 22 (WebInspector.SourceMappingForFormattedSourceFile): 23 (WebInspector.SourceMappingForFormattedSourceFile.prototype.scriptLocationToSourceLine): 24 (WebInspector.SourceMappingForFormattedSourceFile.prototype.sourceLineToScriptLocation): 25 1 26 2011-05-13 Adam Roben <aroben@apple.com> 2 27 -
trunk/Source/WebCore/inspector/front-end/ScriptFormatter.js
r84625 r86443 42 42 } 43 43 44 WebInspector.ScriptFormatter.lineToPosition = function(lineEndings, lineNumber)45 {46 return this.locationToPosition(lineEndings, { lineNumber: lineNumber, columnNumber: 0 });47 }48 49 44 WebInspector.ScriptFormatter.positionToLocation = function(lineEndings, position) 50 45 { … … 70 65 { 71 66 var task = this._tasks.shift(); 72 event.data.mapping.originalLineEndings = task.data.content.lineEndings(); 73 task.callback(event.data.content, event.data.mapping); 67 var originalContent = task.data.content; 68 var formattedContent = event.data.content; 69 var sourceMapping = new WebInspector.FormattedSourceMapping(originalContent.lineEndings(), formattedContent.lineEndings(), event.data.mapping); 70 task.callback(formattedContent, sourceMapping); 74 71 } 75 72 } 73 74 WebInspector.FormattedSourceMapping = function(originalLineEndings, formattedLineEndings, mapping) 75 { 76 this._originalLineEndings = originalLineEndings; 77 this._formattedLineEndings = formattedLineEndings; 78 this._mapping = mapping; 79 } 80 81 WebInspector.FormattedSourceMapping.prototype = { 82 originalToFormatted: function(location) 83 { 84 var originalPosition = WebInspector.ScriptFormatter.locationToPosition(this._originalLineEndings, location); 85 var formattedPosition = this._convertPosition(this._mapping.original, this._mapping.formatted, originalPosition); 86 return WebInspector.ScriptFormatter.positionToLocation(this._formattedLineEndings, formattedPosition); 87 }, 88 89 formattedToOriginal: function(location) 90 { 91 var formattedPosition = WebInspector.ScriptFormatter.locationToPosition(this._formattedLineEndings, location); 92 var originalPosition = this._convertPosition(this._mapping.formatted, this._mapping.original, formattedPosition); 93 return WebInspector.ScriptFormatter.positionToLocation(this._originalLineEndings, originalPosition); 94 }, 95 96 _convertPosition: function(positions1, positions2, position) 97 { 98 var index = positions1.upperBound(position) - 1; 99 var convertedPosition = positions2[index] + position - positions1[index]; 100 if (index < positions2.length - 1 && convertedPosition > positions2[index + 1]) 101 convertedPosition = positions2[index + 1]; 102 return convertedPosition; 103 } 104 } -
trunk/Source/WebCore/inspector/front-end/ScriptFormatterWorker.js
r84625 r86443 35 35 result = formatter.format(event.data.content); 36 36 } else { 37 result.mapping = { original: [ ], formatted: [] };37 result.mapping = { original: [0], formatted: [0] }; 38 38 result.content = formatScript(event.data.content, result.mapping, 0, 0); 39 39 } … … 71 71 this._content = content; 72 72 this._formattedContent = ""; 73 this._mapping = { original: [ ], formatted: [] };73 this._mapping = { original: [0], formatted: [0] }; 74 74 this._position = 0; 75 75 -
trunk/Source/WebCore/inspector/front-end/SourceFile.js
r84629 r86443 255 255 function didFormatContent(formattedText, mapping) 256 256 { 257 this._mapping = new WebInspector. FormattedSourceMapping(this._scripts, mapping.originalLineEndings, formattedText.lineEndings(), mapping);257 this._mapping = new WebInspector.SourceMappingForFormattedSourceFile(this._scripts, mapping); 258 258 WebInspector.SourceFile.prototype._didRequestContent.call(this, mimeType, formattedText); 259 259 } … … 294 294 } 295 295 296 WebInspector. FormattedSourceMapping = function(scripts, originalLineEndings, formattedLineEndings, mapping)296 WebInspector.SourceMappingForFormattedSourceFile = function(scripts, mapping) 297 297 { 298 298 WebInspector.SourceMapping.call(this, scripts); 299 this._originalLineEndings = originalLineEndings;300 this._formattedLineEndings = formattedLineEndings;301 299 this._mapping = mapping; 302 300 } 303 301 304 WebInspector. FormattedSourceMapping.prototype = {302 WebInspector.SourceMappingForFormattedSourceFile.prototype = { 305 303 scriptLocationToSourceLine: function(location) 306 304 { 307 var originalPosition = WebInspector.ScriptFormatter.locationToPosition(this._originalLineEndings, location); 308 var formattedPosition = this._convertPosition(this._mapping.original, this._mapping.formatted, originalPosition); 309 return WebInspector.ScriptFormatter.positionToLocation(this._formattedLineEndings, formattedPosition).lineNumber; 305 return this._mapping.originalToFormatted(location).lineNumber; 310 306 }, 311 307 312 308 sourceLineToScriptLocation: function(lineNumber) 313 309 { 314 var formattedPosition = WebInspector.ScriptFormatter.lineToPosition(this._formattedLineEndings, lineNumber); 315 var originalPosition = this._convertPosition(this._mapping.formatted, this._mapping.original, formattedPosition); 316 var originalLocation = WebInspector.ScriptFormatter.positionToLocation(this._originalLineEndings, originalPosition); 310 var originalLocation = this._mapping.formattedToOriginal({ lineNumber: lineNumber, columnNumber: 0 }); 317 311 return WebInspector.SourceMapping.prototype._sourceLocationToScriptLocation.call(this, originalLocation.lineNumber, originalLocation.columnNumber); 318 },319 320 _convertPosition: function(positions1, positions2, position)321 {322 var index = positions1.upperBound(position) - 1;323 var delta = position - positions1[index];324 return Math.min(positions2[index] + delta, positions2[index + 1]);325 312 } 326 313 } 327 314 328 WebInspector. FormattedSourceMapping.prototype.__proto__ = WebInspector.SourceMapping.prototype;315 WebInspector.SourceMappingForFormattedSourceFile.prototype.__proto__ = WebInspector.SourceMapping.prototype;
Note: See TracChangeset
for help on using the changeset viewer.