Title: [92051] trunk
Revision
92051
Author
[email protected]
Date
2011-07-30 05:42:56 -0700 (Sat, 30 Jul 2011)

Log Message

Web Inspector: move location conversion functions to SourceFile.
https://bugs.webkit.org/show_bug.cgi?id=65185

Reviewed by Pavel Feldman.

Source/WebCore:

Test: inspector/debugger/source-file.html

* inspector/front-end/DebuggerPresentationModel.js:
(WebInspector.DebuggerPresentationModel.prototype._scriptLocationToUILocation.didCreateSourceMapping):
(WebInspector.DebuggerPresentationModel.prototype._scriptLocationToUILocation):
(WebInspector.DebuggerPresentationModel.prototype._uiLocationToScriptLocation.didCreateSourceMapping):
(WebInspector.DebuggerPresentationModel.prototype._uiLocationToScriptLocation):
* inspector/front-end/SourceFile.js:
(WebInspector.SourceFile.prototype.rawLocationToUILocation):
(WebInspector.SourceFile.prototype.uiLocationToRawLocation):
(WebInspector.SourceFile.prototype._scriptForRawLocation):
(WebInspector.SourceFile.prototype.createSourceMappingIfNeeded):
(WebInspector.FormattedSourceFile.prototype.createSourceMappingIfNeeded):
(WebInspector.FormattedSourceFile.prototype._didRequestContent):

LayoutTests:

* inspector/debugger/source-file-expected.txt: Added.
* inspector/debugger/source-file.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (92050 => 92051)


--- trunk/LayoutTests/ChangeLog	2011-07-30 11:43:07 UTC (rev 92050)
+++ trunk/LayoutTests/ChangeLog	2011-07-30 12:42:56 UTC (rev 92051)
@@ -1,3 +1,13 @@
+2011-07-26  Pavel Podivilov  <[email protected]>
+
+        Web Inspector: move location conversion functions to SourceFile.
+        https://bugs.webkit.org/show_bug.cgi?id=65185
+
+        Reviewed by Pavel Feldman.
+
+        * inspector/debugger/source-file-expected.txt: Added.
+        * inspector/debugger/source-file.html: Added.
+
 2011-07-30  Csaba Osztrogonác  <[email protected]>
 
         [Qt] Update platform specific expected files after r92047.

Added: trunk/LayoutTests/inspector/debugger/source-file-expected.txt (0 => 92051)


--- trunk/LayoutTests/inspector/debugger/source-file-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/debugger/source-file-expected.txt	2011-07-30 12:42:56 UTC (rev 92051)
@@ -0,0 +1,11 @@
+Tests mapping between raw locations and ui locations.
+
+
+Running: testPlainConvertLocation
+
+Running: testConcatenatedConvertLocation
+
+Running: testFormattedConvertLocation
+
+Running: testConcatenatedFormattedConvertLocation
+
Property changes on: trunk/LayoutTests/inspector/debugger/source-file-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/inspector/debugger/source-file.html (0 => 92051)


--- trunk/LayoutTests/inspector/debugger/source-file.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/debugger/source-file.html	2011-07-30 12:42:56 UTC (rev 92051)
@@ -0,0 +1,122 @@
+<html>
+<head>
+<script src=""
+
+<script>
+
+function test()
+{
+    var mockSourceMapping = {
+        originalToFormatted: function(location)
+        {
+            var formattedLocation = {};
+            formattedLocation.lineNumber = location.lineNumber * 2;
+            formattedLocation.columnNumber = location.columnNumber * 2;
+            return formattedLocation;
+        },
+
+        formattedToOriginal: function(location)
+        {
+            var originalLocation = {};
+            originalLocation.lineNumber = Math.floor(location.lineNumber / 2);
+            originalLocation.columnNumber = Math.floor(location.columnNumber / 2);
+            return originalLocation;
+        }
+    };
+
+    var mockScriptFormatter = {
+        formatContent: function(mimeType, content, callback)
+        {
+            callback(content, mockSourceMapping);
+        }
+    };
+
+    function rl(lineNumber, columnNumber)
+    {
+        return { lineNumber: lineNumber, columnNumber: columnNumber };
+    }
+
+    function checkRawLocation(script, lineNumber, columnNumber, location)
+    {
+        InspectorTest.assertEquals(script.sourceId, location.sourceId);
+        InspectorTest.assertEquals(lineNumber, location.lineNumber);
+        InspectorTest.assertEquals(columnNumber, location.columnNumber);
+    }
+
+    function checkUILocation(sourceFile, lineNumber, columnNumber, location)
+    {
+        InspectorTest.assertEquals(sourceFile, location.sourceFile);
+        InspectorTest.assertEquals(lineNumber, location.lineNumber);
+        InspectorTest.assertEquals(columnNumber, location.columnNumber);
+    }
+
+    InspectorTest.runTestSuite([
+        function testPlainConvertLocation(next)
+        {
+            var script = new WebInspector.Script("1", "foo.js", 0, 0, 20, 80, undefined, undefined, false);
+            var sourceFile = new WebInspector.SourceFile("id", script);
+
+            checkUILocation(sourceFile, 10, 20, sourceFile.rawLocationToUILocation(rl(10, 20)));
+            checkRawLocation(script, 30, 40, sourceFile.uiLocationToRawLocation(30, 40));
+
+            next();
+        },
+
+        function testConcatenatedConvertLocation(next)
+        {
+            var script1 = new WebInspector.Script("1", "foo.js", 10, 20, 30, 40, undefined, undefined, false);
+            var script2 = new WebInspector.Script("2", "foo.js", 50, 60, 70, 80, undefined, undefined, false);
+            var sourceFile = new WebInspector.SourceFile("id", script1);
+            sourceFile.addScript(script2);
+
+            checkUILocation(sourceFile, 20, 0, sourceFile.rawLocationToUILocation(rl(20, 0)));
+
+            checkRawLocation(script1, 0, 40, sourceFile.uiLocationToRawLocation(0, 40));
+            checkRawLocation(script1, 20, 0, sourceFile.uiLocationToRawLocation(20, 0));
+            checkRawLocation(script2, 50, 60, sourceFile.uiLocationToRawLocation(50, 60));
+
+            next();
+        },
+
+        function testFormattedConvertLocation(next)
+        {
+            var script = new WebInspector.Script("1", "foo.js", 0, 0, 20, 80, undefined, undefined, false);
+            var sourceFile = new WebInspector.FormattedSourceFile("id", script, null, mockScriptFormatter);
+
+            function didCreateSourceMapping()
+            {
+                checkUILocation(sourceFile, 22, 40, sourceFile.rawLocationToUILocation(rl(11, 20)));
+                checkRawLocation(script, 7, 9, sourceFile.uiLocationToRawLocation(14, 19));
+                next();
+            }
+            sourceFile.createSourceMappingIfNeeded(didCreateSourceMapping);
+        },
+
+        function testConcatenatedFormattedConvertLocation(next)
+        {
+            var script1 = new WebInspector.Script("1", "foo.js", 10, 20, 30, 40, undefined, undefined, false);
+            var script2 = new WebInspector.Script("2", "foo.js", 50, 60, 70, 80, undefined, undefined, false);
+            var sourceFile = new WebInspector.FormattedSourceFile("id", script1, null, mockScriptFormatter);
+            sourceFile.addScript(script2);
+
+            function didCreateSourceMapping()
+            {
+                checkUILocation(sourceFile, 22, 60, sourceFile.rawLocationToUILocation(rl(11, 30)));
+                checkRawLocation(script1, 12, 10, sourceFile.uiLocationToRawLocation(24, 20));
+                checkRawLocation(script2, 60, 19, sourceFile.uiLocationToRawLocation(121, 38));
+                next();
+            }
+            sourceFile.createSourceMappingIfNeeded(didCreateSourceMapping);
+        }
+    ]);
+};
+
+</script>
+
+</head>
+
+<body _onload_="runTest()">
+<p>Tests mapping between raw locations and ui locations.</p>
+
+</body>
+</html>
Property changes on: trunk/LayoutTests/inspector/debugger/source-file.html
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/Source/WebCore/ChangeLog (92050 => 92051)


--- trunk/Source/WebCore/ChangeLog	2011-07-30 11:43:07 UTC (rev 92050)
+++ trunk/Source/WebCore/ChangeLog	2011-07-30 12:42:56 UTC (rev 92051)
@@ -1,3 +1,25 @@
+2011-07-26  Pavel Podivilov  <[email protected]>
+
+        Web Inspector: move location conversion functions to SourceFile.
+        https://bugs.webkit.org/show_bug.cgi?id=65185
+
+        Reviewed by Pavel Feldman.
+
+        Test: inspector/debugger/source-file.html
+
+        * inspector/front-end/DebuggerPresentationModel.js:
+        (WebInspector.DebuggerPresentationModel.prototype._scriptLocationToUILocation.didCreateSourceMapping):
+        (WebInspector.DebuggerPresentationModel.prototype._scriptLocationToUILocation):
+        (WebInspector.DebuggerPresentationModel.prototype._uiLocationToScriptLocation.didCreateSourceMapping):
+        (WebInspector.DebuggerPresentationModel.prototype._uiLocationToScriptLocation):
+        * inspector/front-end/SourceFile.js:
+        (WebInspector.SourceFile.prototype.rawLocationToUILocation):
+        (WebInspector.SourceFile.prototype.uiLocationToRawLocation):
+        (WebInspector.SourceFile.prototype._scriptForRawLocation):
+        (WebInspector.SourceFile.prototype.createSourceMappingIfNeeded):
+        (WebInspector.FormattedSourceFile.prototype.createSourceMappingIfNeeded):
+        (WebInspector.FormattedSourceFile.prototype._didRequestContent):
+
 2011-07-29  Rob Buis  <[email protected]>
 
         URL references are completely broken in SVG

Modified: trunk/Source/WebCore/inspector/front-end/DebuggerPresentationModel.js (92050 => 92051)


--- trunk/Source/WebCore/inspector/front-end/DebuggerPresentationModel.js	2011-07-30 11:43:07 UTC (rev 92050)
+++ trunk/Source/WebCore/inspector/front-end/DebuggerPresentationModel.js	2011-07-30 12:42:56 UTC (rev 92051)
@@ -87,23 +87,29 @@
     _scriptLocationToUILocation: function(sourceURL, sourceId, lineNumber, columnNumber, callback)
     {
         var sourceFile = this._sourceFileForScript(sourceURL, sourceId);
-        var scriptLocation = { lineNumber: lineNumber, columnNumber: columnNumber };
 
-        function didRequestSourceMapping(mapping)
+        function didCreateSourceMapping()
         {
-            var lineNumber = mapping.scriptLocationToSourceLine(scriptLocation);
-            callback(sourceFile.id, lineNumber);
+            var uiLocation = sourceFile.rawLocationToUILocation({ lineNumber: lineNumber, columnNumber: columnNumber });
+            callback(uiLocation.sourceFile.id, uiLocation.lineNumber);
         }
-        sourceFile.requestSourceMapping(didRequestSourceMapping);
+        // FIXME: force source formatting if needed. This will go away once formatting
+        // is fully encapsulated in SourceFile.
+        sourceFile.createSourceMappingIfNeeded(didCreateSourceMapping);
     },
 
     _uiLocationToScriptLocation: function(sourceFileId, lineNumber, callback)
     {
-        function didRequestSourceMapping(mapping)
+        var sourceFile = this._sourceFiles[sourceFileId];
+
+        function didCreateSourceMapping()
         {
-            callback(mapping.sourceLineToScriptLocation(lineNumber));
+            var rawLocation = sourceFile.uiLocationToRawLocation(lineNumber, 0);
+            callback(rawLocation);
         }
-        this._sourceFiles[sourceFileId].requestSourceMapping(didRequestSourceMapping.bind(this));
+        // FIXME: force source formatting if needed. This will go away once formatting
+        // is fully encapsulated in SourceFile.
+        sourceFile.createSourceMappingIfNeeded(didCreateSourceMapping);
     },
 
     requestSourceFileContent: function(sourceFileId, callback)

Modified: trunk/Source/WebCore/inspector/front-end/SourceFile.js (92050 => 92051)


--- trunk/Source/WebCore/inspector/front-end/SourceFile.js	2011-07-30 11:43:07 UTC (rev 92050)
+++ trunk/Source/WebCore/inspector/front-end/SourceFile.js	2011-07-30 12:42:56 UTC (rev 92051)
@@ -52,6 +52,36 @@
         this._scripts.push(script);
     },
 
+    rawLocationToUILocation: function(rawLocation)
+    {
+        var uiLocation = this._mapping ? this._mapping.originalToFormatted(rawLocation) : rawLocation;
+        uiLocation.sourceFile = this;
+        return uiLocation;
+    },
+
+    uiLocationToRawLocation: function(lineNumber, columnNumber)
+    {
+        var rawLocation = { lineNumber: lineNumber, columnNumber: columnNumber };
+        if (this._mapping)
+            rawLocation = this._mapping.formattedToOriginal(rawLocation);
+        rawLocation.sourceId = this._scriptForRawLocation(rawLocation.lineNumber, rawLocation.columnNumber).sourceId;
+        return rawLocation;
+    },
+
+    _scriptForRawLocation: function(lineNumber, columnNumber)
+    {
+        var closestScript = this._scripts[0];
+        for (var i = 1; i < this._scripts.length; ++i) {
+            script = this._scripts[i];
+            if (script.lineOffset > lineNumber || (script.lineOffset === lineNumber && script.columnOffset > columnNumber))
+                continue;
+            if (script.lineOffset > closestScript.lineOffset ||
+                (script.lineOffset === closestScript.lineOffset && script.columnOffset > closestScript.columnOffset))
+                closestScript = script;
+        }
+        return closestScript;
+    },
+
     requestContent: function(callback)
     {
         if (this._contentLoaded) {
@@ -74,11 +104,10 @@
         this._content = content;
     },
 
-    requestSourceMapping: function(callback)
+    createSourceMappingIfNeeded: function(callback)
     {
-        if (!this._mapping)
-            this._mapping = new WebInspector.SourceMapping(this._scripts);
-        callback(this._mapping);
+        // Plain source without mapping.
+        callback();
     },
 
     forceLoadContent: function(script)
@@ -236,12 +265,13 @@
 }
 
 WebInspector.FormattedSourceFile.prototype = {
-    requestSourceMapping: function(callback)
+    createSourceMappingIfNeeded: function(callback)
     {
         function didRequestContent()
         {
-            callback(this._mapping);
+            callback();
         }
+        // Force content formatting to obtain the mapping.
         this.requestContent(didRequestContent.bind(this));
     },
 
@@ -249,7 +279,7 @@
     {
         function didFormatContent(formattedText, mapping)
         {
-            this._mapping = new WebInspector.SourceMappingForFormattedSourceFile(this._scripts, mapping);
+            this._mapping = mapping;
             WebInspector.SourceFile.prototype._didRequestContent.call(this, mimeType, formattedText);
         }
         this._formatter.formatContent(mimeType, text, didFormatContent.bind(this));
@@ -257,54 +287,3 @@
 }
 
 WebInspector.FormattedSourceFile.prototype.__proto__ = WebInspector.SourceFile.prototype;
-
-WebInspector.SourceMapping = function(scripts)
-{
-    this._sortedScripts = scripts.slice();
-    this._sortedScripts.sort(function(x, y) { return x.lineOffset - y.lineOffset || x.columnOffset - y.columnOffset; });
-}
-
-WebInspector.SourceMapping.prototype = {
-    scriptLocationToSourceLine: function(location)
-    {
-        return location.lineNumber;
-    },
-
-    sourceLineToScriptLocation: function(lineNumber)
-    {
-        return this._sourceLocationToScriptLocation(lineNumber, 0);
-    },
-
-    _sourceLocationToScriptLocation: function(lineNumber, columnNumber)
-    {
-        var closestScript = this._sortedScripts[0];
-        for (var i = 1; i < this._sortedScripts.length; ++i) {
-            script = this._sortedScripts[i];
-            if (script.lineOffset > lineNumber || (script.lineOffset === lineNumber && script.columnOffset > columnNumber))
-                break;
-            closestScript = script;
-        }
-        return { sourceId: closestScript.sourceId, lineNumber: lineNumber, columnNumber: columnNumber };
-    }
-}
-
-WebInspector.SourceMappingForFormattedSourceFile = function(scripts, mapping)
-{
-    WebInspector.SourceMapping.call(this, scripts);
-    this._mapping = mapping;
-}
-
-WebInspector.SourceMappingForFormattedSourceFile.prototype = {
-    scriptLocationToSourceLine: function(location)
-    {
-        return this._mapping.originalToFormatted(location).lineNumber;
-    },
-
-    sourceLineToScriptLocation: function(lineNumber)
-    {
-        var originalLocation = this._mapping.formattedToOriginal({ lineNumber: lineNumber, columnNumber: 0 });
-        return WebInspector.SourceMapping.prototype._sourceLocationToScriptLocation.call(this, originalLocation.lineNumber, originalLocation.columnNumber);
-    }
-}
-
-WebInspector.SourceMappingForFormattedSourceFile.prototype.__proto__ = WebInspector.SourceMapping.prototype;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to