Changeset 147099 in webkit


Ignore:
Timestamp:
Mar 28, 2013 5:34:16 AM (11 years ago)
Author:
vsevik@chromium.org
Message:

Web Inspector: Simplify ResourceScriptFile so that it stores hasDiverged state in it.
https://bugs.webkit.org/show_bug.cgi?id=113489

Reviewed by Pavel Feldman.

ResourceScriptFile._hasDiverged is the one flag that shows whether we have diverged from VM.
It's values is based both on dirty flag on uiSourceCode and information about live edit failures stored in _lastLiveEditFailed field.
Removed willMerge/Diverge events from ScriptFile.
JavaScriptSourceFrame now uses isMergingToVM/DivergingFromVM methods on ScriptFile.
to determine whether breakpointAdded/Removed events should be ignored.
Introduced muted state on JavaScriptSourceFrame to determine whether it should ignore user attempts to set/remove breakpoints.

  • inspector/front-end/JavaScriptSourceFrame.js:

(WebInspector.JavaScriptSourceFrame):
(WebInspector.JavaScriptSourceFrame.prototype._didMergeToVM):
(WebInspector.JavaScriptSourceFrame.prototype._didDivergeFromVM):
(WebInspector.JavaScriptSourceFrame.prototype._muteBreakpointsWhileEditing):
(WebInspector.JavaScriptSourceFrame.prototype._restoreBreakpointsAfterEditing):
(WebInspector.JavaScriptSourceFrame.prototype._addBreakpointDecoration):
(WebInspector.JavaScriptSourceFrame.prototype._removeBreakpointDecoration):
(WebInspector.JavaScriptSourceFrame.prototype._shouldIgnoreExternalBreakpointEvents):
(WebInspector.JavaScriptSourceFrame.prototype._breakpointAdded):
(WebInspector.JavaScriptSourceFrame.prototype._breakpointRemoved):
(WebInspector.JavaScriptSourceFrame.prototype._updateScriptFile):
(WebInspector.JavaScriptSourceFrame.prototype.onTextEditorContentLoaded):

  • inspector/front-end/LiveEditSupport.js:

(WebInspector.LiveEditScriptFile.prototype.isMergingToVM):

  • inspector/front-end/ResourceScriptMapping.js:

(WebInspector.ResourceScriptMapping.prototype.rawLocationToUILocation):
(WebInspector.ScriptFile.prototype.isMergingToVM):
(WebInspector.ResourceScriptFile):
(WebInspector.ResourceScriptFile.prototype._workingCopyCommitted):
(WebInspector.ResourceScriptFile.prototype._isDiverged):
(WebInspector.ResourceScriptFile.prototype._workingCopyChanged):
(WebInspector.ResourceScriptFile.prototype._update):
(WebInspector.ResourceScriptFile.prototype._divergeFromVM):
(WebInspector.ResourceScriptFile.prototype._mergeToVM):
(WebInspector.ResourceScriptFile.prototype.hasDivergedFromVM):
(WebInspector.ResourceScriptFile.prototype.isMergingToVM):

  • inspector/front-end/ScriptSnippetModel.js:

(WebInspector.SnippetScriptFile.prototype.isMergingToVM):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r147097 r147099  
     12013-03-28  Vsevolod Vlasov  <vsevik@chromium.org>
     2
     3        Web Inspector: Simplify ResourceScriptFile so that it stores hasDiverged state in it.
     4        https://bugs.webkit.org/show_bug.cgi?id=113489
     5
     6        Reviewed by Pavel Feldman.
     7
     8        ResourceScriptFile._hasDiverged is the one flag that shows whether we have diverged from VM.
     9        It's values is based both on dirty flag on uiSourceCode and information about live edit failures stored in _lastLiveEditFailed field.
     10        Removed willMerge/Diverge events from ScriptFile.
     11        JavaScriptSourceFrame now uses isMergingToVM/DivergingFromVM methods on ScriptFile.
     12        to determine whether breakpointAdded/Removed events should be ignored.
     13        Introduced muted state on JavaScriptSourceFrame to determine whether it should ignore user attempts to set/remove breakpoints.
     14
     15        * inspector/front-end/JavaScriptSourceFrame.js:
     16        (WebInspector.JavaScriptSourceFrame):
     17        (WebInspector.JavaScriptSourceFrame.prototype._didMergeToVM):
     18        (WebInspector.JavaScriptSourceFrame.prototype._didDivergeFromVM):
     19        (WebInspector.JavaScriptSourceFrame.prototype._muteBreakpointsWhileEditing):
     20        (WebInspector.JavaScriptSourceFrame.prototype._restoreBreakpointsAfterEditing):
     21        (WebInspector.JavaScriptSourceFrame.prototype._addBreakpointDecoration):
     22        (WebInspector.JavaScriptSourceFrame.prototype._removeBreakpointDecoration):
     23        (WebInspector.JavaScriptSourceFrame.prototype._shouldIgnoreExternalBreakpointEvents):
     24        (WebInspector.JavaScriptSourceFrame.prototype._breakpointAdded):
     25        (WebInspector.JavaScriptSourceFrame.prototype._breakpointRemoved):
     26        (WebInspector.JavaScriptSourceFrame.prototype._updateScriptFile):
     27        (WebInspector.JavaScriptSourceFrame.prototype.onTextEditorContentLoaded):
     28        * inspector/front-end/LiveEditSupport.js:
     29        (WebInspector.LiveEditScriptFile.prototype.isMergingToVM):
     30        * inspector/front-end/ResourceScriptMapping.js:
     31        (WebInspector.ResourceScriptMapping.prototype.rawLocationToUILocation):
     32        (WebInspector.ScriptFile.prototype.isMergingToVM):
     33        (WebInspector.ResourceScriptFile):
     34        (WebInspector.ResourceScriptFile.prototype._workingCopyCommitted):
     35        (WebInspector.ResourceScriptFile.prototype._isDiverged):
     36        (WebInspector.ResourceScriptFile.prototype._workingCopyChanged):
     37        (WebInspector.ResourceScriptFile.prototype._update):
     38        (WebInspector.ResourceScriptFile.prototype._divergeFromVM):
     39        (WebInspector.ResourceScriptFile.prototype._mergeToVM):
     40        (WebInspector.ResourceScriptFile.prototype.hasDivergedFromVM):
     41        (WebInspector.ResourceScriptFile.prototype.isMergingToVM):
     42        * inspector/front-end/ScriptSnippetModel.js:
     43        (WebInspector.SnippetScriptFile.prototype.isMergingToVM):
     44
    1452013-03-25  Andrey Kosyakov  <caseq@chromium.org>
    246
  • trunk/Source/WebCore/inspector/front-end/JavaScriptSourceFrame.js

    r146903 r147099  
    5959    this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.ConsoleMessagesCleared, this._consoleMessagesCleared, this);
    6060    this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.SourceMappingChanged, this._onSourceMappingChanged, this);
    61    
     61
    6262    this._updateScriptFile();
    6363}
     
    130130    },
    131131
    132     _willMergeToVM: function()
     132    _didMergeToVM: function()
    133133    {
    134134        if (this._supportsEnabledBreakpointsWhileEditing())
    135135            return;
    136         this._preserveDecorations = true;
    137     },
    138 
    139     _didMergeToVM: function()
     136        this._restoreBreakpointsAfterEditing();
     137    },
     138
     139    _didDivergeFromVM: function()
    140140    {
    141141        if (this._supportsEnabledBreakpointsWhileEditing())
    142142            return;
    143         delete this._preserveDecorations;
    144         this._restoreBreakpointsAfterEditing();
    145     },
    146 
    147     _willDivergeFromVM: function()
    148     {
    149         if (this._supportsEnabledBreakpointsWhileEditing())
    150             return;
    151         this._preserveDecorations = true;
    152     },
    153 
    154     _didDivergeFromVM: function()
    155     {
    156         if (this._supportsEnabledBreakpointsWhileEditing())
    157             return;
    158         delete this._preserveDecorations;
    159143        this._muteBreakpointsWhileEditing();
    160144    },
     
    162146    _muteBreakpointsWhileEditing: function()
    163147    {
     148        if (this._muted)
     149            return;
    164150        for (var lineNumber = 0; lineNumber < this._textEditor.linesCount; ++lineNumber) {
    165151            var breakpointDecoration = this._textEditor.getAttribute(lineNumber, "breakpoint");
     
    169155            this._addBreakpointDecoration(lineNumber, breakpointDecoration.condition, breakpointDecoration.enabled, true);
    170156        }
     157        this._muted = true;
    171158    },
    172159
     
    178165    _restoreBreakpointsAfterEditing: function()
    179166    {
     167        delete this._muted;
    180168        var breakpoints = {};
    181169        // Save and remove muted breakpoint decorations.
     
    312300    _addBreakpointDecoration: function(lineNumber, condition, enabled, mutedWhileEditing)
    313301    {
    314         if (this._preserveDecorations)
    315             return;
    316302        var breakpoint = {
    317303            condition: condition,
    318304            enabled: enabled
    319305        };
     306
    320307        this.textEditor.setAttribute(lineNumber, "breakpoint", breakpoint);
    321308
     
    326313    _removeBreakpointDecoration: function(lineNumber)
    327314    {
    328         if (this._preserveDecorations)
    329             return;
    330315        this.textEditor.removeAttribute(lineNumber, "breakpoint");
    331316        this.textEditor.removeBreakpoint(lineNumber);
     
    431416    },
    432417
     418    /**
     419     * @return {boolean}
     420     */
     421    _shouldIgnoreExternalBreakpointEvents: function()
     422    {
     423        if (this._supportsEnabledBreakpointsWhileEditing())
     424            return false;
     425        if (this._muted)
     426            return true;
     427        return this._scriptFile && (this._scriptFile.isDivergingFromVM() || this._scriptFile.isMergingToVM());
     428    },
     429
    433430    _breakpointAdded: function(event)
    434431    {
    435432        var uiLocation = /** @type {WebInspector.UILocation} */ (event.data.uiLocation);
    436 
    437433        if (uiLocation.uiSourceCode !== this._uiSourceCode)
     434            return;
     435        if (this._shouldIgnoreExternalBreakpointEvents())
    438436            return;
    439437
     
    447445        var uiLocation = /** @type {WebInspector.UILocation} */ (event.data.uiLocation);
    448446        if (uiLocation.uiSourceCode !== this._uiSourceCode)
     447            return;
     448        if (this._shouldIgnoreExternalBreakpointEvents())
    449449            return;
    450450
     
    485485    {
    486486        if (this._scriptFile) {
    487             this._scriptFile.removeEventListener(WebInspector.ScriptFile.Events.WillMergeToVM, this._willMergeToVM, this);
    488487            this._scriptFile.removeEventListener(WebInspector.ScriptFile.Events.DidMergeToVM, this._didMergeToVM, this);
    489             this._scriptFile.removeEventListener(WebInspector.ScriptFile.Events.WillDivergeFromVM, this._willDivergeFromVM, this);
    490488            this._scriptFile.removeEventListener(WebInspector.ScriptFile.Events.DidDivergeFromVM, this._didDivergeFromVM, this);
    491489        }
    492490        this._scriptFile = this._uiSourceCode.scriptFile();
    493491        if (this._scriptFile) {
    494             this._scriptFile.addEventListener(WebInspector.ScriptFile.Events.WillMergeToVM, this._willMergeToVM, this);
    495492            this._scriptFile.addEventListener(WebInspector.ScriptFile.Events.DidMergeToVM, this._didMergeToVM, this);
    496             this._scriptFile.addEventListener(WebInspector.ScriptFile.Events.WillDivergeFromVM, this._willDivergeFromVM, this);
    497493            this._scriptFile.addEventListener(WebInspector.ScriptFile.Events.DidDivergeFromVM, this._didDivergeFromVM, this);
    498494        }
     
    505501
    506502        var breakpointLocations = this._breakpointManager.breakpointLocationsForUISourceCode(this._uiSourceCode);
    507         for (var i = 0; i < breakpointLocations.length; ++i) {
    508             var breakpoint = breakpointLocations[i].breakpoint;
    509             this._addBreakpointDecoration(breakpointLocations[i].uiLocation.lineNumber, breakpoint.condition(), breakpoint.enabled(), false);
    510         }
     503        for (var i = 0; i < breakpointLocations.length; ++i)
     504            this._breakpointAdded({data:breakpointLocations[i]});
    511505
    512506        var messages = this._uiSourceCode.consoleMessages();
     
    522516    _handleGutterClick: function(event)
    523517    {
    524         if (this._uiSourceCode.isDirty() && !this._supportsEnabledBreakpointsWhileEditing())
     518        if (this._muted)
    525519            return;
    526520
     
    553547    toggleBreakpointOnCurrentLine: function()
    554548    {
    555         if (this._uiSourceCode.isDirty() && !this._supportsEnabledBreakpointsWhileEditing())
     549        if (this._muted)
    556550            return;
    557551
  • trunk/Source/WebCore/inspector/front-end/LiveEditSupport.js

    r142269 r147099  
    127127    },
    128128
     129    /**
     130     * @return {boolean}
     131     */
     132    isMergingToVM: function()
     133    {
     134        return false;
     135    },
     136
    129137    __proto__: WebInspector.Object.prototype
    130138}
  • trunk/Source/WebCore/inspector/front-end/ResourceScriptMapping.js

    r146983 r147099  
    5555        if (!uiSourceCode)
    5656            return null;
    57         if (uiSourceCode.scriptFile() && uiSourceCode.scriptFile().hasDivergedFromVM())
     57        var scriptFile = uiSourceCode.scriptFile();
     58        if (scriptFile && ((scriptFile.hasDivergedFromVM() && !scriptFile.isMergingToVM()) || scriptFile.isDivergingFromVM()))
    5859            return null;
    5960        return new WebInspector.UILocation(uiSourceCode, debuggerModelLocation.lineNumber, debuggerModelLocation.columnNumber || 0);
     
    243244
    244245WebInspector.ScriptFile.Events = {
    245     WillMergeToVM: "WillMergeToVM",
    246246    DidMergeToVM: "DidMergeToVM",
    247     WillDivergeFromVM: "WillDivergeFromVM",
    248247    DidDivergeFromVM: "DidDivergeFromVM",
    249248}
     
    259258     */
    260259    isDivergingFromVM: function() { return false; },
     260
     261    /**
     262     * @return {boolean}
     263     */
     264    isMergingToVM: function() { return false; },
    261265}
    262266
     
    273277    this._resourceScriptMapping = resourceScriptMapping;
    274278    this._uiSourceCode = uiSourceCode;
     279
    275280    this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._workingCopyCommitted, this);
    276281    this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._workingCopyChanged, this);
    277     this._maybeDirtyChanged(false);
     282    this._update();
    278283}
    279284
     
    287292        {
    288293            if (error) {
    289                 this._hasDivergedFromVM = true;
     294                this._lastLiveEditFailed = true;
    290295                WebInspector.showErrorMessage(error);
    291296                return;
    292297            }
    293 
    294             this.dispatchEventToListeners(WebInspector.ScriptFile.Events.WillMergeToVM, this);
    295             delete this._hasDivergedFromVM;
    296             this._resourceScriptMapping._hasMergedToVM(this._uiSourceCode);
    297             this.dispatchEventToListeners(WebInspector.ScriptFile.Events.DidMergeToVM, this);
     298           
     299            delete this._lastLiveEditFailed;
     300            this._mergeToVM();
    298301        }
    299 
     302       
    300303        var rawLocation = /** @type {WebInspector.DebuggerModel.Location} */ (this._uiSourceCode.uiLocationToRawLocation(0, 0));
    301304        if (!rawLocation)
     
    305308    },
    306309
     310    _isDiverged: function()
     311    {
     312        if (this._uiSourceCode.isDirty())
     313            return true;
     314        return this._lastLiveEditFailed;
     315    },
     316
    307317    _workingCopyChanged: function(event)
    308318    {
    309         var wasDirty = /** @type {boolean} */ (event.data.wasDirty);
    310         this._maybeDirtyChanged(wasDirty);
    311     },
    312 
    313     _maybeDirtyChanged: function(wasDirty)
    314     {
    315         if (!wasDirty && this._uiSourceCode.isDirty() && !this._hasDivergedFromVM) {
    316             this._isDivergingFromVM = true;
    317             this.dispatchEventToListeners(WebInspector.ScriptFile.Events.WillDivergeFromVM, this._uiSourceCode);
    318             this._resourceScriptMapping._hasDivergedFromVM(this._uiSourceCode);
    319             this.dispatchEventToListeners(WebInspector.ScriptFile.Events.DidDivergeFromVM, this._uiSourceCode);
    320             delete this._isDivergingFromVM;
    321         } else if (wasDirty && !this._uiSourceCode.isDirty() && !this._hasDivergedFromVM) {
    322             this.dispatchEventToListeners(WebInspector.ScriptFile.Events.WillMergeToVM, this._uiSourceCode);
    323             this._resourceScriptMapping._hasMergedToVM(this._uiSourceCode);
    324             this.dispatchEventToListeners(WebInspector.ScriptFile.Events.DidMergeToVM, this._uiSourceCode);
    325         }
     319        this._update();
     320    },
     321
     322    _update: function()
     323    {
     324        if (this._isDiverged() && !this._hasDivergedFromVM)
     325            this._divergeFromVM();
     326        else if (!this._isDiverged() && this._hasDivergedFromVM)
     327            this._mergeToVM();
     328    },
     329
     330    _divergeFromVM: function()
     331    {
     332        this._isDivergingFromVM = true;
     333        this._resourceScriptMapping._hasDivergedFromVM(this._uiSourceCode);
     334        delete this._isDivergingFromVM;
     335        this._hasDivergedFromVM = true;
     336        this.dispatchEventToListeners(WebInspector.ScriptFile.Events.DidDivergeFromVM, this._uiSourceCode);
     337    },
     338
     339    _mergeToVM: function()
     340    {
     341        delete this._hasDivergedFromVM;
     342        this._isMergingToVM = true;
     343        this._resourceScriptMapping._hasMergedToVM(this._uiSourceCode);
     344        delete this._isMergingToVM;
     345        this.dispatchEventToListeners(WebInspector.ScriptFile.Events.DidMergeToVM, this._uiSourceCode);
    326346    },
    327347
     
    331351    hasDivergedFromVM: function()
    332352    {
    333         return this._uiSourceCode.isDirty() || this._hasDivergedFromVM;
     353        return this._hasDivergedFromVM;
    334354    },
    335355
     
    340360    {
    341361        return this._isDivergingFromVM;
     362    },
     363
     364    /**
     365     * @return {boolean}
     366     */
     367    isMergingToVM: function()
     368    {
     369        return this._isMergingToVM;
    342370    },
    343371
  • trunk/Source/WebCore/inspector/front-end/ScriptSnippetModel.js

    r146983 r147099  
    435435
    436436    /**
     437     * @return {boolean}
     438     */
     439    isMergingToVM: function()
     440    {
     441        return false;
     442    },
     443
     444    /**
    437445     * @param {boolean} isDivergingFromVM
    438446     */
Note: See TracChangeset for help on using the changeset viewer.