Title: [87071] trunk
Revision
87071
Author
[email protected]
Date
2011-05-23 06:41:24 -0700 (Mon, 23 May 2011)

Log Message

2011-05-18  Pavel Podivilov  <[email protected]>

        Reviewed by Yury Semikhatsky.

        Web Inspector: source mapping for pretty-printed scripts is sometimes inaccurate after indented comments.
        https://bugs.webkit.org/show_bug.cgi?id=61037

        * http/tests/inspector/inspector-test.js:
        (initialize_InspectorTest):
        * inspector/debugger/resources/obfuscated.js:
        (withComments):
        * inspector/debugger/script-formatter.html:
2011-05-18  Pavel Podivilov  <[email protected]>

        Reviewed by Yury Semikhatsky.

        Web Inspector: source mapping for pretty-printed scripts is sometimes inaccurate after indented comments.
        https://bugs.webkit.org/show_bug.cgi?id=61037

        * inspector/front-end/_javascript_Formatter.js:
        (FormattedContentBuilder.prototype.addToken):
        (FormattedContentBuilder.prototype._addComment):
        (FormattedContentBuilder.prototype._addText):
        (FormattedContentBuilder.prototype._addMappingIfNeeded):

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (87070 => 87071)


--- trunk/LayoutTests/ChangeLog	2011-05-23 13:29:25 UTC (rev 87070)
+++ trunk/LayoutTests/ChangeLog	2011-05-23 13:41:24 UTC (rev 87071)
@@ -1,3 +1,16 @@
+2011-05-18  Pavel Podivilov  <[email protected]>
+
+        Reviewed by Yury Semikhatsky.
+
+        Web Inspector: source mapping for pretty-printed scripts is sometimes inaccurate after indented comments.
+        https://bugs.webkit.org/show_bug.cgi?id=61037
+
+        * http/tests/inspector/inspector-test.js:
+        (initialize_InspectorTest):
+        * inspector/debugger/resources/obfuscated.js:
+        (withComments):
+        * inspector/debugger/script-formatter.html:
+
 2011-05-23  Mike West  <[email protected]>
 
         Reviewed by Yury Semikhatsky.

Modified: trunk/LayoutTests/http/tests/inspector/inspector-test.js (87070 => 87071)


--- trunk/LayoutTests/http/tests/inspector/inspector-test.js	2011-05-23 13:29:25 UTC (rev 87070)
+++ trunk/LayoutTests/http/tests/inspector/inspector-test.js	2011-05-23 13:41:24 UTC (rev 87071)
@@ -235,6 +235,11 @@
     throw new Error(error + " expected <" + expected + "> found <" + found + ">");
 }
 
+InspectorTest.assertTrue = function(found, message)
+{
+    InspectorTest.assertEquals(true, !!found);
+}
+
 InspectorTest.safeWrap = function(func, onexception)
 {
     function result()

Modified: trunk/LayoutTests/inspector/debugger/resources/obfuscated.js (87070 => 87071)


--- trunk/LayoutTests/inspector/debugger/resources/obfuscated.js	2011-05-23 13:29:25 UTC (rev 87070)
+++ trunk/LayoutTests/inspector/debugger/resources/obfuscated.js	2011-05-23 13:41:24 UTC (rev 87071)
@@ -3,6 +3,12 @@
     var variable1 = 0;
 }
 
+function withComments()
+{
+// comment
+    return "functionWithComments";
+}
+
 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);

Modified: trunk/LayoutTests/inspector/debugger/script-formatter.html (87070 => 87071)


--- trunk/LayoutTests/inspector/debugger/script-formatter.html	2011-05-23 13:29:25 UTC (rev 87070)
+++ trunk/LayoutTests/inspector/debugger/script-formatter.html	2011-05-23 13:41:24 UTC (rev 87071)
@@ -59,17 +59,21 @@
 
                 function testMapping(string)
                 {
-                    var originalLocation = WebInspector.ScriptFormatter.positionToLocation(source.lineEndings(), source.indexOf(string));
+                    var originalPosition = source.indexOf(string);
+                    InspectorTest.assertTrue(originalPosition !== -1);
+                    var originalLocation = WebInspector.ScriptFormatter.positionToLocation(source.lineEndings(), originalPosition);
                     var formattedLocation = mapping.originalToFormatted(originalLocation);
                     var formattedPosition = WebInspector.ScriptFormatter.locationToPosition(formattedSource.lineEndings(), formattedLocation);
                     var expectedFormattedPosition = formattedSource.indexOf(string);
-                    InspectorTest.assertEquals(expectedFormattedPosition, formattedPosition);
+                    InspectorTest.assertEquals(expectedFormattedPosition, formattedPosition, "wrong mapping for <" + string + ">");
                 }
 
                 testMapping("function");
                 testMapping("formatted1");
                 testMapping("variable1");
 
+                testMapping("    return \"functionWithComments\"");
+
                 testMapping("onmessage");
                 testMapping("indent_start");
                 testMapping("function require");

Modified: trunk/Source/WebCore/ChangeLog (87070 => 87071)


--- trunk/Source/WebCore/ChangeLog	2011-05-23 13:29:25 UTC (rev 87070)
+++ trunk/Source/WebCore/ChangeLog	2011-05-23 13:41:24 UTC (rev 87071)
@@ -1,3 +1,16 @@
+2011-05-18  Pavel Podivilov  <[email protected]>
+
+        Reviewed by Yury Semikhatsky.
+
+        Web Inspector: source mapping for pretty-printed scripts is sometimes inaccurate after indented comments.
+        https://bugs.webkit.org/show_bug.cgi?id=61037
+
+        * inspector/front-end/_javascript_Formatter.js:
+        (FormattedContentBuilder.prototype.addToken):
+        (FormattedContentBuilder.prototype._addComment):
+        (FormattedContentBuilder.prototype._addText):
+        (FormattedContentBuilder.prototype._addMappingIfNeeded):
+
 2011-05-23  Mike West  <[email protected]>
 
         Reviewed by Yury Semikhatsky.

Modified: trunk/Source/WebCore/inspector/front-end/_javascript_Formatter.js (87070 => 87071)


--- trunk/Source/WebCore/inspector/front-end/_javascript_Formatter.js	2011-05-23 13:29:25 UTC (rev 87070)
+++ trunk/Source/WebCore/inspector/front-end/_javascript_Formatter.js	2011-05-23 13:41:24 UTC (rev 87071)
@@ -64,13 +64,7 @@
             this._needNewLine = false;
         }
 
-        if (token.pos - this._lastOriginalPosition !== this._formattedContentLength - this._lastFormattedPosition) {
-            this._mapping.original.push(this._originalOffset + token.pos);
-            this._lastOriginalPosition = token.pos;
-            this._mapping.formatted.push(this._formattedOffset + this._formattedContentLength);
-            this._lastFormattedPosition = this._formattedContentLength;
-        }
-
+        this._addMappingIfNeeded(token.pos);
         this._addText(this._originalContent.substring(token.pos, token.endPos));
         this._lineNumber = token.endLine;
     },
@@ -122,6 +116,7 @@
         } else
             this.addSpace();
 
+        this._addMappingIfNeeded(comment.pos);
         if (comment.type === "comment1")
             this._addText("//");
         else
@@ -141,6 +136,16 @@
     {
         this._formattedContent.push(text);
         this._formattedContentLength += text.length;
+    },
+
+    _addMappingIfNeeded: function(originalPosition)
+    {
+        if (originalPosition - this._lastOriginalPosition === this._formattedContentLength - this._lastFormattedPosition)
+            return;
+        this._mapping.original.push(this._originalOffset + originalPosition);
+        this._lastOriginalPosition = originalPosition;
+        this._mapping.formatted.push(this._formattedOffset + this._formattedContentLength);
+        this._lastFormattedPosition = this._formattedContentLength;
     }
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to