Changeset 83748 in webkit
- Timestamp:
- Apr 13, 2011 9:45:42 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r83744 r83748 1 2011-04-12 Pavel Podivilov <podivilov@chromium.org> 2 3 Reviewed by Pavel Feldman. 4 5 Web Inspector: fix source mapping for deobfuscated scripts. 6 https://bugs.webkit.org/show_bug.cgi?id=58231 7 8 * inspector/debugger/resources/obfuscated.js: Added. 9 * inspector/debugger/script-formatter-expected.txt: 10 * inspector/debugger/script-formatter.html: 11 1 12 2011-04-13 Philippe Normand <pnormand@igalia.com> 2 13 -
trunk/LayoutTests/inspector/debugger/script-formatter-expected.txt
r83284 r83748 1 1 Tests the script formatting functionality. 2 2 3 Debugger was enabled. 3 4 4 5 Running: testScriptFormatterWorker 5 6 7 Running: testSourceMapping 8 Debugger was disabled. 9 -
trunk/LayoutTests/inspector/debugger/script-formatter.html
r83284 r83748 3 3 <script src="../../http/tests/inspector/inspector-test.js"></script> 4 4 <script src="../../http/tests/inspector/debugger-test.js"></script> 5 <script src="resources/obfuscated.js"></script> 5 6 6 7 <script> … … 8 9 var test = function() 9 10 { 10 InspectorTest.runTestSuite([ 11 var worker = new Worker("ScriptFormatterWorker.js"); 12 13 InspectorTest.runDebuggerTestSuite([ 11 14 function testScriptFormatterWorker(next) 12 15 { 13 var worker = new Worker("ScriptFormatterWorker.js");14 15 16 worker.onmessage = InspectorTest.safeWrap(function(event) 16 17 { 17 18 InspectorTest.assertEquals("var x = 0;", event.data.formattedSource); 18 InspectorTest.completeTest();19 next(); 19 20 }); 20 21 … … 22 23 { 23 24 InspectorTest.addResult("Error in worker: " + event.data); 24 InspectorTest.completeTest();25 next(); 25 26 }; 26 27 27 28 worker.postMessage("var x=0"); 29 }, 30 31 function testSourceMapping(next) 32 { 33 worker.onmessage = InspectorTest.safeWrap(function(event) 34 { 35 var source = WebInspector.panels.scripts.visibleView._content; 36 var formattedSource = event.data.formattedSource; 37 var mapping = event.data.mapping; 38 39 function testMapping(string) 40 { 41 var position = source.indexOf(string); 42 var formattedPosition = mapping.formatted[mapping.original.upperBound(position - 1)]; 43 InspectorTest.assertEquals(string, formattedSource.substr(formattedPosition, string.length)); 44 } 45 46 testMapping("onmessage"); 47 testMapping("indent_start"); 48 testMapping("function require"); 49 testMapping("var regexp"); 50 testMapping("importScripts"); 51 52 next(); 53 }); 54 55 worker.onerror = function(event) 56 { 57 InspectorTest.addResult("Error in worker: " + event.data); 58 next(); 59 }; 60 61 InspectorTest.showScriptSource("obfuscated.js", didShowScriptSource); 62 63 function didShowScriptSource(sourceFrame) 64 { 65 worker.postMessage(sourceFrame._content); 66 } 28 67 } 29 68 ]); -
trunk/Source/WebCore/ChangeLog
r83747 r83748 1 2011-04-12 Pavel Podivilov <podivilov@chromium.org> 2 3 Reviewed by Pavel Feldman. 4 5 Web Inspector: fix source mapping for de-obfuscated scripts. 6 https://bugs.webkit.org/show_bug.cgi?id=58231 7 8 * inspector/front-end/ScriptFormatterWorker.js: 9 (buildMapping): 10 * inspector/front-end/SourceFile.js: 11 (WebInspector.SourceMapping): 12 (WebInspector.SourceMapping.prototype.sourceLineToScriptLocation): 13 (WebInspector.SourceMapping.prototype._sourceLocationToScriptLocation): 14 (WebInspector): 15 (WebInspector.FormattedSourceMapping): 16 (WebInspector.FormattedSourceMapping.prototype.scriptLocationToSourceLine): 17 (WebInspector.FormattedSourceMapping.prototype.sourceLineToScriptLocation): 18 1 19 2011-04-13 Mario Sanchez Prada <msanchez@igalia.com> 2 20 -
trunk/Source/WebCore/inspector/front-end/ScriptFormatterWorker.js
r83284 r83748 51 51 { 52 52 var mapping = { original: [], formatted: [] }; 53 var last FormattedPosition = 0;54 var regexp = / \b(?:function|var|const|try|catch|throw|new|switch|break|continue|if|for|while|do|return|with|null|undefined)\b/g;53 var lastPosition = 0; 54 var regexp = /(^|[^\\])\b((?=\D)[\$\.\w]+)\b/g; 55 55 while (true) { 56 var match = regexp.exec( source);56 var match = regexp.exec(formattedSource); 57 57 if (!match) 58 58 break; 59 var formattedPosition = formattedSource.indexOf(match[0], lastFormattedPosition); 60 mapping.original.push(match.index); 61 mapping.formatted.push(formattedPosition); 62 lastFormattedPosition = formattedPosition + match[0].length; 59 var position = source.indexOf(match[2], lastPosition); 60 if (position === -1) 61 throw "No match found in original source for " + match[2]; 62 mapping.original.push(position); 63 mapping.formatted.push(match.index + match[1].length); 64 lastPosition = position + match[2].length; 63 65 } 64 66 return mapping; -
trunk/Source/WebCore/inspector/front-end/SourceFile.js
r83601 r83748 264 264 WebInspector.FormattedSourceFile.prototype.__proto__ = WebInspector.SourceFile.prototype; 265 265 266 WebInspector.SourceMapping = function(s ortedScripts)266 WebInspector.SourceMapping = function(scripts) 267 267 { 268 this._sortedScripts = sortedScripts; 268 this._sortedScripts = scripts.slice(); 269 this._sortedScripts.sort(function(x, y) { return x.lineOffset - y.lineOffset || x.columnOffset - y.columnOffset; }); 269 270 } 270 271 … … 277 278 sourceLineToScriptLocation: function(lineNumber) 278 279 { 279 var columnNumber = 0; 280 return this._sourceLocationToScriptLocation(lineNumber, 0); 281 }, 282 283 _sourceLocationToScriptLocation: function(lineNumber, columnNumber) 284 { 280 285 var closestScript = this._sortedScripts[0]; 281 286 for (var i = 1; i < this._sortedScripts.length; ++i) { … … 289 294 } 290 295 291 WebInspector.FormattedSourceMapping = function(s ortedScripts, originalText, formattedText, mapping)296 WebInspector.FormattedSourceMapping = function(scripts, originalText, formattedText, mapping) 292 297 { 293 WebInspector.SourceMapping.call(this, s ortedScripts);298 WebInspector.SourceMapping.call(this, scripts); 294 299 this._originalLineEndings = originalText.lineEndings(); 295 300 this._formattedLineEndings = formattedText.lineEndings(); … … 301 306 { 302 307 var originalPosition = WebInspector.ScriptFormatter.locationToPosition(this._originalLineEndings, location); 303 var formattedPosition = this._convertPosition(this._mapping.original, this._mapping.formatted, originalPosition); 308 var index = this._mapping.original.upperBound(originalPosition - 1); 309 var formattedPosition = this._mapping.formatted[index]; 304 310 return WebInspector.ScriptFormatter.positionToLocation(this._formattedLineEndings, formattedPosition).lineNumber; 305 311 }, … … 308 314 { 309 315 var formattedPosition = WebInspector.ScriptFormatter.lineToPosition(this._formattedLineEndings, lineNumber); 310 var originalPosition = this._convertPosition(this._mapping.formatted, this._mapping.original, formattedPosition); 316 var index = this._mapping.formatted.upperBound(formattedPosition - 1); 317 var originalPosition = this._mapping.original[index]; 311 318 var originalLocation = WebInspector.ScriptFormatter.positionToLocation(this._originalLineEndings, originalPosition); 312 return WebInspector.SourceMapping.prototype.sourceLineToScriptLocation.call(this, originalLocation.lineNumber); 313 }, 314 315 _convertPosition: function(positions1, positions2, position) 316 { 317 var index = positions1.upperBound(position); 318 var range1 = positions1[index] - positions1[index - 1]; 319 var range2 = positions2[index] - positions2[index - 1]; 320 var position2 = positions2[index - 1]; 321 if (range1) 322 position2 += Math.round((position - positions1[index - 1]) * range2 / range1); 323 return position2; 319 return WebInspector.SourceMapping.prototype._sourceLocationToScriptLocation.call(this, originalLocation.lineNumber, originalLocation.columnNumber); 324 320 } 325 321 } -
trunk/Source/WebCore/inspector/front-end/SourceFrame.js
r83725 r83748 40 40 41 41 this._textViewer = new WebInspector.TextViewer(this._textModel, WebInspector.platform, this._url, this); 42 this._textViewer.element.addStyleClass("script-view"); 42 43 this._visible = false; 43 44 … … 306 307 307 308 var element = this._textViewer.element; 308 element.addStyleClass("script-view");309 309 if (this._delegate.debuggingSupported()) { 310 310 element.addEventListener("contextmenu", this._contextMenu.bind(this), true);
Note: See TracChangeset
for help on using the changeset viewer.