Title: [112070] trunk
Revision
112070
Author
podivi...@chromium.org
Date
2012-03-26 02:55:15 -0700 (Mon, 26 Mar 2012)

Log Message

Web Inspector: move resource loading logic from SourceMapParser to CompilerScriptMapping.
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:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (112069 => 112070)


--- trunk/LayoutTests/ChangeLog	2012-03-26 09:36:39 UTC (rev 112069)
+++ trunk/LayoutTests/ChangeLog	2012-03-26 09:55:15 UTC (rev 112070)
@@ -1,3 +1,12 @@
+2012-03-22  Pavel Podivilov  <podivi...@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  <pfeld...@chromium.org>
 
         Reverting r112060, css3/selector3 expectations for chromium.

Modified: trunk/LayoutTests/http/tests/inspector/compiler-script-mapping.html (112069 => 112070)


--- trunk/LayoutTests/http/tests/inspector/compiler-script-mapping.html	2012-03-26 09:36:39 UTC (rev 112069)
+++ trunk/LayoutTests/http/tests/inspector/compiler-script-mapping.html	2012-03-26 09:55:15 UTC (rev 112070)
@@ -9,17 +9,17 @@
 {
     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 @@
                 "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 @@
             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 @@
                 "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 @@
                 "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 @@
                     }
                 }
             ]};
-            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);

Modified: trunk/Source/WebCore/ChangeLog (112069 => 112070)


--- trunk/Source/WebCore/ChangeLog	2012-03-26 09:36:39 UTC (rev 112069)
+++ trunk/Source/WebCore/ChangeLog	2012-03-26 09:55:15 UTC (rev 112070)
@@ -1,3 +1,25 @@
+2012-03-22  Pavel Podivilov  <podivi...@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  <loi...@chromium.org>
 
         Web Inspector: replace indexOf('a text') === 0 with RegExp because it is much faster.

Modified: trunk/Source/WebCore/inspector/front-end/CompilerScriptMapping.js (112069 => 112070)


--- trunk/Source/WebCore/inspector/front-end/CompilerScriptMapping.js	2012-03-26 09:36:39 UTC (rev 112069)
+++ trunk/Source/WebCore/inspector/front-end/CompilerScriptMapping.js	2012-03-26 09:55:15 UTC (rev 112070)
@@ -49,9 +49,8 @@
     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 @@
     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 @@
             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 @@
         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 @@
 /**
  * @constructor
  */
-WebInspector.SourceMapParserPayload = function()
+WebInspector.SourceMapPayload = function()
 {
+    this.sections = [];
     this.mappings = "";
     this.sourceRoot = "";
     this.sources = [];
@@ -178,9 +190,9 @@
  * 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,53 +201,15 @@
             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>}
      */
     sources: function()
@@ -246,25 +220,12 @@
         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 @@
         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)

Modified: trunk/Source/WebCore/inspector/front-end/ContentProviders.js (112069 => 112070)


--- trunk/Source/WebCore/inspector/front-end/ContentProviders.js	2012-03-26 09:36:39 UTC (rev 112069)
+++ trunk/Source/WebCore/inspector/front-end/ContentProviders.js	2012-03-26 09:55:15 UTC (rev 112070)
@@ -243,11 +243,10 @@
  * @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 @@
      */
     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);
     },
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to