Changeset 76132 in webkit


Ignore:
Timestamp:
Jan 19, 2011 9:57:36 AM (13 years ago)
Author:
podivilov@chromium.org
Message:

2011-01-18 Pavel Podivilov <podivilov@chromium.org>

Reviewed by Yury Semikhatsky.

Web Inspector: add UglifyJS parser and formatter files
https://bugs.webkit.org/show_bug.cgi?id=51702

  • WebCore.gypi:
  • WebCore.vcproj/WebCore.vcproj:
  • inspector/front-end/ScriptFormatter.js: (WebInspector.ScriptFormatter.positionToLocation): (WebInspector.ScriptFormatter.prototype.format.messageHandler): (WebInspector.ScriptFormatter.prototype.format): (WebInspector.ScriptFormatter.prototype._buildMapping): (WebInspector.ScriptFormatter.prototype._convertPosition):
  • inspector/front-end/SourceFrame.js: (WebInspector.SourceFrame.prototype.formatSource.didFormat): (WebInspector.SourceFrame.prototype.formatSource):
  • inspector/front-end/WebKit.qrc:
  • inspector/front-end/parse-js.js: Added. UglifyJS parser.
  • inspector/front-end/process.js: Added. UglifyJS formatter.
  • inspector/front-end/scriptFormatterWorker.js: Added. Worker script that wraps UglifyJS code. (onmessage): (beautify): (loadModule): (require):
  • inspector/front-end/utilities.js: ():
Location:
trunk/Source/WebCore
Files:
4 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r76129 r76132  
     12011-01-18  Pavel Podivilov  <podivilov@chromium.org>
     2
     3        Reviewed by Yury Semikhatsky.
     4
     5        Web Inspector: add UglifyJS parser and formatter files
     6        https://bugs.webkit.org/show_bug.cgi?id=51702
     7
     8        * WebCore.gypi:
     9        * WebCore.vcproj/WebCore.vcproj:
     10        * inspector/front-end/ScriptFormatter.js:
     11        (WebInspector.ScriptFormatter.positionToLocation):
     12        (WebInspector.ScriptFormatter.prototype.format.messageHandler):
     13        (WebInspector.ScriptFormatter.prototype.format):
     14        (WebInspector.ScriptFormatter.prototype._buildMapping):
     15        (WebInspector.ScriptFormatter.prototype._convertPosition):
     16        * inspector/front-end/SourceFrame.js:
     17        (WebInspector.SourceFrame.prototype.formatSource.didFormat):
     18        (WebInspector.SourceFrame.prototype.formatSource):
     19        * inspector/front-end/WebKit.qrc:
     20        * inspector/front-end/parse-js.js: Added. UglifyJS parser.
     21        * inspector/front-end/process.js: Added. UglifyJS formatter.
     22        * inspector/front-end/scriptFormatterWorker.js: Added. Worker script that wraps UglifyJS code.
     23        (onmessage):
     24        (beautify):
     25        (loadModule):
     26        (require):
     27        * inspector/front-end/utilities.js:
     28        ():
     29
    1302011-01-19  Pavel Podivilov  <podivilov@chromium.org>
    231
  • trunk/Source/WebCore/WebCore.gypi

    r76105 r76132  
    46794679            'inspector/front-end/Script.js',
    46804680            'inspector/front-end/ScriptFormatter.js',
     4681            'inspector/front-end/ScriptFormatterWorker.js',
    46814682            'inspector/front-end/ScriptsPanel.js',
    46824683            'inspector/front-end/ScriptView.js',
     
    47124713            'inspector/front-end/WelcomeView.js',
    47134714            'inspector/front-end/WorkersSidebarPane.js',
     4715            'inspector/front-end/UglifyJS/parse-js.js',
     4716            'inspector/front-end/UglifyJS/process.js',
    47144717            'inspector/front-end/audits.css',
    47154718            'inspector/front-end/goToLineDialog.css',
  • trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj

    r76105 r76132  
    6560265602                                </File>
    6560365603                                <File
     65604                                        RelativePath="..\inspector\front-end\scriptFormatterWorker.js"
     65605                                        >
     65606                                </File>
     65607                                <File
    6560465608                                        RelativePath="..\inspector\front-end\ScriptsPanel.js"
    6560565609                                        >
     
    6573565739                                <File
    6573665740                                        RelativePath="..\inspector\front-end\WorkersSidebarPane.js"
     65741                                        >
     65742                                </File>
     65743                                        <File
     65744                                        RelativePath="..\inspector\front-end\UglifyJS\parse-js.js"
     65745                                        >
     65746                                </File>
     65747                                        <File
     65748                                        RelativePath="..\inspector\front-end\UglifyJS\process.js"
    6573765749                                        >
    6573865750                                </File>
  • trunk/Source/WebCore/inspector/front-end/ScriptFormatter.js

    r76009 r76132  
    4545{
    4646    var location = {};
    47     location.line = WebInspector.ScriptFormatter.upperBound(lineEndings, position - 1);
     47    location.line = lineEndings.upperBound(position - 1);
    4848    if (!location.line)
    4949        location.column = position;
     
    5353}
    5454
    55 WebInspector.ScriptFormatter.upperBound = function(array, number)
    56 {
    57     var first = 0;
    58     var count = array.length;
    59     while (count > 0) {
    60       var step = count >> 1;
    61       var middle = first + step;
    62       if (number >= array[middle]) {
    63           first = middle + 1;
    64           count -= step + 1;
    65       } else
    66           count = step;
    67     }
    68     return first;
    69 }
     55WebInspector.ScriptFormatter.prototype = {
     56    format: function(callback)
     57    {
     58        var worker = new Worker("scriptFormatterWorker.js");
     59        function messageHandler(event)
     60        {
     61            var formattedSource = event.data;
     62            this._formatted = true;
     63            this._formattedSource = formattedSource;
     64            this._formattedLineEndings = formattedSource.findAll("\n");
     65            this._formattedLineEndings.push(formattedSource.length);
     66            this._buildMapping();
     67            callback(formattedSource);
     68        }
     69        worker.onmessage = messageHandler.bind(this);
     70        worker.postMessage(this._originalSource);
     71    },
    7072
    71 WebInspector.ScriptFormatter.prototype = {
    72     format: function()
     73    _buildMapping: function()
    7374    {
    74         this._formatted = true;
    75         this._formattedSource = this._originalSource.replace(/;/g, ";\n");
    76         this._formattedLineEndings = this._formattedSource.findAll("\n");
    77         this._formattedLineEndings.push(this._formattedSource.length);
    78 
    7975        this._originalSymbolPositions = [];
    8076        this._formattedSymbolPositions = [];
     
    9490        this._originalSymbolPositions.push(this._originalSource.length);
    9591        this._formattedSymbolPositions.push(this._formattedSource.length);
    96 
    97         return this._formattedSource;
    9892    },
    9993
     
    133127    _convertPosition: function(symbolPositions1, symbolPositions2, position)
    134128    {
    135         var index = WebInspector.ScriptFormatter.upperBound(symbolPositions1, position);
     129        var index = symbolPositions1.upperBound(position);
    136130        if (index === symbolPositions2.length - 1)
    137131            return symbolPositions2[index] - 1;
  • trunk/Source/WebCore/inspector/front-end/SourceFrame.js

    r76009 r76132  
    787787            return;
    788788
    789         this._textModel.setText(null, this._formatter.format());
    790         this._setTextViewerDecorations();
     789        function didFormat(source)
     790        {
     791            this._textModel.setText(null, source);
     792            this._setTextViewerDecorations();
     793        }
     794        this._formatter.format(didFormat.bind(this));
    791795    },
    792796
  • trunk/Source/WebCore/inspector/front-end/WebKit.qrc

    r76105 r76132  
    8282    <file>Script.js</file>
    8383    <file>ScriptFormatter.js</file>
     84    <file>ScriptFormatterWorker.js</file>
    8485    <file>ScriptsPanel.js</file>
    8586    <file>ScriptView.js</file>
     
    115116    <file>WelcomeView.js</file>
    116117    <file>WorkersSidebarPane.js</file>
     118    <file>UglifyJS/parse-js.js</file>
     119    <file>UglifyJS/process.js</file>
    117120    <file>audits.css</file>
    118121    <file>goToLineDialog.css</file>
  • trunk/Source/WebCore/inspector/front-end/utilities.js

    r75795 r76132  
    746746}});
    747747
     748Object.defineProperty(Array.prototype, "upperBound", { value: function(value)
     749{
     750    var first = 0;
     751    var count = this.length;
     752    while (count > 0) {
     753      var step = count >> 1;
     754      var middle = first + step;
     755      if (value >= this[middle]) {
     756          first = middle + 1;
     757          count -= step + 1;
     758      } else
     759          count = step;
     760    }
     761    return first;
     762}});
     763
    748764Array.diff = function(left, right)
    749765{
Note: See TracChangeset for help on using the changeset viewer.