Changeset 95524 in webkit


Ignore:
Timestamp:
Sep 20, 2011 3:22:59 AM (13 years ago)
Author:
podivilov@chromium.org
Message:

Web Inspector: implement reverse mapping for compiler source maps.
https://bugs.webkit.org/show_bug.cgi?id=67850

Source/WebCore:

Implement the mapping from source code to compiled code. It will be used for
setting breakpoints on source code.

Reviewed by Pavel Feldman.

  • inspector/front-end/CompilerSourceMapping.js:

(WebInspector.ClosureCompilerSourceMapping):
(WebInspector.ClosureCompilerSourceMapping.prototype.compiledLocationToSourceLocation):
(WebInspector.ClosureCompilerSourceMapping.prototype.sourceLocationToCompiledLocation):
(WebInspector.ClosureCompilerSourceMapping.prototype._parseMappings):

LayoutTests:

Reviewed by Pavel Feldman.

  • inspector/debugger/compiler-source-mapping.html:
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r95520 r95524  
     12011-09-09  Pavel Podivilov  <podivilov@chromium.org>
     2
     3        Web Inspector: implement reverse mapping for compiler source maps.
     4        https://bugs.webkit.org/show_bug.cgi?id=67850
     5
     6        Reviewed by Pavel Feldman.
     7
     8        * inspector/debugger/compiler-source-mapping.html:
     9
    1102011-09-20  Renata Hodovan  <reni@webkit.org>
    211
  • trunk/LayoutTests/inspector/debugger/compiler-source-mapping.html

    r94577 r95524  
    1515    }
    1616
     17    function checkReverseMapping(compiledLineNumber, compiledColumnNumber, sourceURL, sourceLineNumber, mapping)
     18    {
     19        var compiledLocation = mapping.sourceLocationToCompiledLocation(sourceURL, sourceLineNumber);
     20        InspectorTest.assertEquals(compiledLineNumber, compiledLocation.lineNumber);
     21        InspectorTest.assertEquals(compiledColumnNumber, compiledLocation.columnNumber);
     22    }
     23
    1724    InspectorTest.runTestSuite([
    1825        function testSimpleMapping(next)
    1926        {
    20             // example.js:
    21             // 0         1         2         3
    22             // 012345678901234567890123456789012345
    23             // function add(variable_x, variable_y)
    24             // {
    25             //     return variable_x + variable_y;
    26             // }
    27             // example-compiled.js:
    28             // 0         1         2         3
    29             // 012345678901234567890123456789012345
    30             // function add(a,b){return a+b};
     27            /*
     28                example.js:
     29                0         1         2         3
     30                012345678901234567890123456789012345
     31                function add(variable_x, variable_y)
     32                {
     33                    return variable_x + variable_y;
     34                }
     35
     36                var global = "foo";
     37                ----------------------------------------
     38                example-compiled.js:
     39                0         1         2         3
     40                012345678901234567890123456789012345
     41                function add(a,b){return a+b}var global="foo";
     42            */
    3143            var mappingPayload = {
    32                 "mappings":"AAASA,QAAAA,IAAG,CAACC,CAAD,CAAaC,CAAb,CACZ,CACI,MAAOD,EAAP,CAAoBC,CADxB;",
     44                "mappings":"AAASA,QAAAA,IAAG,CAACC,CAAD,CAAaC,CAAb,CACZ,CACI,MAAOD,EAAP,CAAoBC,CADxB,CAIA,IAAIC,OAAS;",
    3345                "sources":["example.js"]
    3446            };
    3547            var mapping = new WebInspector.ClosureCompilerSourceMapping(mappingPayload);
     48
    3649            checkMapping(0, 9, "example.js", 0, 9, mapping);
    3750            checkMapping(0, 13, "example.js", 0, 13, mapping);
     
    4053            checkMapping(0, 25, "example.js", 2, 11, mapping);
    4154            checkMapping(0, 27, "example.js", 2, 24, mapping);
     55
     56            checkReverseMapping(0, 0, "example.js", 0, mapping);
     57            checkReverseMapping(0, 17, "example.js", 1, mapping);
     58            checkReverseMapping(0, 18, "example.js", 2, mapping);
     59            checkReverseMapping(0, 29, "example.js", 4, mapping);
     60            checkReverseMapping(0, 29, "example.js", 5, mapping);
     61            InspectorTest.assertTrue(!mapping.sourceLocationToCompiledLocation("example.js", 6));
     62
    4263            next();
    4364        }
  • trunk/Source/WebCore/ChangeLog

    r95522 r95524  
     12011-09-09  Pavel Podivilov  <podivilov@chromium.org>
     2
     3        Web Inspector: implement reverse mapping for compiler source maps.
     4        https://bugs.webkit.org/show_bug.cgi?id=67850
     5
     6        Implement the mapping from source code to compiled code. It will be used for
     7        setting breakpoints on source code.
     8
     9        Reviewed by Pavel Feldman.
     10
     11        * inspector/front-end/CompilerSourceMapping.js:
     12        (WebInspector.ClosureCompilerSourceMapping):
     13        (WebInspector.ClosureCompilerSourceMapping.prototype.compiledLocationToSourceLocation):
     14        (WebInspector.ClosureCompilerSourceMapping.prototype.sourceLocationToCompiledLocation):
     15        (WebInspector.ClosureCompilerSourceMapping.prototype._parseMappings):
     16
    1172011-09-08  Pavel Podivilov  <podivilov@chromium.org>
    218
  • trunk/Source/WebCore/inspector/front-end/CompilerSourceMapping.js

    r94577 r95524  
    6969
    7070    this._sources = payload.sources;
    71     this._mappings = this._parsePayload(payload);
     71    this._mappings = [];
     72    this._reverseMappingsBySourceURL = {};
     73    for (var i = 0; i < this._sources.length; ++i)
     74        this._reverseMappingsBySourceURL[this._sources[i]] = [];
     75    this._parseMappings(payload.mappings);
    7276}
    7377
     
    7680    {
    7781        var mapping = this._findMapping(lineNumber, columnNumber);
    78         var sourceURL = this._sources[mapping[2]];
    79         return { sourceURL: sourceURL, lineNumber: mapping[3], columnNumber: mapping[4] };
    80     },
    81 
    82     sourceLocationToCompiledLocation: function(sourceURL, lineNumber, columnNumber)
    83     {
     82        return { sourceURL: mapping[2], lineNumber: mapping[3], columnNumber: mapping[4] };
     83    },
     84
     85    sourceLocationToCompiledLocation: function(sourceURL, lineNumber)
     86    {
     87        var mappings = this._reverseMappingsBySourceURL[sourceURL];
     88        for ( ; lineNumber < mappings.length; ++lineNumber) {
     89            var mapping = mappings[lineNumber];
     90            if (mapping)
     91                return { lineNumber: mapping[0], columnNumber: mapping[1] };
     92        }
    8493    },
    8594
     
    107116    },
    108117
    109     _parsePayload: function(payload)
    110     {
    111         var mappings = [];
    112         var stringCharIterator = new WebInspector.ClosureCompilerSourceMapping.StringCharIterator(payload.mappings);
     118    _parseMappings: function(mappingsPayload)
     119    {
     120        var stringCharIterator = new WebInspector.ClosureCompilerSourceMapping.StringCharIterator(mappingsPayload);
    113121
    114122        var lineNumber = 0;
     
    118126        var sourceColumnNumber = 0;
    119127        var nameIndex = 0;
     128
     129        var sourceURL = this._sources[0];
     130        var reverseMappings = this._reverseMappingsBySourceURL[sourceURL];
     131
    120132        do {
    121133            columnNumber += this._decodeVLQ(stringCharIterator);
    122134            if (this._isSeparator(stringCharIterator.peek()))
    123135                continue;
    124             sourceIndex += this._decodeVLQ(stringCharIterator);
     136            var sourceIndexDelta = this._decodeVLQ(stringCharIterator);
     137            if (sourceIndexDelta) {
     138                sourceIndex += sourceIndexDelta;
     139                sourceURL = this._sources[sourceIndex];
     140                reverseMappings = this._reverseMappingsBySourceURL[sourceURL];
     141            }
    125142            sourceLineNumber += this._decodeVLQ(stringCharIterator);
    126143            sourceColumnNumber += this._decodeVLQ(stringCharIterator);
    127             var mapping = [lineNumber, columnNumber, sourceIndex, sourceLineNumber, sourceColumnNumber];
    128             if (!this._isSeparator(stringCharIterator.peek())) {
     144            if (!this._isSeparator(stringCharIterator.peek()))
    129145                nameIndex += this._decodeVLQ(stringCharIterator);
    130                 mapping.push(nameIndex);
    131             }
    132             mappings.push(mapping);
     146
     147            this._mappings.push([lineNumber, columnNumber, sourceURL, sourceLineNumber, sourceColumnNumber]);
     148            if (!reverseMappings[sourceLineNumber])
     149                reverseMappings[sourceLineNumber] = [lineNumber, columnNumber];
     150
    133151            if (stringCharIterator.next() === ";") {
    134152                lineNumber += 1;
     
    136154            }
    137155        } while(stringCharIterator.hasNext());
    138         return mappings;
    139156    },
    140157
  • trunk/Source/WebCore/inspector/front-end/DebuggerPresentationModel.js

    r94762 r95524  
    174174        var rawSourceCode = uiSourceCode.rawSourceCode;
    175175        var script = this._scriptForRawSourceCode(rawSourceCode);
    176         return !script.lineOffset && !script.columnOffset;
     176        return script && !script.lineOffset && !script.columnOffset;
    177177    },
    178178
Note: See TracChangeset for help on using the changeset viewer.