Web Inspector: extract CompilerScriptMapping from RawSourceCode.
authorpodivilov@chromium.org <podivilov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Mar 2012 16:55:38 +0000 (16:55 +0000)
committerpodivilov@chromium.org <podivilov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Mar 2012 16:55:38 +0000 (16:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=81088

Reviewed by Vsevolod Vlasov.

Source/WebCore:

* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* inspector/compile-front-end.py:
* inspector/front-end/CompilerScriptMapping.js: Added.
(WebInspector.CompilerScriptMapping):
(WebInspector.CompilerScriptMapping.prototype.rawLocationToUILocation):
(WebInspector.CompilerScriptMapping.prototype.get uiSourceCodeList):
(WebInspector.CompilerScriptMapping.prototype.addScript.get this):
(WebInspector.CompilerScriptMapping.prototype.addScript):
(WebInspector.CompilerScriptMapping.prototype.loadSourceMapForScript):
(WebInspector.CompilerScriptMapping.prototype.reset):
* inspector/front-end/RawSourceCode.js:
(WebInspector.RawSourceCode):
(WebInspector.RawSourceCode.prototype.setFormatted):
(WebInspector.RawSourceCode.prototype._resourceFinished):
(WebInspector.RawSourceCode.prototype._createUISourceCode):
(WebInspector.RawSourceCode.FormattedSourceMapping.prototype.rawLocationToUILocation):
* inspector/front-end/ResourceScriptMapping.js:
(WebInspector.ResourceScriptMapping.prototype.addScript):
* inspector/front-end/ScriptMapping.js:
(WebInspector.MainScriptMapping):
* inspector/front-end/WebKit.qrc:
* inspector/front-end/inspector.html:

LayoutTests:

* http/tests/inspector/compiler-source-mapping-expected.txt:
* http/tests/inspector/compiler-source-mapping.html:
* http/tests/inspector/debugger-test.js:
(initialize_DebuggerTest.):
(initialize_DebuggerTest):
* inspector/debugger/raw-source-code-expected.txt:
* inspector/debugger/raw-source-code.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@110856 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/inspector/compiler-source-mapping-expected.txt
LayoutTests/http/tests/inspector/compiler-source-mapping.html
LayoutTests/http/tests/inspector/debugger-test.js
LayoutTests/inspector/debugger/raw-source-code-expected.txt
LayoutTests/inspector/debugger/raw-source-code.html
Source/WebCore/ChangeLog
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/inspector/compile-front-end.py
Source/WebCore/inspector/front-end/CompilerScriptMapping.js [new file with mode: 0644]
Source/WebCore/inspector/front-end/RawSourceCode.js
Source/WebCore/inspector/front-end/ResourceScriptMapping.js
Source/WebCore/inspector/front-end/ScriptMapping.js
Source/WebCore/inspector/front-end/WebKit.qrc
Source/WebCore/inspector/front-end/inspector.html

index aa4a054..c3df1db 100644 (file)
@@ -1,3 +1,18 @@
+2012-03-14  Pavel Podivilov  <podivilov@chromium.org>
+
+        Web Inspector: extract CompilerScriptMapping from RawSourceCode.
+        https://bugs.webkit.org/show_bug.cgi?id=81088
+
+        Reviewed by Vsevolod Vlasov.
+
+        * http/tests/inspector/compiler-source-mapping-expected.txt:
+        * http/tests/inspector/compiler-source-mapping.html:
+        * http/tests/inspector/debugger-test.js:
+        (initialize_DebuggerTest.):
+        (initialize_DebuggerTest):
+        * inspector/debugger/raw-source-code-expected.txt:
+        * inspector/debugger/raw-source-code.html:
+
 2012-03-15  Jessie Berlin  <jberlin@apple.com>
 
         css3/filters/custom/custom-filter-property-computed-style.html passes in browser, fails in DRT.
index 7af9b32..7a29b10 100644 (file)
@@ -11,5 +11,7 @@ Running: testSections
 
 Running: testResolveSourceMappingURL
 
-Running: testLoad
+Running: testCompilerScriptMapping
+
+Running: testCompilerSourceMappingCouldNotBeLoaded
 
index 6d244f8..ab16354 100644 (file)
@@ -1,6 +1,7 @@
 <html>
 <head>
 <script src="inspector-test.js"></script>
+<script src="debugger-test.js"></script>
 
 <script>
 
@@ -126,23 +127,56 @@ function test()
             next();
         },
 
-        function testLoad(next)
+        function testCompilerScriptMapping(next)
         {
-            var sourceMapping = new WebInspector.ClosureCompilerSourceMapping("http://localhost:8000/inspector/resources/source-map.json");
-            var success = sourceMapping.load();
-            InspectorTest.assertTrue(success);
-
-            var sources = sourceMapping.sources();
-            InspectorTest.assertEquals(2, sources.length);
-            InspectorTest.assertEquals("http://localhost:8000/inspector/resources/source1.js", sources[0]);
-            InspectorTest.assertEquals("http://localhost:8000/inspector/resources/source2.js", sources[1]);
-
-            var sourceCode1 = sourceMapping.loadSourceCode(sourceMapping.sources()[0]);
-            InspectorTest.assertEquals(0, sourceCode1.indexOf("window.addEventListener"));
+            var mapping = new WebInspector.CompilerScriptMapping();
+            var script = InspectorTest.createScriptMock("compiled.js", 0, 0, true, "");
+            script.sourceMapURL = "http://localhost:8000/inspector/resources/source-map.json";
+            mapping.addScript(script);
+
+            var uiSourceCodeList = mapping.uiSourceCodeList();
+            InspectorTest.assertEquals(2, uiSourceCodeList.length);
+            InspectorTest.assertEquals("http://localhost:8000/inspector/resources/source1.js", uiSourceCodeList[0].url);
+            InspectorTest.assertEquals("http://localhost:8000/inspector/resources/source2.js", uiSourceCodeList[1].url);
+
+            InspectorTest.checkUILocation(uiSourceCodeList[0], 4, 4, mapping.rawLocationToUILocation(WebInspector.debuggerModel.createRawLocation(script, 0, 81)));
+            InspectorTest.checkUILocation(uiSourceCodeList[0], 5, 4, mapping.rawLocationToUILocation(WebInspector.debuggerModel.createRawLocation(script, 0, 93)));
+            InspectorTest.checkUILocation(uiSourceCodeList[1], 7, 4, mapping.rawLocationToUILocation(WebInspector.debuggerModel.createRawLocation(script, 1, 151)));
+
+            InspectorTest.checkRawLocation(script, 0, 42, mapping.uiLocationToRawLocation(uiSourceCodeList[0], 3, 10));
+            InspectorTest.checkRawLocation(script, 1, 85, mapping.uiLocationToRawLocation(uiSourceCodeList[1], 0, 0));
+            InspectorTest.checkRawLocation(script, 1, 110, mapping.uiLocationToRawLocation(uiSourceCodeList[1], 5, 2));
+
+            uiSourceCodeList[0].requestContent(didRequestContent1);
+
+            function didRequestContent1(mimeType, content)
+            {
+                InspectorTest.assertEquals(0, content.indexOf("window.addEventListener"));
+                uiSourceCodeList[1].requestContent(didRequestContent2);
+            }
+
+            function didRequestContent2(mimeType, content)
+            {
+                InspectorTest.assertEquals(0, content.indexOf("function ClickHandler()"));
+                next();
+            }
+        },
 
-            var sourceCode2 = sourceMapping.loadSourceCode(sourceMapping.sources()[1]);
-            InspectorTest.assertEquals(0, sourceCode2.indexOf("function ClickHandler()"));
-            next();
+        function testCompilerSourceMappingCouldNotBeLoaded(next)
+        {
+            var mainScriptMapping = new WebInspector.MainScriptMapping();
+            mainScriptMapping.addEventListener(WebInspector.MainScriptMapping.Events.UISourceCodeListChanged, uiSourceCodeListChanged);
+
+            var script = InspectorTest.createScriptMock("compiled.js", 0, 0, true, "");
+            script.sourceMapURL = "http://localhost:8000/inspector/resources/source-map.json_";
+            mainScriptMapping.addScript(script);
+
+            function uiSourceCodeListChanged(event)
+            {
+                InspectorTest.assertEquals(1, event.data.addedItems.length);
+                InspectorTest.assertEquals("compiled.js", event.data.addedItems[0].url);
+                next();
+            }
         }
     ]);
 };
index 37479c9..95f47dd 100644 (file)
@@ -282,4 +282,32 @@ InspectorTest.queryScripts = function(filter)
     return scripts;
 };
 
+InspectorTest.createScriptMock = function(url, startLine, startColumn, isContentScript, source)
+{
+    var scriptId = ++InspectorTest._lastScriptId;
+    var lineCount = source.lineEndings().length;
+    var endLine = startLine + lineCount - 1;
+    var endColumn = lineCount === 1 ? startColumn + source.length : source.length - source.lineEndings()[lineCount - 2];
+    var script = new WebInspector.Script(scriptId, url, startLine, startColumn, endLine, endColumn, isContentScript);
+    script.requestSource = function(callback) { callback(source); };
+    WebInspector.debuggerModel._scripts[scriptId] = script;
+    return script;
+}
+
+InspectorTest._lastScriptId = 0;
+
+InspectorTest.checkRawLocation = function(script, lineNumber, columnNumber, location)
+{
+    InspectorTest.assertEquals(script.scriptId, location.scriptId);
+    InspectorTest.assertEquals(lineNumber, location.lineNumber);
+    InspectorTest.assertEquals(columnNumber, location.columnNumber);
+};
+
+InspectorTest.checkUILocation = function(uiSourceCode, lineNumber, columnNumber, location)
+{
+    InspectorTest.assertEquals(uiSourceCode, location.uiSourceCode);
+    InspectorTest.assertEquals(lineNumber, location.lineNumber);
+    InspectorTest.assertEquals(columnNumber, location.columnNumber);
+};
+
 };
index 106b55c..fda655f 100644 (file)
@@ -13,7 +13,3 @@ Running: testFormattingWithFinishedResource
 
 Running: testFormattingWithPendingResource
 
-Running: testCompilerSourceMapping
-
-Running: testCompilerSourceMappingCouldNotBeLoaded
-
index 2babed5..6027573 100644 (file)
@@ -1,22 +1,12 @@
 <html>
 <head>
 <script src="../../http/tests/inspector/inspector-test.js"></script>
+<script src="../../http/tests/inspector/debugger-test.js"></script>
 
 <script>
 
 function test()
 {
-    function createScriptMock(url, startLine, startColumn, isContentScript, source)
-    {
-        var lineCount = source.lineEndings().length;
-        var endLine = startLine + lineCount - 1;
-        var endColumn = lineCount === 1 ? startColumn + source.length : source.length - source.lineEndings()[lineCount - 2];
-        var script = new WebInspector.Script(1, url, startLine, startColumn, endLine, endColumn, isContentScript);
-        script.requestSource = function(callback) { callback(source); };
-        WebInspector.debuggerModel._scripts[1] = script;
-        return script;
-    }
-
     function createResourceMock(type, finished, content)
     {
         var resource = {};
@@ -73,32 +63,19 @@ function test()
         return { lineNumber: lineNumber, columnNumber: columnNumber };
     }
 
-    function checkRawLocation(script, lineNumber, columnNumber, location)
-    {
-        InspectorTest.assertEquals(script.scriptId, location.scriptId);
-        InspectorTest.assertEquals(lineNumber, location.lineNumber);
-        InspectorTest.assertEquals(columnNumber, location.columnNumber);
-    }
-
-    function checkUILocation(uiSourceCode, lineNumber, columnNumber, location)
-    {
-        InspectorTest.assertEquals(uiSourceCode, location.uiSourceCode);
-        InspectorTest.assertEquals(lineNumber, location.lineNumber);
-        InspectorTest.assertEquals(columnNumber, location.columnNumber);
-    }
-
     InspectorTest.runTestSuite([
         function testScriptWithoutResource(next)
         {
-            var script = createScriptMock("foo.js", 0, 0, true, "<script source>");
+            WebInspector.debuggerModel._scripts = [];
+            var script = InspectorTest.createScriptMock("foo.js", 0, 0, true, "<script source>");
             var rawSourceCode = createRawSourceCode(script, null);
 
             InspectorTest.assertEquals(1, rawSourceCode.uiSourceCodeList().length);
             var uiSourceCode = rawSourceCode.uiSourceCodeList()[0];
             InspectorTest.assertEquals("foo.js", uiSourceCode.url);
             InspectorTest.assertEquals(true, uiSourceCode.isContentScript);
-            checkUILocation(uiSourceCode, 0, 5, rawSourceCode.rawLocationToUILocation(createRawLocation(0, 5)));
-            checkRawLocation(script, 10, 0, rawSourceCode.uiLocationToRawLocation(uiSourceCode, 10, 0));
+            InspectorTest.checkUILocation(uiSourceCode, 0, 5, rawSourceCode.rawLocationToUILocation(createRawLocation(0, 5)));
+            InspectorTest.checkRawLocation(script, 10, 0, rawSourceCode.uiLocationToRawLocation(uiSourceCode, 10, 0));
             uiSourceCode.requestContent(didRequestContent);
 
             function didRequestContent(mimeType, content)
@@ -111,8 +88,9 @@ function test()
 
         function testHTMLWithPendingResource(next)
         {
-            var script1 = createScriptMock("index.html", 0, 10, false, "<script source 1>");
-            var script2 = createScriptMock("index.html", 0, 45, false, "<script source 2>");
+            WebInspector.debuggerModel._scripts = [];
+            var script1 = InspectorTest.createScriptMock("index.html", 0, 10, false, "<script source 1>");
+            var script2 = InspectorTest.createScriptMock("index.html", 0, 45, false, "<script source 2>");
             var resource = createPendingResourceMock("document", "<resource content>");
             var rawSourceCode = createRawSourceCode(script1, resource);
 
@@ -143,8 +121,9 @@ function test()
 
         function testHTMLWithFinishedResource(next)
         {
-            var script1 = createScriptMock("index.html", 1, 10, false, "<script source 1>");
-            var script2 = createScriptMock("index.html", 5, 45, false, "<script\nsource\n2>");
+            WebInspector.debuggerModel._scripts = [];
+            var script1 = InspectorTest.createScriptMock("index.html", 1, 10, false, "<script source 1>");
+            var script2 = InspectorTest.createScriptMock("index.html", 5, 45, false, "<script\nsource\n2>");
             var resource = createFinishedResourceMock("document", "<resource content>");
             var rawSourceCode = createRawSourceCode(script1, resource);
 
@@ -161,9 +140,9 @@ function test()
 
                 rawSourceCode.addScript(script2);
                 rawSourceCode.forceUpdateSourceMapping();
-                checkUILocation(uiSourceCode, 1, 20, rawSourceCode.rawLocationToUILocation(createRawLocation(1, 20)));
-                checkRawLocation(script1, 1, 0, rawSourceCode.uiLocationToRawLocation(uiSourceCode, 1, 0));
-                checkRawLocation(script2, 6, 0, rawSourceCode.uiLocationToRawLocation(uiSourceCode, 6, 0));
+                InspectorTest.checkUILocation(uiSourceCode, 1, 20, rawSourceCode.rawLocationToUILocation(createRawLocation(1, 20)));
+                InspectorTest.checkRawLocation(script1, 1, 0, rawSourceCode.uiLocationToRawLocation(uiSourceCode, 1, 0));
+                InspectorTest.checkRawLocation(script2, 6, 0, rawSourceCode.uiLocationToRawLocation(uiSourceCode, 6, 0));
 
                 next();
             }
@@ -171,9 +150,10 @@ function test()
 
         function testForceUpdateSourceMapping(next)
         {
-            var script1 = createScriptMock("index.html", 0, 10, false, "<script source 1>");
-            var script2 = createScriptMock("index.html", 0, 45, false, "<script source 2>");
-            var script3 = createScriptMock("index.html", 1, 10, false, "<script source 3>");
+            WebInspector.debuggerModel._scripts = [];
+            var script1 = InspectorTest.createScriptMock("index.html", 0, 10, false, "<script source 1>");
+            var script2 = InspectorTest.createScriptMock("index.html", 0, 45, false, "<script source 2>");
+            var script3 = InspectorTest.createScriptMock("index.html", 1, 10, false, "<script source 3>");
             var resource = createPendingResourceMock("document", "<resource content>");
             var rawSourceCode = createRawSourceCode(script1, resource);
 
@@ -237,14 +217,15 @@ function test()
 
         function testFormattingWithFinishedResource(next)
         {
-            var script = createScriptMock("foo.js", 0, 0, true, "<script source>");
+            WebInspector.debuggerModel._scripts = [];
+            var script = InspectorTest.createScriptMock("foo.js", 0, 0, true, "<script source>");
             var resource = createFinishedResourceMock("script", "<resource content>");
             var rawSourceCode = createRawSourceCode(script, resource, false);
 
             InspectorTest.assertEquals(1, rawSourceCode.uiSourceCodeList().length);
             var uiSourceCode = rawSourceCode.uiSourceCodeList()[0];
-            checkUILocation(uiSourceCode, 1, 2, rawSourceCode.rawLocationToUILocation(createRawLocation(1, 2)));
-            checkRawLocation(script, 2, 0, rawSourceCode.uiLocationToRawLocation(uiSourceCode, 2, 0));
+            InspectorTest.checkUILocation(uiSourceCode, 1, 2, rawSourceCode.rawLocationToUILocation(createRawLocation(1, 2)));
+            InspectorTest.checkRawLocation(script, 2, 0, rawSourceCode.uiLocationToRawLocation(uiSourceCode, 2, 0));
             uiSourceCode.requestContent(didRequestContent);
 
             function didRequestContent(mimeType, content)
@@ -261,8 +242,8 @@ function test()
             {
                 InspectorTest.assertEquals(1, rawSourceCode.uiSourceCodeList().length);
                 var uiSourceCode = rawSourceCode.uiSourceCodeList()[0];
-                checkUILocation(uiSourceCode, 2, 4, rawSourceCode.rawLocationToUILocation(createRawLocation(1, 2)));
-                checkRawLocation(script, 1, 0, rawSourceCode.uiLocationToRawLocation(uiSourceCode, 2, 0));
+                InspectorTest.checkUILocation(uiSourceCode, 2, 4, rawSourceCode.rawLocationToUILocation(createRawLocation(1, 2)));
+                InspectorTest.checkRawLocation(script, 1, 0, rawSourceCode.uiLocationToRawLocation(uiSourceCode, 2, 0));
                 uiSourceCode.requestContent(didRequestFormattedContent);
             }
 
@@ -279,8 +260,8 @@ function test()
             {
                 InspectorTest.assertEquals(1, rawSourceCode.uiSourceCodeList().length);
                 var uiSourceCode = rawSourceCode.uiSourceCodeList()[0];
-                checkUILocation(uiSourceCode, 1, 2, rawSourceCode.rawLocationToUILocation(createRawLocation(1, 2)));
-                checkRawLocation(script, 2, 0, rawSourceCode.uiLocationToRawLocation(uiSourceCode, 2, 0));
+                InspectorTest.checkUILocation(uiSourceCode, 1, 2, rawSourceCode.rawLocationToUILocation(createRawLocation(1, 2)));
+                InspectorTest.checkRawLocation(script, 2, 0, rawSourceCode.uiLocationToRawLocation(uiSourceCode, 2, 0));
                 uiSourceCode.requestContent(didRequestNotFormattedContent);
             }
 
@@ -295,7 +276,8 @@ function test()
 
         function testFormattingWithPendingResource(next)
         {
-            var script = createScriptMock("foo.js", 0, 0, true, "<script source>");
+            WebInspector.debuggerModel._scripts = [];
+            var script = InspectorTest.createScriptMock("foo.js", 0, 0, true, "<script source>");
             var resource = createPendingResourceMock("script", "<resource content>");
             var rawSourceCode = createRawSourceCode(script, resource, true);
 
@@ -308,73 +290,10 @@ function test()
             {
                 InspectorTest.assertEquals(1, rawSourceCode.uiSourceCodeList().length);
                 var uiSourceCode = rawSourceCode.uiSourceCodeList()[0];
-                checkUILocation(uiSourceCode, 2, 4, rawSourceCode.rawLocationToUILocation(createRawLocation(1, 2)));
-                checkRawLocation(script, 1, 0, rawSourceCode.uiLocationToRawLocation(uiSourceCode, 2, 0));
-                next();
-            }
-        },
-
-        function testCompilerSourceMapping(next)
-        {
-            var compilerSourceMappingMock = {
-                compiledLocationToSourceLocation: function(lineNumber, columnNumber)
-                {
-                    if (lineNumber < 10)
-                        return { sourceURL: "source1.js", lineNumber: lineNumber * 2, columnNumber: columnNumber * 2 };
-                    return { sourceURL: "source2.js", lineNumber: (lineNumber - 10) * 2, columnNumber: columnNumber * 2 };
-                },
-                sourceLocationToCompiledLocation: function(sourceURL, lineNumber)
-                {
-                    if (sourceURL === "source1.js")
-                        return [Math.floor(lineNumber / 2), 0];
-                    return [Math.floor(lineNumber / 2) + 10, 0];
-                },
-                sources: function() { return ["source1.js", "source2.js"]; },
-                load: function() { return true; },
-                loadSourceCode: function(url) { return "<content of " + url + ">"; }
-            };
-
-            var script = createScriptMock("compiled.js", 0, 0, true, "<script source>");
-            var resource = createPendingResourceMock("script", "<resource content>");
-            var rawSourceCode = createRawSourceCode(script, resource, false, compilerSourceMappingMock);
-            var uiSourceCodeList;
-
-            uiSourceCodeList = rawSourceCode.uiSourceCodeList();
-            var uiSourceCodeByURL = {};
-            for (var i = 0; i < uiSourceCodeList.length; ++i)
-                uiSourceCodeByURL[uiSourceCodeList[i].url] = uiSourceCodeList[i];
-            checkUILocation(uiSourceCodeByURL["source1.js"], 2, 4, rawSourceCode.rawLocationToUILocation(createRawLocation(1, 2)));
-            checkUILocation(uiSourceCodeByURL["source2.js"], 10, 40, rawSourceCode.rawLocationToUILocation(createRawLocation(15, 20)));
-            checkRawLocation(script, 1, 0, rawSourceCode.uiLocationToRawLocation(uiSourceCodeByURL["source1.js"], 2, 0));
-            checkRawLocation(script, 15, 0, rawSourceCode.uiLocationToRawLocation(uiSourceCodeByURL["source2.js"], 10, 0));
-
-            uiSourceCodeList[0].requestContent(didRequestContent1);
-
-            function didRequestContent1(mimeType, content)
-            {
-                InspectorTest.assertEquals("text/javascript", mimeType);
-                InspectorTest.assertEquals("<content of source1.js>", content);
-                uiSourceCodeList[1].requestContent(didRequestContent2);
-            }
-
-            function didRequestContent2(mimeType, content)
-            {
-                InspectorTest.assertEquals("text/javascript", mimeType);
-                InspectorTest.assertEquals("<content of source2.js>", content);
+                InspectorTest.checkUILocation(uiSourceCode, 2, 4, rawSourceCode.rawLocationToUILocation(createRawLocation(1, 2)));
+                InspectorTest.checkRawLocation(script, 1, 0, rawSourceCode.uiLocationToRawLocation(uiSourceCode, 2, 0));
                 next();
             }
-        },
-
-        function testCompilerSourceMappingCouldNotBeLoaded(next)
-        {
-            var compilerSourceMappingMock = { load: function() { return false; } };
-
-            var script = createScriptMock("compiled.js", 0, 0, true, "<script source>");
-            var rawSourceCode = createRawSourceCode(script, null, false, compilerSourceMappingMock);
-
-            InspectorTest.assertEquals(1, rawSourceCode.uiSourceCodeList().length);
-            InspectorTest.assertEquals("compiled.js", rawSourceCode.uiSourceCodeList()[0].url);
-            next();
         }
     ]);
 };
index 839fa7b..d527cd8 100644 (file)
@@ -1,3 +1,34 @@
+2012-03-14  Pavel Podivilov  <podivilov@chromium.org>
+
+        Web Inspector: extract CompilerScriptMapping from RawSourceCode.
+        https://bugs.webkit.org/show_bug.cgi?id=81088
+
+        Reviewed by Vsevolod Vlasov.
+
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * inspector/compile-front-end.py:
+        * inspector/front-end/CompilerScriptMapping.js: Added.
+        (WebInspector.CompilerScriptMapping):
+        (WebInspector.CompilerScriptMapping.prototype.rawLocationToUILocation):
+        (WebInspector.CompilerScriptMapping.prototype.get uiSourceCodeList):
+        (WebInspector.CompilerScriptMapping.prototype.addScript.get this):
+        (WebInspector.CompilerScriptMapping.prototype.addScript):
+        (WebInspector.CompilerScriptMapping.prototype.loadSourceMapForScript):
+        (WebInspector.CompilerScriptMapping.prototype.reset):
+        * inspector/front-end/RawSourceCode.js:
+        (WebInspector.RawSourceCode):
+        (WebInspector.RawSourceCode.prototype.setFormatted):
+        (WebInspector.RawSourceCode.prototype._resourceFinished):
+        (WebInspector.RawSourceCode.prototype._createUISourceCode):
+        (WebInspector.RawSourceCode.FormattedSourceMapping.prototype.rawLocationToUILocation):
+        * inspector/front-end/ResourceScriptMapping.js:
+        (WebInspector.ResourceScriptMapping.prototype.addScript):
+        * inspector/front-end/ScriptMapping.js:
+        (WebInspector.MainScriptMapping):
+        * inspector/front-end/WebKit.qrc:
+        * inspector/front-end/inspector.html:
+
 2012-03-15  Peter Rybin  <peter.rybin@gmail.com>
 
         Web Inspector: Move all includes behind ENABLE(INSPECTOR) guards
index 851b8b5..ba14133 100644 (file)
             'inspector/front-end/CallStackSidebarPane.js',
             'inspector/front-end/Checkbox.js',
             'inspector/front-end/Color.js',
+            'inspector/front-end/CompilerScriptMapping.js',
             'inspector/front-end/CompilerSourceMapping.js',
             'inspector/front-end/ConsoleMessage.js',
             'inspector/front-end/ConsoleModel.js',
index 70ee15a..f5d7977 100755 (executable)
                                        >
                                </File>
                                <File
+                                       RelativePath="..\inspector\front-end\CompilerScriptMapping.js"
+                                       >
+                               </File>
+                               <File
                                        RelativePath="..\inspector\front-end\CompilerSourceMapping.js"
                                        >
                                </File>
index 6d0c6b5..589deff 100755 (executable)
@@ -61,6 +61,7 @@ modules = [
             "InspectorBackend.js",
             "ApplicationCacheModel.js",
             "Color.js",
+            "CompilerScriptMapping.js",
             "CompilerSourceMapping.js",
             "ConsoleModel.js",
             "ContentProviders.js",
diff --git a/Source/WebCore/inspector/front-end/CompilerScriptMapping.js b/Source/WebCore/inspector/front-end/CompilerScriptMapping.js
new file mode 100644 (file)
index 0000000..c7e13c9
--- /dev/null
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @constructor
+ * @extends {WebInspector.ScriptMapping}
+ */
+WebInspector.CompilerScriptMapping = function()
+{
+    this._sourceMapByURL = {};
+    this._sourceMapForScriptId = {};
+    this._scriptForSourceMap = new Map();
+    this._sourceMapForUISourceCode = new Map();
+    this._uiSourceCodeByURL = {};
+}
+
+WebInspector.CompilerScriptMapping.prototype = {
+    /**
+     * @param {DebuggerAgent.Location} rawLocation
+     * @return {WebInspector.UILocation}
+     */
+    rawLocationToUILocation: function(rawLocation)
+    {
+        var sourceMap = this._sourceMapForScriptId[rawLocation.scriptId];
+        var location = sourceMap.compiledLocationToSourceLocation(rawLocation.lineNumber, rawLocation.columnNumber || 0);
+        var uiSourceCode = this._uiSourceCodeByURL[location.sourceURL];
+        return new WebInspector.UILocation(uiSourceCode, location.lineNumber, location.columnNumber);
+    },
+
+    /**
+     * @param {WebInspector.UISourceCode} uiSourceCode
+     * @param {number} lineNumber
+     * @param {number} columnNumber
+     * @return {DebuggerAgent.Location}
+     */
+    uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber)
+    {
+        var sourceMap = this._sourceMapForUISourceCode.get(uiSourceCode);
+        var location = sourceMap.sourceLocationToCompiledLocation(uiSourceCode.url, lineNumber);
+        return WebInspector.debuggerModel.createRawLocation(this._scriptForSourceMap.get(sourceMap), location[0], location[1]);
+    },
+
+    /**
+     * @return {Array.<WebInspector.UISourceCode>}
+     */
+    uiSourceCodeList: function()
+    {
+        var result = []
+        for (var url in this._uiSourceCodeByURL)
+            result.push(this._uiSourceCodeByURL[url]);
+        return result;
+    },
+
+    /**
+     * @param {WebInspector.Script} script
+     */
+    addScript: function(script)
+    {
+        var sourceMap = this.loadSourceMapForScript(script);
+
+        if (this._scriptForSourceMap.get(sourceMap)) {
+            this._sourceMapForScriptId[script.scriptId] = sourceMap;
+            var data = { removedItems: [], addedItems: [], scriptIds: [script.scriptId] };
+            this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.UISourceCodeListChanged, data);
+            return;
+        }
+
+        var uiSourceCodeList = [];
+        var sourceURLs = sourceMap.sources();
+        for (var i = 0; i < sourceURLs.length; ++i) {
+            var sourceURL = sourceURLs[i];
+            if (this._uiSourceCodeByURL[sourceURL])
+                continue;
+            var contentProvider = new WebInspector.CompilerSourceMappingContentProvider(sourceURL, sourceMap);
+            var uiSourceCode = new WebInspector.UISourceCode(sourceURL, sourceURL, contentProvider);
+            uiSourceCode.isContentScript = script.isContentScript;
+            uiSourceCode.isEditable = false;
+            this._uiSourceCodeByURL[sourceURL] = uiSourceCode;
+            this._sourceMapForUISourceCode.put(uiSourceCode, sourceMap);
+            uiSourceCodeList.push(uiSourceCode);
+        }
+
+        this._sourceMapForScriptId[script.scriptId] = sourceMap;
+        this._scriptForSourceMap.put(sourceMap, script);
+        var data = { removedItems: [], addedItems: uiSourceCodeList, scriptIds: [script.scriptId] };
+        this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.UISourceCodeListChanged, data);
+    },
+
+    /**
+     * @param {WebInspector.Script} script
+     * @return {WebInspector.ClosureCompilerSourceMapping}
+     */
+    loadSourceMapForScript: function(script)
+    {
+        var sourceMapURL = WebInspector.ClosureCompilerSourceMapping.prototype._canonicalizeURL(script.sourceMapURL, script.sourceURL);
+        var sourceMap = this._sourceMapByURL[sourceMapURL];
+        if (sourceMap)
+            return sourceMap;
+
+        sourceMap = new WebInspector.ClosureCompilerSourceMapping(script.sourceMapURL, script.sourceURL);
+        if (!sourceMap.load())
+            return null;
+
+        this._sourceMapByURL[sourceMapURL] = sourceMap;
+        return sourceMap;
+    },
+
+    reset: function()
+    {
+        var data = { removedItems: this.uiSourceCodeList(), addedItems: [], scriptIds: [] };
+        this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.UISourceCodeListChanged, data);
+
+        this._sourceMapByURL = {};
+        this._sourceMapForScriptId = {};
+        this._scriptForSourceMap = new Map();
+        this._sourceMapForUISourceCode = new Map();
+        this._uiSourceCodeByURL = {};
+    }
+}
+
+WebInspector.CompilerScriptMapping.prototype.__proto__ = WebInspector.ScriptMapping.prototype;
index 4c04636..e41a9d1 100644 (file)
@@ -39,9 +39,8 @@
  * @param {WebInspector.Resource} resource
  * @param {WebInspector.ScriptFormatter} formatter
  * @param {boolean} formatted
- * @param {WebInspector.CompilerSourceMapping} compilerSourceMapping
  */
-WebInspector.RawSourceCode = function(id, script, resource, formatter, formatted, compilerSourceMapping)
+WebInspector.RawSourceCode = function(id, script, resource, formatter, formatted)
 {
     this.id = id;
     this.url = script.sourceURL;
@@ -49,10 +48,9 @@ WebInspector.RawSourceCode = function(id, script, resource, formatter, formatted
     this._scripts = [script];
     this._formatter = formatter;
     this._formatted = formatted;
-    this._compilerSourceMapping = compilerSourceMapping;
     this._resource = resource;
 
-    this._useTemporaryContent = !this._compilerSourceMapping && this._resource && !this._resource.finished;
+    this._useTemporaryContent = this._resource && !this._resource.finished;
     this._hasNewScripts = true;
     if (!this._useTemporaryContent)
         this._updateSourceMapping();
@@ -116,14 +114,11 @@ WebInspector.RawSourceCode.prototype = {
         if (this._formatted === formatted)
             return;
         this._formatted = formatted;
-        if (!this._compilerSourceMapping)
-            this._updateSourceMapping();
+        this._updateSourceMapping();
     },
 
     _resourceFinished: function()
     {
-        if (this._compilerSourceMapping)
-            return;
         this._useTemporaryContent = false;
         this._updateSourceMapping();
     },
@@ -178,26 +173,6 @@ WebInspector.RawSourceCode.prototype = {
      */
     _createSourceMapping: function(callback)
     {
-        if (this._compilerSourceMapping) {
-            var success = this._compilerSourceMapping.load();
-            if (!success) {
-                delete this._compilerSourceMapping;
-                callback(null);
-                return;
-            }
-            var uiSourceCodeList = [];
-            var sourceURLs = this._compilerSourceMapping.sources();
-            for (var i = 0; i < sourceURLs.length; ++i) {
-                var sourceURL = sourceURLs[i];
-                var contentProvider = new WebInspector.CompilerSourceMappingContentProvider(sourceURL, this._compilerSourceMapping);
-                var uiSourceCode = this._createUISourceCode(sourceURL, sourceURL, contentProvider);
-                uiSourceCodeList.push(uiSourceCode);
-            }
-            var sourceMapping = new WebInspector.RawSourceCode.CompilerSourceMapping(this, uiSourceCodeList, this._compilerSourceMapping);
-            callback(sourceMapping);
-            return;
-        }
-
         var originalContentProvider = this._createContentProvider();
         if (!this._formatted) {
             var uiSourceCode = this._createUISourceCode(this.url, this.url, originalContentProvider);
@@ -239,8 +214,7 @@ WebInspector.RawSourceCode.prototype = {
     {
         var uiSourceCode = new WebInspector.UISourceCode(id, url, contentProvider);
         uiSourceCode.isContentScript = this.isContentScript;
-        uiSourceCode.isEditable = this._scripts.length === 1 && !this._scripts[0].lineOffset && !this._scripts[0].columnOffset
-                                  && !this._formatted && !this._compilerSourceMapping;
+        uiSourceCode.isEditable = this._scripts.length === 1 && !this._scripts[0].lineOffset && !this._scripts[0].columnOffset && !this._formatted;
         return uiSourceCode;
     },
 
@@ -345,7 +319,7 @@ WebInspector.RawSourceCode.FormattedSourceMapping.prototype = {
      */
     rawLocationToUILocation: function(rawLocation)
     {
-        var location = this._mapping.originalToFormatted(rawLocation.lineNumber, rawLocation.columnNumber);
+        var location = this._mapping.originalToFormatted(rawLocation.lineNumber, rawLocation.columnNumber || 0);
         return new WebInspector.UILocation(this._uiSourceCodeList[0], location[0], location[1]);
     },
 
@@ -373,55 +347,6 @@ WebInspector.RawSourceCode.FormattedSourceMapping.prototype = {
 
 /**
  * @constructor
- * @implements {WebInspector.RawSourceCode.SourceMapping}
- * @param {WebInspector.RawSourceCode} rawSourceCode
- * @param {Array.<WebInspector.UISourceCode>} uiSourceCodeList
- * @param {WebInspector.CompilerSourceMapping} mapping
- */
-WebInspector.RawSourceCode.CompilerSourceMapping = function(rawSourceCode, uiSourceCodeList, mapping)
-{
-    this._rawSourceCode = rawSourceCode;
-    this._uiSourceCodeList = uiSourceCodeList;
-    this._mapping = mapping;
-    this._uiSourceCodeByURL = {};
-    for (var i = 0; i < uiSourceCodeList.length; ++i)
-        this._uiSourceCodeByURL[uiSourceCodeList[i].url] = uiSourceCodeList[i];
-}
-
-WebInspector.RawSourceCode.CompilerSourceMapping.prototype = {
-    /**
-     * @param {DebuggerAgent.Location} rawLocation
-     */
-    rawLocationToUILocation: function(rawLocation)
-    {
-        var location = this._mapping.compiledLocationToSourceLocation(rawLocation.lineNumber, rawLocation.columnNumber || 0);
-        var uiSourceCode = this._uiSourceCodeByURL[location.sourceURL];
-        return new WebInspector.UILocation(uiSourceCode, location.lineNumber, location.columnNumber);
-    },
-
-    /**
-     * @param {WebInspector.UISourceCode} uiSourceCode
-     * @param {number} lineNumber
-     * @param {number} columnNumber
-     * @return {DebuggerAgent.Location}
-     */
-    uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber)
-    {
-        var location = this._mapping.sourceLocationToCompiledLocation(uiSourceCode.url, lineNumber);
-        return WebInspector.debuggerModel.createRawLocation(this._rawSourceCode._scripts[0], location[0], location[1]);
-    },
-
-    /**
-     * @return {Array.<WebInspector.UISourceCode>}
-     */
-    uiSourceCodeList: function()
-    {
-        return this._uiSourceCodeList;
-    }
-}
-
-/**
- * @constructor
  * @param {WebInspector.UISourceCode} uiSourceCode
  * @param {number} lineNumber
  * @param {number} columnNumber
index 3796ff4..5405057 100644 (file)
@@ -100,11 +100,7 @@ WebInspector.ResourceScriptMapping.prototype = {
             }
         }
 
-        var compilerSourceMapping = null;
-        if (WebInspector.settings.sourceMapsEnabled.get() && script.sourceMapURL)
-            compilerSourceMapping = new WebInspector.ClosureCompilerSourceMapping(script.sourceMapURL, script.sourceURL);
-
-        var rawSourceCode = new WebInspector.RawSourceCode(script.scriptId, script, resource, this._formatter, this._formatSource, compilerSourceMapping);
+        var rawSourceCode = new WebInspector.RawSourceCode(script.scriptId, script, resource, this._formatter, this._formatSource);
         this._rawSourceCodes.push(rawSourceCode);
         this._bindScriptToRawSourceCode(script, rawSourceCode);
 
index 628725b..65a9c40 100644 (file)
@@ -70,9 +70,14 @@ WebInspector.ScriptMapping.prototype.__proto__ = WebInspector.Object.prototype;
 WebInspector.MainScriptMapping = function()
 {
     this._mappings = [];
-    
+
     this._resourceMapping = new WebInspector.ResourceScriptMapping();
     this._mappings.push(this._resourceMapping);
+    this._compilerMapping = new WebInspector.CompilerScriptMapping();
+    this._mappings.push(this._compilerMapping);
+
+    for (var i = 0; i < this._mappings.length; ++i)
+        this._mappings[i].addEventListener(WebInspector.ScriptMapping.Events.UISourceCodeListChanged, this._handleUISourceCodeListChanged, this);
 
     if (WebInspector.experimentsSettings.snippetsSupport.isEnabled()) {
         this._snippetsMapping = new WebInspector.SnippetsScriptMapping();
@@ -81,7 +86,7 @@ WebInspector.MainScriptMapping = function()
 
     for (var i = 0; i < this._mappings.length; ++i)
         this._mappings[i].addEventListener(WebInspector.ScriptMapping.Events.UISourceCodeListChanged, this._handleUISourceCodeListChanged, this);
-    
+
     this._mappingForScriptId = {};
     this._mappingForUISourceCode = new Map();
     this._liveLocationsForScriptId = {};
@@ -178,7 +183,12 @@ WebInspector.MainScriptMapping.prototype = {
             if (WebInspector.snippetsModel.snippetIdForSourceURL(script.sourceURL))
                 return this._snippetsMapping;
         }
-            
+
+        if (WebInspector.settings.sourceMapsEnabled.get() && script.sourceMapURL) {
+            if (this._compilerMapping.loadSourceMapForScript(script))
+                return this._compilerMapping;
+        }
+
         return this._resourceMapping;
     },
 
index a4264b3..4bb4672 100644 (file)
@@ -17,6 +17,7 @@
     <file>CallStackSidebarPane.js</file>
     <file>Checkbox.js</file>
     <file>Color.js</file>
+    <file>CompilerScriptMapping.js</file>
     <file>CompilerSourceMapping.js</file>
     <file>ConsoleMessage.js</file>
     <file>ConsoleModel.js</file>
index 73f1ec1..5a6dfcf 100644 (file)
@@ -175,6 +175,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     <script type="text/javascript" src="ContentProviders.js"></script>
     <script type="text/javascript" src="RawSourceCode.js"></script>
     <script type="text/javascript" src="ResourceScriptMapping.js"></script>
+    <script type="text/javascript" src="CompilerScriptMapping.js"></script>
     <script type="text/javascript" src="CompilerSourceMapping.js"></script>
     <script type="text/javascript" src="ScriptsSearchScope.js"></script>
     <script type="text/javascript" src="DOMAgent.js"></script>