Web Inspector: move resource loading logic from SourceMapParser to CompilerScriptMapping.
authorpodivilov@chromium.org <podivilov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 26 Mar 2012 09:55:15 +0000 (09:55 +0000)
committerpodivilov@chromium.org <podivilov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 26 Mar 2012 09:55:15 +0000 (09:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=81897

Reviewed by Vsevolod Vlasov.

Source/WebCore:

SourceMapParser should only deal with payload parsing.

* inspector/front-end/CompilerScriptMapping.js:
(WebInspector.CompilerScriptMapping.prototype.rawLocationToUILocation):
(WebInspector.CompilerScriptMapping.prototype.addScript):
(WebInspector.CompilerScriptMapping.prototype.loadSourceMapForScript):
(WebInspector.SourceMapPayload):
(WebInspector.SourceMapParser):
(WebInspector.SourceMapParser.prototype.sourceContent):
(WebInspector.SourceMapParser.prototype.findEntry):
(WebInspector.SourceMapParser.prototype.findEntryReversed):
* inspector/front-end/ContentProviders.js:
(WebInspector.CompilerSourceMappingContentProvider):
(WebInspector.CompilerSourceMappingContentProvider.prototype.requestContent):

LayoutTests:

* http/tests/inspector/compiler-script-mapping.html:

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

LayoutTests/ChangeLog
LayoutTests/http/tests/inspector/compiler-script-mapping.html
Source/WebCore/ChangeLog
Source/WebCore/inspector/front-end/CompilerScriptMapping.js
Source/WebCore/inspector/front-end/ContentProviders.js

index 7d045e7931af119baa3b720d2801aa3f5cad3a39..8a3fdd96542d27d34d0aaa479dbc1d454b62b820 100644 (file)
@@ -1,3 +1,12 @@
+2012-03-22  Pavel Podivilov  <podivilov@chromium.org>
+
+        Web Inspector: move resource loading logic from SourceMapParser to CompilerScriptMapping.
+        https://bugs.webkit.org/show_bug.cgi?id=81897
+
+        Reviewed by Vsevolod Vlasov.
+
+        * http/tests/inspector/compiler-script-mapping.html:
+
 2012-03-26  Pavel Feldman  <pfeldman@chromium.org>
 
         Reverting r112060, css3/selector3 expectations for chromium.
index bb7c93d57464be493a37a430ad48d200e009f6ec..fb557488533957eb8c5c5d061aafb7db549c0fd2 100644 (file)
@@ -9,17 +9,17 @@ function test()
 {
     function checkMapping(compiledLineNumber, compiledColumnNumber, sourceURL, sourceLineNumber, sourceColumnNumber, mapping)
     {
-        var sourceLocation = mapping.compiledLocationToSourceLocation(compiledLineNumber, compiledColumnNumber);
-        InspectorTest.assertEquals(sourceURL, sourceLocation.sourceURL);
-        InspectorTest.assertEquals(sourceLineNumber, sourceLocation.lineNumber);
-        InspectorTest.assertEquals(sourceColumnNumber, sourceLocation.columnNumber);
+        var entry = mapping.findEntry(compiledLineNumber, compiledColumnNumber);
+        InspectorTest.assertEquals(sourceURL, entry[2]);
+        InspectorTest.assertEquals(sourceLineNumber, entry[3]);
+        InspectorTest.assertEquals(sourceColumnNumber, entry[4]);
     }
 
     function checkReverseMapping(compiledLineNumber, compiledColumnNumber, sourceURL, sourceLineNumber, mapping)
     {
-        var compiledLocation = mapping.sourceLocationToCompiledLocation(sourceURL, sourceLineNumber);
-        InspectorTest.assertEquals(compiledLineNumber, compiledLocation[0]);
-        InspectorTest.assertEquals(compiledColumnNumber, compiledLocation[1]);
+        var entry = mapping.findEntryReversed(sourceURL, sourceLineNumber);
+        InspectorTest.assertEquals(compiledLineNumber, entry[0]);
+        InspectorTest.assertEquals(compiledColumnNumber, entry[1]);
     }
 
     InspectorTest.runTestSuite([
@@ -45,8 +45,7 @@ function test()
                 "mappings":"AAASA,QAAAA,IAAG,CAACC,CAAD,CAAaC,CAAb,CACZ,CACI,MAAOD,EAAP,CAAoBC,CADxB,CAIA,IAAIC,OAAS;",
                 "sources":["example.js"]
             };
-            var mapping = new WebInspector.SourceMapParser();
-            mapping._parseMappingPayload(mappingPayload);
+            var mapping = new WebInspector.SourceMapParser("source-map.json", mappingPayload);
 
             checkMapping(0, 9, "example.js", 0, 9, mapping);
             checkMapping(0, 13, "example.js", 0, 13, mapping);
@@ -60,7 +59,6 @@ function test()
             checkReverseMapping(0, 18, "example.js", 2, mapping);
             checkReverseMapping(0, 29, "example.js", 4, mapping);
             checkReverseMapping(0, 29, "example.js", 5, mapping);
-            InspectorTest.assertTrue(!mapping.sourceLocationToCompiledLocation("example.js", 6));
 
             next();
         },
@@ -71,8 +69,7 @@ function test()
                 "mappings":"AAAA,C,CAAE;",
                 "sources":["example.js"]
             };
-            var mapping = new WebInspector.SourceMapParser();
-            mapping._parseMappingPayload(mappingPayload);
+            var mapping = new WebInspector.SourceMapParser("source-map.json", mappingPayload);
             checkMapping(0, 0, "example.js", 0, 0, mapping);
             checkMapping(0, 2, "example.js", 0, 2, mapping);
             next();
@@ -84,8 +81,7 @@ function test()
                 "mappings":"AAAA;;;CACA",
                 "sources":["example.js"]
             };
-            var mapping = new WebInspector.SourceMapParser();
-            mapping._parseMappingPayload(mappingPayload);
+            var mapping = new WebInspector.SourceMapParser("source-map.json", mappingPayload);
             checkMapping(0, 0, "example.js", 0, 0, mapping);
             checkReverseMapping(3, 1, "example.js", 1, mapping);
             next();
@@ -108,8 +104,7 @@ function test()
                     }
                 }
             ]};
-            var mapping = new WebInspector.SourceMapParser();
-            mapping._parseMappingPayload(mappingPayload);
+            var mapping = new WebInspector.SourceMapParser("source-map.json", mappingPayload);
             InspectorTest.assertEquals(2, mapping.sources().length);
             checkMapping(0, 0, "source1.js", 0, 0, mapping);
             checkMapping(0, 1, "source1.js", 2, 1, mapping);
index ad71a3ac9c99cc9ddc877e112c59344a958a07e0..4b9dbabdd19a836b61ad177bc96bed3fd08db243 100644 (file)
@@ -1,3 +1,25 @@
+2012-03-22  Pavel Podivilov  <podivilov@chromium.org>
+
+        Web Inspector: move resource loading logic from SourceMapParser to CompilerScriptMapping.
+        https://bugs.webkit.org/show_bug.cgi?id=81897
+
+        Reviewed by Vsevolod Vlasov.
+
+        SourceMapParser should only deal with payload parsing.
+
+        * inspector/front-end/CompilerScriptMapping.js:
+        (WebInspector.CompilerScriptMapping.prototype.rawLocationToUILocation):
+        (WebInspector.CompilerScriptMapping.prototype.addScript):
+        (WebInspector.CompilerScriptMapping.prototype.loadSourceMapForScript):
+        (WebInspector.SourceMapPayload):
+        (WebInspector.SourceMapParser):
+        (WebInspector.SourceMapParser.prototype.sourceContent):
+        (WebInspector.SourceMapParser.prototype.findEntry):
+        (WebInspector.SourceMapParser.prototype.findEntryReversed):
+        * inspector/front-end/ContentProviders.js:
+        (WebInspector.CompilerSourceMappingContentProvider):
+        (WebInspector.CompilerSourceMappingContentProvider.prototype.requestContent):
+
 2012-03-26  Ilya Tikhonovsky  <loislo@chromium.org>
 
         Web Inspector: replace indexOf('a text') === 0 with RegExp because it is much faster.
index 782337c8240597fa7f5028cae3f7157133e2aa2f..0ed7dbf040d71b30f92cff4bac7ed9aed51e22e2 100644 (file)
@@ -49,9 +49,8 @@ WebInspector.CompilerScriptMapping.prototype = {
     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);
+        var entry = sourceMap.findEntry(rawLocation.lineNumber, rawLocation.columnNumber || 0);
+        return new WebInspector.UILocation(this._uiSourceCodeByURL[entry[2]], entry[3], entry[4]);
     },
 
     /**
@@ -63,8 +62,8 @@ WebInspector.CompilerScriptMapping.prototype = {
     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]);
+        var entry = sourceMap.findEntryReversed(uiSourceCode.url, lineNumber);
+        return WebInspector.debuggerModel.createRawLocation(this._scriptForSourceMap.get(sourceMap), entry[0], entry[1]);
     },
 
     /**
@@ -112,7 +111,12 @@ WebInspector.CompilerScriptMapping.prototype = {
             var sourceURL = sourceURLs[i];
             if (this._uiSourceCodeByURL[sourceURL])
                 continue;
-            var contentProvider = new WebInspector.CompilerSourceMappingContentProvider(sourceURL, sourceMap);
+            var sourceContent = sourceMap.sourceContent(sourceURL);
+            var contentProvider;
+            if (sourceContent)
+                contentProvider = new WebInspector.StaticContentProvider("text/javascript", sourceContent);
+            else
+                contentProvider = new WebInspector.CompilerSourceMappingContentProvider(sourceURL);
             var uiSourceCode = new WebInspector.UISourceCode(sourceURL, sourceURL, contentProvider);
             uiSourceCode.isContentScript = script.isContentScript;
             uiSourceCode.isEditable = false;
@@ -140,10 +144,17 @@ WebInspector.CompilerScriptMapping.prototype = {
         if (sourceMap)
             return sourceMap;
 
-        sourceMap = new WebInspector.SourceMapParser(script.sourceMapURL, script.sourceURL);
-        if (!sourceMap.load())
+        try {
+            // FIXME: make sendRequest async.
+            var response = InspectorFrontendHost.loadResourceSynchronously(sourceMapURL);
+            if (response.slice(0, 3) === ")]}")
+                response = response.substring(response.indexOf('\n'));
+            var payload = /** @type {WebInspector.SourceMapPayload} */ JSON.parse(response);
+            sourceMap = new WebInspector.SourceMapParser(sourceMapURL, payload);
+        } catch(e) {
+            console.error(e.message);
             return null;
-
+        }
         this._sourceMapByURL[sourceMapURL] = sourceMap;
         return sourceMap;
     },
@@ -166,8 +177,9 @@ WebInspector.CompilerScriptMapping.prototype.__proto__ = WebInspector.ScriptMapp
 /**
  * @constructor
  */
-WebInspector.SourceMapParserPayload = function()
+WebInspector.SourceMapPayload = function()
 {
+    this.sections = [];
     this.mappings = "";
     this.sourceRoot = "";
     this.sources = [];
@@ -178,9 +190,9 @@ WebInspector.SourceMapParserPayload = function()
  * for format description.
  * @constructor
  * @param {string} sourceMappingURL
- * @param {string} scriptSourceOrigin
+ * @param {WebInspector.SourceMapPayload} payload
  */
-WebInspector.SourceMapParser = function(sourceMappingURL, scriptSourceOrigin)
+WebInspector.SourceMapParser = function(sourceMappingURL, payload)
 {
     if (!WebInspector.SourceMapParser.prototype._base64Map) {
         const base64Digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@@ -189,52 +201,14 @@ WebInspector.SourceMapParser = function(sourceMappingURL, scriptSourceOrigin)
             WebInspector.SourceMapParser.prototype._base64Map[base64Digits.charAt(i)] = i;
     }
 
-    this._sourceMappingURL = this._canonicalizeURL(sourceMappingURL, scriptSourceOrigin);
+    this._sourceMappingURL = sourceMappingURL;
     this._mappings = [];
     this._reverseMappingsBySourceURL = {};
     this._sourceContentByURL = {};
+    this._parseMappingPayload(payload);
 }
 
 WebInspector.SourceMapParser.prototype = {
-    /**
-     * @return {boolean}
-     */
-    load: function()
-    {
-        try {
-            // FIXME: make sendRequest async.
-            var response = InspectorFrontendHost.loadResourceSynchronously(this._sourceMappingURL);
-            if (response.slice(0, 3) === ")]}")
-                response = response.substring(response.indexOf('\n'));
-            this._parseMappingPayload(JSON.parse(response));
-            return true
-        } catch(e) {
-            console.error(e.message);
-            return false;
-        }
-    },
-
-    /**
-     * @param {number} lineNumber
-     * @param {number} columnNumber
-     * @return {Object}
-     */
-    compiledLocationToSourceLocation: function(lineNumber, columnNumber)
-    {
-        var mapping = this._findMapping(lineNumber, columnNumber);
-        return { sourceURL: mapping[2], lineNumber: mapping[3], columnNumber: mapping[4] };
-    },
-
-    sourceLocationToCompiledLocation: function(sourceURL, lineNumber)
-    {
-        var mappings = this._reverseMappingsBySourceURL[sourceURL];
-        for ( ; lineNumber < mappings.length; ++lineNumber) {
-            var mapping = mappings[lineNumber];
-            if (mapping)
-                return [mapping[0], mapping[1]];
-        }
-    },
-
     /**
      * @return {Array.<string>}
      */
@@ -246,25 +220,12 @@ WebInspector.SourceMapParser.prototype = {
         return sources;
     },
 
-    /**
-     * @param {string} sourceURL
-     * @return {string}
-     */
-    loadSourceCode: function(sourceURL)
+    sourceContent: function(sourceURL)
     {
-        if (this._sourceContentByURL[sourceURL])
-            return this._sourceContentByURL[sourceURL];
-
-        try {
-            // FIXME: make sendRequest async.
-            return InspectorFrontendHost.loadResourceSynchronously(sourceURL);
-        } catch(e) {
-            console.error(e.message);
-            return "";
-        }
+        return this._sourceContentByURL[sourceURL];
     },
 
-    _findMapping: function(lineNumber, columnNumber)
+    findEntry: function(lineNumber, columnNumber)
     {
         var first = 0;
         var count = this._mappings.length;
@@ -282,6 +243,17 @@ WebInspector.SourceMapParser.prototype = {
         return this._mappings[first];
     },
 
+    findEntryReversed: function(sourceURL, lineNumber)
+    {
+        var mappings = this._reverseMappingsBySourceURL[sourceURL];
+        for ( ; lineNumber < mappings.length; ++lineNumber) {
+            var mapping = mappings[lineNumber];
+            if (mapping)
+                return mapping;
+        }
+        return this._mappings[0];
+    },
+
     _parseMappingPayload: function(mappingPayload)
     {
         if (mappingPayload.sections)
index 9f3736a3cfc5923c97d03563c6d4a0e94a447fcf..b8697166d089b7255391dbaf499a4253b11edb66 100644 (file)
@@ -243,11 +243,10 @@ WebInspector.ResourceContentProvider.prototype.__proto__ = WebInspector.ContentP
  * @constructor
  * @implements {WebInspector.ContentProvider}
  */
-WebInspector.CompilerSourceMappingContentProvider = function(sourceURL, compilerSourceMapping)
+WebInspector.CompilerSourceMappingContentProvider = function(sourceURL)
 {
     this._mimeType = "text/javascript";
     this._sourceURL = sourceURL;
-    this._compilerSourceMapping = compilerSourceMapping;
 }
 
 WebInspector.CompilerSourceMappingContentProvider.prototype = {
@@ -256,7 +255,13 @@ WebInspector.CompilerSourceMappingContentProvider.prototype = {
      */
     requestContent: function(callback)
     {
-        var sourceCode = this._compilerSourceMapping.loadSourceCode(this._sourceURL);
+        var sourceCode = "";
+        try {
+            // FIXME: make sendRequest async.
+            sourceCode = InspectorFrontendHost.loadResourceSynchronously(this._sourceURL);
+        } catch(e) {
+            console.error(e.message);
+        }
         callback(this._mimeType, sourceCode);
     },