Changeset 112070 in webkit


Ignore:
Timestamp:
Mar 26, 2012 2:55:15 AM (12 years ago)
Author:
podivilov@chromium.org
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:
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r112069 r112070  
     12012-03-22  Pavel Podivilov  <podivilov@chromium.org>
     2
     3        Web Inspector: move resource loading logic from SourceMapParser to CompilerScriptMapping.
     4        https://bugs.webkit.org/show_bug.cgi?id=81897
     5
     6        Reviewed by Vsevolod Vlasov.
     7
     8        * http/tests/inspector/compiler-script-mapping.html:
     9
    1102012-03-26  Pavel Feldman  <pfeldman@chromium.org>
    211
  • trunk/LayoutTests/http/tests/inspector/compiler-script-mapping.html

    r111655 r112070  
    1010    function checkMapping(compiledLineNumber, compiledColumnNumber, sourceURL, sourceLineNumber, sourceColumnNumber, mapping)
    1111    {
    12         var sourceLocation = mapping.compiledLocationToSourceLocation(compiledLineNumber, compiledColumnNumber);
    13         InspectorTest.assertEquals(sourceURL, sourceLocation.sourceURL);
    14         InspectorTest.assertEquals(sourceLineNumber, sourceLocation.lineNumber);
    15         InspectorTest.assertEquals(sourceColumnNumber, sourceLocation.columnNumber);
     12        var entry = mapping.findEntry(compiledLineNumber, compiledColumnNumber);
     13        InspectorTest.assertEquals(sourceURL, entry[2]);
     14        InspectorTest.assertEquals(sourceLineNumber, entry[3]);
     15        InspectorTest.assertEquals(sourceColumnNumber, entry[4]);
    1616    }
    1717
    1818    function checkReverseMapping(compiledLineNumber, compiledColumnNumber, sourceURL, sourceLineNumber, mapping)
    1919    {
    20         var compiledLocation = mapping.sourceLocationToCompiledLocation(sourceURL, sourceLineNumber);
    21         InspectorTest.assertEquals(compiledLineNumber, compiledLocation[0]);
    22         InspectorTest.assertEquals(compiledColumnNumber, compiledLocation[1]);
     20        var entry = mapping.findEntryReversed(sourceURL, sourceLineNumber);
     21        InspectorTest.assertEquals(compiledLineNumber, entry[0]);
     22        InspectorTest.assertEquals(compiledColumnNumber, entry[1]);
    2323    }
    2424
     
    4646                "sources":["example.js"]
    4747            };
    48             var mapping = new WebInspector.SourceMapParser();
    49             mapping._parseMappingPayload(mappingPayload);
     48            var mapping = new WebInspector.SourceMapParser("source-map.json", mappingPayload);
    5049
    5150            checkMapping(0, 9, "example.js", 0, 9, mapping);
     
    6160            checkReverseMapping(0, 29, "example.js", 4, mapping);
    6261            checkReverseMapping(0, 29, "example.js", 5, mapping);
    63             InspectorTest.assertTrue(!mapping.sourceLocationToCompiledLocation("example.js", 6));
    6462
    6563            next();
     
    7270                "sources":["example.js"]
    7371            };
    74             var mapping = new WebInspector.SourceMapParser();
    75             mapping._parseMappingPayload(mappingPayload);
     72            var mapping = new WebInspector.SourceMapParser("source-map.json", mappingPayload);
    7673            checkMapping(0, 0, "example.js", 0, 0, mapping);
    7774            checkMapping(0, 2, "example.js", 0, 2, mapping);
     
    8582                "sources":["example.js"]
    8683            };
    87             var mapping = new WebInspector.SourceMapParser();
    88             mapping._parseMappingPayload(mappingPayload);
     84            var mapping = new WebInspector.SourceMapParser("source-map.json", mappingPayload);
    8985            checkMapping(0, 0, "example.js", 0, 0, mapping);
    9086            checkReverseMapping(3, 1, "example.js", 1, mapping);
     
    109105                }
    110106            ]};
    111             var mapping = new WebInspector.SourceMapParser();
    112             mapping._parseMappingPayload(mappingPayload);
     107            var mapping = new WebInspector.SourceMapParser("source-map.json", mappingPayload);
    113108            InspectorTest.assertEquals(2, mapping.sources().length);
    114109            checkMapping(0, 0, "source1.js", 0, 0, mapping);
  • trunk/Source/WebCore/ChangeLog

    r112066 r112070  
     12012-03-22  Pavel Podivilov  <podivilov@chromium.org>
     2
     3        Web Inspector: move resource loading logic from SourceMapParser to CompilerScriptMapping.
     4        https://bugs.webkit.org/show_bug.cgi?id=81897
     5
     6        Reviewed by Vsevolod Vlasov.
     7
     8        SourceMapParser should only deal with payload parsing.
     9
     10        * inspector/front-end/CompilerScriptMapping.js:
     11        (WebInspector.CompilerScriptMapping.prototype.rawLocationToUILocation):
     12        (WebInspector.CompilerScriptMapping.prototype.addScript):
     13        (WebInspector.CompilerScriptMapping.prototype.loadSourceMapForScript):
     14        (WebInspector.SourceMapPayload):
     15        (WebInspector.SourceMapParser):
     16        (WebInspector.SourceMapParser.prototype.sourceContent):
     17        (WebInspector.SourceMapParser.prototype.findEntry):
     18        (WebInspector.SourceMapParser.prototype.findEntryReversed):
     19        * inspector/front-end/ContentProviders.js:
     20        (WebInspector.CompilerSourceMappingContentProvider):
     21        (WebInspector.CompilerSourceMappingContentProvider.prototype.requestContent):
     22
    1232012-03-26  Ilya Tikhonovsky  <loislo@chromium.org>
    224
  • trunk/Source/WebCore/inspector/front-end/CompilerScriptMapping.js

    r111694 r112070  
    5050    {
    5151        var sourceMap = this._sourceMapForScriptId[rawLocation.scriptId];
    52         var location = sourceMap.compiledLocationToSourceLocation(rawLocation.lineNumber, rawLocation.columnNumber || 0);
    53         var uiSourceCode = this._uiSourceCodeByURL[location.sourceURL];
    54         return new WebInspector.UILocation(uiSourceCode, location.lineNumber, location.columnNumber);
     52        var entry = sourceMap.findEntry(rawLocation.lineNumber, rawLocation.columnNumber || 0);
     53        return new WebInspector.UILocation(this._uiSourceCodeByURL[entry[2]], entry[3], entry[4]);
    5554    },
    5655
     
    6463    {
    6564        var sourceMap = this._sourceMapForUISourceCode.get(uiSourceCode);
    66         var location = sourceMap.sourceLocationToCompiledLocation(uiSourceCode.url, lineNumber);
    67         return WebInspector.debuggerModel.createRawLocation(this._scriptForSourceMap.get(sourceMap), location[0], location[1]);
     65        var entry = sourceMap.findEntryReversed(uiSourceCode.url, lineNumber);
     66        return WebInspector.debuggerModel.createRawLocation(this._scriptForSourceMap.get(sourceMap), entry[0], entry[1]);
    6867    },
    6968
     
    113112            if (this._uiSourceCodeByURL[sourceURL])
    114113                continue;
    115             var contentProvider = new WebInspector.CompilerSourceMappingContentProvider(sourceURL, sourceMap);
     114            var sourceContent = sourceMap.sourceContent(sourceURL);
     115            var contentProvider;
     116            if (sourceContent)
     117                contentProvider = new WebInspector.StaticContentProvider("text/javascript", sourceContent);
     118            else
     119                contentProvider = new WebInspector.CompilerSourceMappingContentProvider(sourceURL);
    116120            var uiSourceCode = new WebInspector.UISourceCode(sourceURL, sourceURL, contentProvider);
    117121            uiSourceCode.isContentScript = script.isContentScript;
     
    141145            return sourceMap;
    142146
    143         sourceMap = new WebInspector.SourceMapParser(script.sourceMapURL, script.sourceURL);
    144         if (!sourceMap.load())
     147        try {
     148            // FIXME: make sendRequest async.
     149            var response = InspectorFrontendHost.loadResourceSynchronously(sourceMapURL);
     150            if (response.slice(0, 3) === ")]}")
     151                response = response.substring(response.indexOf('\n'));
     152            var payload = /** @type {WebInspector.SourceMapPayload} */ JSON.parse(response);
     153            sourceMap = new WebInspector.SourceMapParser(sourceMapURL, payload);
     154        } catch(e) {
     155            console.error(e.message);
    145156            return null;
    146 
     157        }
    147158        this._sourceMapByURL[sourceMapURL] = sourceMap;
    148159        return sourceMap;
     
    167178 * @constructor
    168179 */
    169 WebInspector.SourceMapParserPayload = function()
     180WebInspector.SourceMapPayload = function()
    170181{
     182    this.sections = [];
    171183    this.mappings = "";
    172184    this.sourceRoot = "";
     
    179191 * @constructor
    180192 * @param {string} sourceMappingURL
    181  * @param {string} scriptSourceOrigin
    182  */
    183 WebInspector.SourceMapParser = function(sourceMappingURL, scriptSourceOrigin)
     193 * @param {WebInspector.SourceMapPayload} payload
     194 */
     195WebInspector.SourceMapParser = function(sourceMappingURL, payload)
    184196{
    185197    if (!WebInspector.SourceMapParser.prototype._base64Map) {
     
    190202    }
    191203
    192     this._sourceMappingURL = this._canonicalizeURL(sourceMappingURL, scriptSourceOrigin);
     204    this._sourceMappingURL = sourceMappingURL;
    193205    this._mappings = [];
    194206    this._reverseMappingsBySourceURL = {};
    195207    this._sourceContentByURL = {};
     208    this._parseMappingPayload(payload);
    196209}
    197210
    198211WebInspector.SourceMapParser.prototype = {
    199     /**
    200      * @return {boolean}
    201      */
    202     load: function()
    203     {
    204         try {
    205             // FIXME: make sendRequest async.
    206             var response = InspectorFrontendHost.loadResourceSynchronously(this._sourceMappingURL);
    207             if (response.slice(0, 3) === ")]}")
    208                 response = response.substring(response.indexOf('\n'));
    209             this._parseMappingPayload(JSON.parse(response));
    210             return true
    211         } catch(e) {
    212             console.error(e.message);
    213             return false;
    214         }
    215     },
    216 
    217     /**
    218      * @param {number} lineNumber
    219      * @param {number} columnNumber
    220      * @return {Object}
    221      */
    222     compiledLocationToSourceLocation: function(lineNumber, columnNumber)
    223     {
    224         var mapping = this._findMapping(lineNumber, columnNumber);
    225         return { sourceURL: mapping[2], lineNumber: mapping[3], columnNumber: mapping[4] };
    226     },
    227 
    228     sourceLocationToCompiledLocation: function(sourceURL, lineNumber)
    229     {
    230         var mappings = this._reverseMappingsBySourceURL[sourceURL];
    231         for ( ; lineNumber < mappings.length; ++lineNumber) {
    232             var mapping = mappings[lineNumber];
    233             if (mapping)
    234                 return [mapping[0], mapping[1]];
    235         }
    236     },
    237 
    238212    /**
    239213     * @return {Array.<string>}
     
    247221    },
    248222
    249     /**
    250      * @param {string} sourceURL
    251      * @return {string}
    252      */
    253     loadSourceCode: function(sourceURL)
    254     {
    255         if (this._sourceContentByURL[sourceURL])
    256             return this._sourceContentByURL[sourceURL];
    257 
    258         try {
    259             // FIXME: make sendRequest async.
    260             return InspectorFrontendHost.loadResourceSynchronously(sourceURL);
    261         } catch(e) {
    262             console.error(e.message);
    263             return "";
    264         }
    265     },
    266 
    267     _findMapping: function(lineNumber, columnNumber)
     223    sourceContent: function(sourceURL)
     224    {
     225        return this._sourceContentByURL[sourceURL];
     226    },
     227
     228    findEntry: function(lineNumber, columnNumber)
    268229    {
    269230        var first = 0;
     
    283244    },
    284245
     246    findEntryReversed: function(sourceURL, lineNumber)
     247    {
     248        var mappings = this._reverseMappingsBySourceURL[sourceURL];
     249        for ( ; lineNumber < mappings.length; ++lineNumber) {
     250            var mapping = mappings[lineNumber];
     251            if (mapping)
     252                return mapping;
     253        }
     254        return this._mappings[0];
     255    },
     256
    285257    _parseMappingPayload: function(mappingPayload)
    286258    {
  • trunk/Source/WebCore/inspector/front-end/ContentProviders.js

    r103711 r112070  
    244244 * @implements {WebInspector.ContentProvider}
    245245 */
    246 WebInspector.CompilerSourceMappingContentProvider = function(sourceURL, compilerSourceMapping)
     246WebInspector.CompilerSourceMappingContentProvider = function(sourceURL)
    247247{
    248248    this._mimeType = "text/javascript";
    249249    this._sourceURL = sourceURL;
    250     this._compilerSourceMapping = compilerSourceMapping;
    251250}
    252251
     
    257256    requestContent: function(callback)
    258257    {
    259         var sourceCode = this._compilerSourceMapping.loadSourceCode(this._sourceURL);
     258        var sourceCode = "";
     259        try {
     260            // FIXME: make sendRequest async.
     261            sourceCode = InspectorFrontendHost.loadResourceSynchronously(this._sourceURL);
     262        } catch(e) {
     263            console.error(e.message);
     264        }
    260265        callback(this._mimeType, sourceCode);
    261266    },
Note: See TracChangeset for help on using the changeset viewer.