Changeset 116398 in webkit


Ignore:
Timestamp:
May 7, 2012 11:56:55 PM (12 years ago)
Author:
pfeldman@chromium.org
Message:

Web Inspector: make JavaScriptSourceFrame use breakpoint manager's breakpoints store.
https://bugs.webkit.org/show_bug.cgi?id=85714

Reviewed by Yury Semikhatsky.

It is currently using its own copy of breakpoints which is not necessary.

  • inspector/front-end/BreakpointManager.js:

(WebInspector.BreakpointManager):
(WebInspector.BreakpointManager.prototype.restoreBreakpoints):
(WebInspector.BreakpointManager.prototype.setBreakpoint):
(WebInspector.BreakpointManager.prototype._innerSetBreakpoint):
(WebInspector.BreakpointManager.prototype.findBreakpoint):
(WebInspector.BreakpointManager.prototype.reset):
(WebInspector.BreakpointManager.prototype._debuggerReset):
(WebInspector.BreakpointManager.prototype._breakpointResolved):
(WebInspector.BreakpointManager.prototype._uiLocationAdded):
(WebInspector.BreakpointManager.prototype._uiLocationRemoved):
(WebInspector.BreakpointManager.Breakpoint.prototype._breakpointStorageId):
(WebInspector.BreakpointManager.Storage.prototype._restoreBreakpoints):
(set WebInspector.BreakpointManager.Storage.Item):

  • inspector/front-end/JavaScriptSource.js:

(WebInspector.JavaScriptSource.prototype.consoleMessagesCleared):
(WebInspector.JavaScriptSource.prototype.breakpointStorageId):

  • inspector/front-end/JavaScriptSourceFrame.js:

(WebInspector.JavaScriptSourceFrame):
(WebInspector.JavaScriptSourceFrame.prototype._onContentChanged):
(WebInspector.JavaScriptSourceFrame.prototype.populateLineGutterContextMenu):
(WebInspector.JavaScriptSourceFrame.prototype.beforeTextChanged):
(WebInspector.JavaScriptSourceFrame.prototype._onMouseDown):
(WebInspector.JavaScriptSourceFrame.prototype._breakpointAdded):
(WebInspector.JavaScriptSourceFrame.prototype._breakpointRemoved):
(WebInspector.JavaScriptSourceFrame.prototype.onTextViewerContentLoaded):
(WebInspector.JavaScriptSourceFrame.prototype._continueToLine):
(WebInspector.JavaScriptSourceFrame.prototype._updateBreakpointsAfterLiveEdit):

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/http/tests/inspector/debugger-test.js

    r116077 r116398  
    218218InspectorTest.removeBreakpoint = function(sourceFrame, lineNumber)
    219219{
    220     var breakpoint = sourceFrame._breakpoints[lineNumber];
    221     breakpoint.remove();
     220    sourceFrame._breakpointManager.findBreakpoint(sourceFrame._uiSourceCode, lineNumber).remove();
    222221};
    223222
  • trunk/Source/WebCore/ChangeLog

    r116397 r116398  
     12012-05-05  Pavel Feldman  <pfeldman@chromium.org>
     2
     3        Web Inspector: make JavaScriptSourceFrame use breakpoint manager's breakpoints store.
     4        https://bugs.webkit.org/show_bug.cgi?id=85714
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        It is currently using its own copy of breakpoints which is not necessary.
     9
     10        * inspector/front-end/BreakpointManager.js:
     11        (WebInspector.BreakpointManager):
     12        (WebInspector.BreakpointManager.prototype.restoreBreakpoints):
     13        (WebInspector.BreakpointManager.prototype.setBreakpoint):
     14        (WebInspector.BreakpointManager.prototype._innerSetBreakpoint):
     15        (WebInspector.BreakpointManager.prototype.findBreakpoint):
     16        (WebInspector.BreakpointManager.prototype.reset):
     17        (WebInspector.BreakpointManager.prototype._debuggerReset):
     18        (WebInspector.BreakpointManager.prototype._breakpointResolved):
     19        (WebInspector.BreakpointManager.prototype._uiLocationAdded):
     20        (WebInspector.BreakpointManager.prototype._uiLocationRemoved):
     21        (WebInspector.BreakpointManager.Breakpoint.prototype._breakpointStorageId):
     22        (WebInspector.BreakpointManager.Storage.prototype._restoreBreakpoints):
     23        (set WebInspector.BreakpointManager.Storage.Item):
     24        * inspector/front-end/JavaScriptSource.js:
     25        (WebInspector.JavaScriptSource.prototype.consoleMessagesCleared):
     26        (WebInspector.JavaScriptSource.prototype.breakpointStorageId):
     27        * inspector/front-end/JavaScriptSourceFrame.js:
     28        (WebInspector.JavaScriptSourceFrame):
     29        (WebInspector.JavaScriptSourceFrame.prototype._onContentChanged):
     30        (WebInspector.JavaScriptSourceFrame.prototype.populateLineGutterContextMenu):
     31        (WebInspector.JavaScriptSourceFrame.prototype.beforeTextChanged):
     32        (WebInspector.JavaScriptSourceFrame.prototype._onMouseDown):
     33        (WebInspector.JavaScriptSourceFrame.prototype._breakpointAdded):
     34        (WebInspector.JavaScriptSourceFrame.prototype._breakpointRemoved):
     35        (WebInspector.JavaScriptSourceFrame.prototype.onTextViewerContentLoaded):
     36        (WebInspector.JavaScriptSourceFrame.prototype._continueToLine):
     37        (WebInspector.JavaScriptSourceFrame.prototype._updateBreakpointsAfterLiveEdit):
     38
    1392012-05-07  Pavel Feldman  <pfeldman@chromium.org>
    240
  • trunk/Source/WebCore/inspector/front-end/BreakpointManager.js

    r116397 r116398  
    4444    this._breakpoints = [];
    4545    this._breakpointForDebuggerId = {};
    46     this._breakpointForUILocation = {};
    47     this._uiSourceCodeIds = {};
     46    this._breakpointsForUILocation = {};
     47    this._sourceFilesWithRestoredBreakpoints = {};
    4848
    4949    this._debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.BreakpointResolved, this._breakpointResolved, this);
     
    6262    restoreBreakpoints: function(uiSourceCode)
    6363    {
    64         if (!uiSourceCode.id || this._uiSourceCodeIds[uiSourceCode.id])
    65             return;
    66         this._uiSourceCodeIds[uiSourceCode.id] = true;
     64        var sourceFileId = uiSourceCode.breakpointStorageId();
     65        if (!sourceFileId || this._sourceFilesWithRestoredBreakpoints[sourceFileId])
     66            return;
     67        this._sourceFilesWithRestoredBreakpoints[sourceFileId] = true;
    6768
    6869        // Erase provisional breakpoints prior to restoring them.
     
    7475            delete this._breakpointForDebuggerId[debuggerId];
    7576        }
    76         this._storage.restoreBreakpoints(uiSourceCode);
     77        this._storage._restoreBreakpoints(uiSourceCode);
    7778    },
    7879
     
    8283     * @param {string} condition
    8384     * @param {boolean} enabled
    84      * @param {boolean=} doNotActivateBreakpoints
    8585     * @return {WebInspector.BreakpointManager.Breakpoint}
    8686     */
    87     setBreakpoint: function(uiSourceCode, lineNumber, condition, enabled, doNotActivateBreakpoints)
    88     {
    89         if (!doNotActivateBreakpoints)
    90             this._debuggerModel.setBreakpointsActive(true);
    91 
     87    setBreakpoint: function(uiSourceCode, lineNumber, condition, enabled)
     88    {
     89        this._debuggerModel.setBreakpointsActive(true);
     90        return this._innerSetBreakpoint(uiSourceCode, lineNumber, condition, enabled);
     91    },
     92
     93    /**
     94     * @param {WebInspector.UISourceCode} uiSourceCode
     95     * @param {number} lineNumber
     96     * @param {string} condition
     97     * @param {boolean} enabled
     98     * @return {WebInspector.BreakpointManager.Breakpoint}
     99     */
     100    _innerSetBreakpoint: function(uiSourceCode, lineNumber, condition, enabled)
     101    {
    92102        var breakpoint = this.findBreakpoint(uiSourceCode, lineNumber);
    93103        if (breakpoint) {
     
    107117    findBreakpoint: function(uiSourceCode, lineNumber)
    108118    {
    109         return this._breakpointForUILocation[uiSourceCode.id + ":" + lineNumber];
     119        var breakpoints = this._breakpointsForUILocation[uiSourceCode.id + ":" + lineNumber];
     120        return breakpoints ? breakpoints[0] : null;
    110121    },
    111122
     
    147158            this._debuggerModel.removeBreakpoint(debuggerId);
    148159        this._breakpointForDebuggerId = {};
    149         this._uiSourceCodeIds = {};
     160        this._sourceFilesWithRestoredBreakpoints = {};
    150161    },
    151162
     
    158169        }
    159170        this._breakpoints = [];
    160         this._breakpointForUILocation = {};
    161         this._uiSourceCodeIds = {};
     171        this._breakpointsForUILocation = {};
     172        this._sourceFilesWithRestoredBreakpoints = {};
    162173    },
    163174
     
    190201    _uiLocationAdded: function(breakpoint, uiLocation)
    191202    {
    192         this._breakpointForUILocation[uiLocation.uiSourceCode.id + ":" + uiLocation.lineNumber] = breakpoint;
     203        var key = uiLocation.uiSourceCode.id + ":" + uiLocation.lineNumber;
     204        var breakpoints = this._breakpointsForUILocation[key];
     205        if (!breakpoints) {
     206            breakpoints = [];
     207            this._breakpointsForUILocation[key] = breakpoints;
     208        }
     209        breakpoints.push(breakpoint);
    193210        this.dispatchEventToListeners(WebInspector.BreakpointManager.Events.BreakpointAdded, {breakpoint: breakpoint, uiLocation: uiLocation});
    194211    },
     
    200217    _uiLocationRemoved: function(breakpoint, uiLocation)
    201218    {
    202         delete this._breakpointForUILocation[uiLocation.uiSourceCode.id + ":" + uiLocation.lineNumber];
     219        var key = uiLocation.uiSourceCode.id + ":" + uiLocation.lineNumber;
     220        var breakpoints = this._breakpointsForUILocation[key];
     221        if (!breakpoints)
     222            return;
     223        breakpoints.remove(breakpoint);
     224        if (!breakpoints.length)
     225            delete this._breakpointsForUILocation[key];
    203226        this.dispatchEventToListeners(WebInspector.BreakpointManager.Events.BreakpointRemoved, {breakpoint: breakpoint, uiLocation: uiLocation});
    204227    }
     
    389412    _breakpointStorageId: function()
    390413    {
    391         return this._primaryUILocation.uiSourceCode.id + ":" + this._primaryUILocation.lineNumber;
     414        return this._primaryUILocation.uiSourceCode.breakpointStorageId() + ":" + this._primaryUILocation.lineNumber;
    392415    },
    393416
     
    422445     * @param {WebInspector.UISourceCode} uiSourceCode
    423446     */
    424     restoreBreakpoints: function(uiSourceCode)
     447    _restoreBreakpoints: function(uiSourceCode)
    425448    {
    426449        this._muted = true;
     450        var breakpointStorageId = uiSourceCode.breakpointStorageId();
    427451        for (var id in this._breakpoints) {
    428452            var breakpoint = this._breakpoints[id];
    429             if (breakpoint.sourceFileId === uiSourceCode.id)
    430                 this._breakpointManager.setBreakpoint(uiSourceCode, breakpoint.lineNumber, breakpoint.condition, breakpoint.enabled, true);
     453            if (breakpoint.sourceFileId === breakpointStorageId)
     454                this._breakpointManager._innerSetBreakpoint(uiSourceCode, breakpoint.lineNumber, breakpoint.condition, breakpoint.enabled);
    431455        }
    432456        delete this._muted;
     
    471495{
    472496    var primaryUILocation = breakpoint.primaryUILocation();
    473     this.sourceFileId = primaryUILocation.uiSourceCode.id;
     497    this.sourceFileId = primaryUILocation.uiSourceCode.breakpointStorageId();
    474498    this.lineNumber = primaryUILocation.lineNumber;
    475499    this.condition = breakpoint.condition();
  • trunk/Source/WebCore/inspector/front-end/JavaScriptSource.js

    r115961 r116398  
    6868        this._consoleMessages = [];
    6969        this.dispatchEventToListeners(WebInspector.UISourceCode.Events.ConsoleMessagesCleared);
     70    },
     71
     72    /**
     73     * @return {string}
     74     */
     75    breakpointStorageId: function()
     76    {
     77        return this.id;
    7078    }
    7179}
  • trunk/Source/WebCore/inspector/front-end/JavaScriptSourceFrame.js

    r115961 r116398  
    4242    this._breakpointManager = this._model.breakpointManager;
    4343    this._uiSourceCode = uiSourceCode;
    44     this._breakpoints = {};
    4544
    4645    var locations = this._breakpointManager.breakpointLocationsForUISourceCode(this._uiSourceCode);
     
    122121        var content = /** @type {string} */ event.data.content;
    123122
    124         var breakpoints = {};
    125         for (var lineNumber in this._breakpoints) {
    126             breakpoints[lineNumber] = this._breakpoints[lineNumber];
    127             this._breakpoints[lineNumber].remove();
    128         }
     123        var breakpointLocations = this._breakpointManager.breakpointLocationsForUISourceCode(this._uiSourceCode);
     124        for (var i = 0; i < breakpointLocations.length; ++i)
     125            breakpointLocations[i].breakpoint.remove();
    129126        this.setContent(content, false, "text/javascript");
    130         this._updateBreakpointsAfterLiveEdit(oldContent, content, breakpoints);
     127        this._updateBreakpointsAfterLiveEdit(oldContent, content, breakpointLocations);
    131128    },
    132129
     
    135132        contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Continue to here" : "Continue to Here"), this._continueToLine.bind(this, lineNumber));
    136133
    137         var breakpoint = this._breakpoints[lineNumber];
     134        var breakpoint = this._breakpointManager.findBreakpoint(this._uiSourceCode, lineNumber);
    138135        if (!breakpoint) {
    139136            // This row doesn't have a breakpoint: We want to show Add Breakpoint and Add and Edit Breakpoint.
     
    182179        if (!this._isDirty) {
    183180            // Disable all breakpoints in the model, store them as muted breakpoints.
    184             for (var lineNumber = 0; lineNumber < this.textModel.linesCount; ++lineNumber) {
    185                 var breakpointAttribute = this.textModel.getAttribute(lineNumber, "breakpoint");
    186                 if (breakpointAttribute) {
    187                     var breakpoint = this._breakpoints[lineNumber];
    188                     if (breakpoint)
    189                         breakpoint.remove();
    190                     // Re-adding decoration only.
    191                     this._addBreakpointDecoration(lineNumber, breakpointAttribute.condition, breakpointAttribute.enabled, true);
    192                 }
     181            var breakpointLocations = this._breakpointManager.breakpointLocationsForUISourceCode(this._uiSourceCode);
     182            var lineNumbers = {};
     183            for (var i = 0; i < breakpointLocations.length; ++i) {
     184                var breakpoint = breakpointLocations[i].breakpoint;
     185                breakpointLocations[i].breakpoint.remove();
     186                // Re-adding decoration only.
     187                this._addBreakpointDecoration(breakpointLocations[i].uiLocation.lineNumber, breakpoint.condition(), breakpoint.enabled(), true);
    193188            }
    194189        }
     
    388383        var lineNumber = target.lineNumber;
    389384
    390         var breakpoint = this._breakpoints[lineNumber];
     385        var breakpoint = this._breakpointManager.findBreakpoint(this._uiSourceCode, lineNumber);
    391386        if (breakpoint) {
    392387            if (event.shiftKey)
     
    504499
    505500        var breakpoint = /** @type {WebInspector.BreakpointManager.Breakpoint} */ event.data.breakpoint;
    506         this._breakpoints[uiLocation.lineNumber] = breakpoint;
    507501        if (this.loaded)
    508502            this._addBreakpointDecoration(uiLocation.lineNumber, breakpoint.condition(), breakpoint.enabled(), false);
     
    516510
    517511        var breakpoint = /** @type {WebInspector.BreakpointManager.Breakpoint} */ event.data.breakpoint;
    518         if (this._breakpoints[uiLocation.lineNumber] !== breakpoint)
    519             return;
    520         delete this._breakpoints[uiLocation.lineNumber];
    521         if (this.loaded)
     512        var remainingBreakpoint = this._breakpointManager.findBreakpoint(this._uiSourceCode, uiLocation.lineNumber);
     513        if (!remainingBreakpoint && this.loaded) {
    522514            this._removeBreakpointDecoration(uiLocation.lineNumber);
     515        }
    523516    },
    524517
     
    540533            this.setExecutionLine(this._executionLineNumber);
    541534
    542         for (var lineNumber in this._breakpoints) {
    543             var breakpoint = this._breakpoints[lineNumber];
    544             this._addBreakpointDecoration(parseInt(lineNumber, 10), breakpoint.condition(), breakpoint.enabled(), false);
     535        var breakpointLocations = this._breakpointManager.breakpointLocationsForUISourceCode(this._uiSourceCode);
     536        for (var i = 0; i < breakpointLocations.length; ++i) {
     537            var breakpoint = breakpointLocations[i].breakpoint;
     538            this._addBreakpointDecoration(breakpointLocations[i].uiLocation.lineNumber, breakpoint.condition(), breakpoint.enabled(), false);
    545539        }
    546540
     
    573567     * @param {string} oldSource
    574568     * @param {string} newSource
    575      * @param {Object.<string, WebInspector.BreakpointManager.Breakpoint>} breakpoints
    576      */
    577     _updateBreakpointsAfterLiveEdit: function(oldSource, newSource, breakpoints)
     569     * @param {Array.<Object>} breakpointLocations
     570     */
     571    _updateBreakpointsAfterLiveEdit: function(oldSource, newSource, breakpointLocations)
    578572    {
    579573        // Clear and re-create breakpoints according to text diff.
    580574        var diff = Array.diff(oldSource.split("\n"), newSource.split("\n"));
    581         for (var lineNumber in breakpoints) {
     575        for (var i = 0; i < breakpointLocations.length; ++i) {
     576            var lineNumber = breakpointLocations[i].uiLocation.lineNumber;
    582577            var newLineNumber = diff.left[lineNumber].row;
    583578            if (newLineNumber === undefined) {
     
    595590            }
    596591            if (newLineNumber !== undefined) {
    597                 var breakpoint = breakpoints[lineNumber];
     592                var breakpoint = breakpointLocations[i].breakpoint;
    598593                this._setBreakpoint(newLineNumber, breakpoint.condition(), breakpoint.enabled());
    599594            }
Note: See TracChangeset for help on using the changeset viewer.