Changeset 74119 in webkit


Ignore:
Timestamp:
Dec 15, 2010 9:36:04 AM (13 years ago)
Author:
podivilov@chromium.org
Message:

2010-12-13 Pavel Podivilov <podivilov@chromium.org>

Reviewed by Pavel Feldman.

Web Inspector: move scripts storage from ScriptsPanel to DebuggerModel.
https://bugs.webkit.org/show_bug.cgi?id=50908

  • inspector/front-end/BreakpointManager.js: (WebInspector.BreakpointManager): (WebInspector.BreakpointManager.prototype._debuggerPaused):
  • inspector/front-end/CallStackSidebarPane.js: (WebInspector.CallStackSidebarPane): (WebInspector.CallStackSidebarPane.prototype.update):
  • inspector/front-end/DebuggerModel.js: (WebInspector.DebuggerModel): (WebInspector.DebuggerModel.prototype.setBreakpoint): (WebInspector.DebuggerModel.prototype._setBreakpoint): (WebInspector.DebuggerModel.prototype.scriptForSourceID): (WebInspector.DebuggerModel.prototype.scriptsForURL): (WebInspector.DebuggerModel.prototype.queryScripts): (WebInspector.DebuggerModel.prototype.parsedScriptSource): (WebInspector.DebuggerModel.prototype.failedToParseScriptSource): (WebInspector.DebuggerModel.prototype.breakpointRestored): (WebInspector.DebuggerModel.prototype.debuggerPaused): (WebInspector.DebuggerModel.prototype.debuggerResumed):
  • inspector/front-end/Resource.js:
  • inspector/front-end/ScriptsPanel.js: (WebInspector.ScriptsPanel): eliminate sourceIDMap
  • inspector/front-end/SourceFrame.js: (WebInspector.SourceFrame.prototype._createViewerIfNeeded): (WebInspector.SourceFrame.prototype._setBreakpoint):
  • inspector/front-end/SourceView.js: (WebInspector.SourceView):
  • inspector/front-end/inspector.js: (WebInspector.createJSBreakpointsSidebarPane): (WebInspector.parsedScriptSource): (WebInspector.failedToParseScriptSource):
Location:
trunk/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r74118 r74119  
     12010-12-13  Pavel Podivilov  <podivilov@chromium.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        Web Inspector: move scripts storage from ScriptsPanel to DebuggerModel.
     6        https://bugs.webkit.org/show_bug.cgi?id=50908
     7
     8        * inspector/front-end/BreakpointManager.js:
     9        (WebInspector.BreakpointManager):
     10        (WebInspector.BreakpointManager.prototype._debuggerPaused):
     11        * inspector/front-end/CallStackSidebarPane.js:
     12        (WebInspector.CallStackSidebarPane):
     13        (WebInspector.CallStackSidebarPane.prototype.update):
     14        * inspector/front-end/DebuggerModel.js:
     15        (WebInspector.DebuggerModel):
     16        (WebInspector.DebuggerModel.prototype.setBreakpoint):
     17        (WebInspector.DebuggerModel.prototype._setBreakpoint):
     18        (WebInspector.DebuggerModel.prototype.scriptForSourceID):
     19        (WebInspector.DebuggerModel.prototype.scriptsForURL):
     20        (WebInspector.DebuggerModel.prototype.queryScripts):
     21        (WebInspector.DebuggerModel.prototype.parsedScriptSource):
     22        (WebInspector.DebuggerModel.prototype.failedToParseScriptSource):
     23        (WebInspector.DebuggerModel.prototype.breakpointRestored):
     24        (WebInspector.DebuggerModel.prototype.debuggerPaused):
     25        (WebInspector.DebuggerModel.prototype.debuggerResumed):
     26        * inspector/front-end/Resource.js:
     27        * inspector/front-end/ScriptsPanel.js:
     28        (WebInspector.ScriptsPanel): eliminate sourceIDMap
     29        * inspector/front-end/SourceFrame.js:
     30        (WebInspector.SourceFrame.prototype._createViewerIfNeeded):
     31        (WebInspector.SourceFrame.prototype._setBreakpoint):
     32        * inspector/front-end/SourceView.js:
     33        (WebInspector.SourceView):
     34        * inspector/front-end/inspector.js:
     35        (WebInspector.createJSBreakpointsSidebarPane):
     36        (WebInspector.parsedScriptSource):
     37        (WebInspector.failedToParseScriptSource):
     38
    1392010-12-15  Eric Carlson  <eric.carlson@apple.com>
    240
  • trunk/WebCore/inspector/front-end/BreakpointManager.js

    r74103 r74119  
    4141
    4242    WebInspector.settings.addEventListener(WebInspector.Settings.Events.ProjectChanged, this._projectChanged, this);
    43     WebInspector.debuggerModel.addEventListener("native-breakpoint-hit", this._nativeBreakpointHit, this);
    44     WebInspector.debuggerModel.addEventListener("debugger-resumed", this._debuggerResumed, this);
     43    WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.DebuggerPaused, this._debuggerPaused, this);
     44    WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.DebuggerResumed, this._debuggerResumed, this);
    4545}
    4646
     
    153153    },
    154154
    155     _nativeBreakpointHit: function(event)
    156     {
    157         var eventData = event.data;
     155    _debuggerPaused: function(event)
     156    {
     157        var eventType = event.data.eventType;
     158        var eventData = event.data.eventData;
     159
     160        if (eventType !== WebInspector.DebuggerEventTypes.NativeBreakpoint)
     161            return;
    158162
    159163        var breakpointId;
  • trunk/WebCore/inspector/front-end/CallStackSidebarPane.js

    r74103 r74119  
    2828    WebInspector.SidebarPane.call(this, WebInspector.UIString("Call Stack"));
    2929    WebInspector.breakpointManager.addEventListener(WebInspector.BreakpointManager.Events.NativeBreakpointHit, this._nativeBreakpointHit, this);
    30     WebInspector.debuggerModel.addEventListener("script-breakpoint-hit", this._scriptBreakpointHit, this);
     30    WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.BreakpointHit, this._scriptBreakpointHit, this);
    3131}
    3232
    3333WebInspector.CallStackSidebarPane.prototype = {
    34     update: function(callFrames, sourceIDMap)
     34    update: function(callFrames)
    3535    {
    3636        this.bodyElement.removeChildren();
     
    4949        var title;
    5050        var subtitle;
    51         var scriptOrResource;
     51        var script;
    5252
    5353        for (var i = 0; i < callFrames.length; ++i) {
     
    6262            }
    6363
    64             scriptOrResource = sourceIDMap[callFrame.sourceID];
    65             if (scriptOrResource)
    66                 subtitle = WebInspector.displayNameForURL(scriptOrResource.sourceURL || scriptOrResource.url);
     64            script = WebInspector.debuggerModel.scriptForSourceID(callFrame.sourceID);
     65            if (script)
     66                subtitle = WebInspector.displayNameForURL(script.sourceURL);
    6767            else
    6868                subtitle = WebInspector.UIString("(internal script)");
  • trunk/WebCore/inspector/front-end/DebuggerModel.js

    r73916 r74119  
    3131WebInspector.DebuggerModel = function()
    3232{
     33    InspectorBackend.registerDomainDispatcher("Debugger", this);
     34
    3335    this._breakpoints = {};
    34     InspectorBackend.registerDomainDispatcher("Debugger", this);
     36    this._scripts = {};
     37}
     38
     39WebInspector.DebuggerModel.Events = {
     40    DebuggerPaused: "debugger-paused",
     41    DebuggerResumed: "debugger-resumed",
     42    ParsedScriptSource: "parsed-script-source",
     43    FailedToParseScriptSource: "failed-to-parse-script-source",
     44    BreakpointAdded: "breakpoint-added",
     45    BreakpointHit: "breakpoint-hit"
    3546}
    3647
     
    5667    },
    5768
    58     setBreakpoint: function(sourceID, url, line, enabled, condition)
    59     {
     69    setBreakpoint: function(sourceID, line, enabled, condition)
     70    {
     71        var url = this._scripts[sourceID].sourceURL;
    6072        var breakpoint = this._setBreakpoint(sourceID, url, line, enabled, condition);
    6173        if (breakpoint)
    6274            this._setBreakpointOnBackend(breakpoint);
    63     },
    64 
    65     breakpointRestored: function(sourceID, url, line, enabled, condition)
    66     {
    67         this._setBreakpoint(sourceID, url, line, enabled, condition);
    6875    },
    6976
     
    8996        this._breakpoints = {};
    9097        delete this._oneTimeBreakpoint;
     98        this._scripts = {};
    9199    },
    92100
     
    100108        this._breakpoints[breakpoint.id] = breakpoint;
    101109        breakpoint.addEventListener("removed", this._breakpointRemoved, this);
    102         this.dispatchEventToListeners("breakpoint-added", breakpoint);
     110        this.dispatchEventToListeners(WebInspector.DebuggerModel.Events.BreakpointAdded, breakpoint);
    103111        return breakpoint;
    104112    },
     
    129137    },
    130138
     139    scriptForSourceID: function(sourceID)
     140    {
     141        return this._scripts[sourceID];
     142    },
     143
     144    scriptsForURL: function(url)
     145    {
     146        return this.queryScripts(function(s) { return s.sourceURL === url; });
     147    },
     148
     149    queryScripts: function(filter)
     150    {
     151        var scripts = [];
     152        for (var sourceID in this._scripts) {
     153            var script = this._scripts[sourceID];
     154            if (filter(script))
     155                scripts.push(script);
     156        }
     157        return scripts;
     158    },
     159
     160    // All the methods below are InspectorBackend notification handlers.
     161
     162    breakpointRestored: function(sourceID, url, line, enabled, condition)
     163    {
     164        this._setBreakpoint(sourceID, url, line, enabled, condition);
     165    },
     166
    131167    pausedScript: function(details)
    132168    {
    133         this.dispatchEventToListeners("debugger-paused", details.callFrames);
    134 
    135         if (details.eventType === WebInspector.DebuggerEventTypes.JavaScriptPause)
    136             return;
    137         if (details.eventType === WebInspector.DebuggerEventTypes.NativeBreakpoint) {
    138             this.dispatchEventToListeners("native-breakpoint-hit", details.eventData);
    139             return;
    140         }
     169        this.dispatchEventToListeners(WebInspector.DebuggerModel.Events.DebuggerPaused, details);
     170
     171        if (details.eventType === WebInspector.DebuggerEventTypes.JavaScriptPause || details.eventType === WebInspector.DebuggerEventTypes.NativeBreakpoint)
     172            return;
    141173
    142174        var breakpointId = WebInspector.Breakpoint.jsBreakpointId(details.callFrames[0].sourceID, details.callFrames[0].line);
     
    146178        breakpoint.hit = true;
    147179        this._lastHitBreakpoint = breakpoint;
    148         this.dispatchEventToListeners("script-breakpoint-hit", breakpoint);
     180        this.dispatchEventToListeners(WebInspector.DebuggerModel.Events.BreakpointHit, breakpoint);
    149181    },
    150182
    151183    resumedScript: function()
    152184    {
    153         this.dispatchEventToListeners("debugger-resumed");
     185        this.dispatchEventToListeners(WebInspector.DebuggerModel.Events.DebuggerResumed);
    154186
    155187        if (!this._lastHitBreakpoint)
     
    176208    parsedScriptSource: function(sourceID, sourceURL, source, startingLine, scriptWorldType)
    177209    {
    178         WebInspector.panels.scripts.addScript(sourceID, sourceURL, source, startingLine, undefined, undefined, scriptWorldType);
     210        var script = new WebInspector.Script(sourceID, sourceURL, source, startingLine, undefined, undefined, scriptWorldType);
     211        this._scripts[sourceID] = script;
     212        this.dispatchEventToListeners(WebInspector.DebuggerModel.Events.ParsedScriptSource, sourceID);
    179213    },
    180214
    181215    failedToParseScriptSource: function(sourceURL, source, startingLine, errorLine, errorMessage)
    182216    {
    183         WebInspector.panels.scripts.addScript(null, sourceURL, source, startingLine, errorLine, errorMessage);
     217        var script = new WebInspector.Script(null, sourceURL, source, startingLine, errorLine, errorMessage, undefined);
     218        this.dispatchEventToListeners(WebInspector.DebuggerModel.Events.FailedToParseScriptSource, script);
    184219    },
    185220
  • trunk/WebCore/inspector/front-end/Resource.js

    r73504 r74119  
    498498    },
    499499
    500     get scripts()
    501     {
    502         if (!("_scripts" in this))
    503             this._scripts = [];
    504         return this._scripts;
    505     },
    506 
    507     addScript: function(script)
    508     {
    509         if (!script)
    510             return;
    511         this.scripts.unshift(script);
    512         script.resource = this;
    513     },
    514 
    515     removeAllScripts: function()
    516     {
    517         if (!this._scripts)
    518             return;
    519 
    520         for (var i = 0; i < this._scripts.length; ++i) {
    521             if (this._scripts[i].resource === this)
    522                 delete this._scripts[i].resource;
    523         }
    524 
    525         delete this._scripts;
    526     },
    527 
    528     removeScript: function(script)
    529     {
    530         if (!script)
    531             return;
    532 
    533         if (script.resource === this)
    534             delete script.resource;
    535 
    536         if (!this._scripts)
    537             return;
    538 
    539         this._scripts.remove(script);
    540     },
    541 
    542500    get errors()
    543501    {
  • trunk/WebCore/inspector/front-end/ScriptsPanel.js

    r74103 r74119  
    178178    this.reset();
    179179
    180     WebInspector.debuggerModel.addEventListener("debugger-paused", this._debuggerPaused, this);
    181     WebInspector.debuggerModel.addEventListener("debugger-resumed", this._debuggerResumed, this);
     180    WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.ParsedScriptSource, this._parsedScriptSource, this);
     181    WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.FailedToParseScriptSource, this._failedToParseScriptSource, this);
     182    WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.DebuggerPaused, this._debuggerPaused, this);
     183    WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.DebuggerResumed, this._debuggerResumed, this);
    182184}
    183185
     
    236238    },
    237239
    238     addScript: function(sourceID, sourceURL, source, startingLine, errorLine, errorMessage, scriptWorldType)
    239     {
    240         var script = new WebInspector.Script(sourceID, sourceURL, source, startingLine, errorLine, errorMessage, scriptWorldType);
    241         this._sourceIDMap[sourceID] = script;
    242 
    243         var resource = WebInspector.resourceForURL(sourceURL);
     240    _parsedScriptSource: function(event)
     241    {
     242        var sourceID = event.data;
     243        var script = WebInspector.debuggerModel.scriptForSourceID(sourceID);
     244        this._addScript(script);
     245    },
     246
     247    _failedToParseScriptSource: function(event)
     248    {
     249        this._addScript(event.data);
     250    },
     251
     252    _addScript: function(script)
     253    {
     254        var resource = WebInspector.resourceForURL(script.sourceURL);
    244255        if (resource) {
    245256            if (resource.finished) {
    246257                // Resource is finished, bind the script right away.
    247                 resource.addScript(script);
    248                 this._sourceIDMap[sourceID] = resource;
     258                script.resource = resource;
    249259            } else {
    250260                // Resource is not finished, bind the script later.
     
    272282            // Bind script to resource.
    273283            var script = resource._scriptsPendingResourceLoad[i];
    274             resource.addScript(script);
    275             this._sourceIDMap[script.sourceID] = resource;
     284            script.resource = resource;
    276285
    277286            // Remove script from the files list.
     
    303312                commitEditingCallback(newBodyOrErrorMessage);
    304313                if (callFrames && callFrames.length)
    305                     this._debuggerPaused({ data: callFrames });
     314                    this._debuggerPaused({ data: { callFrames: callFrames } });
    306315            } else {
    307316                if (cancelEditingCallback)
     
    314323                if (success && breakpoint.line >= editData.line)
    315324                    newLine += editData.linesCountToShift;
    316                 WebInspector.debuggerModel.setBreakpoint(editData.sourceID, breakpoint.url, newLine, breakpoint.enabled, breakpoint.condition);
     325                WebInspector.debuggerModel.setBreakpoint(editData.sourceID, newLine, breakpoint.enabled, breakpoint.condition);
    317326            }
    318327        };
     
    359368    _debuggerPaused: function(event)
    360369    {
    361         var callFrames = event.data;
     370        var callFrames = event.data.callFrames;
    362371
    363372        WebInspector.debuggerModel.removeOneTimeBreakpoint();
     
    370379        WebInspector.currentPanel = this;
    371380
    372         this.sidebarPanes.callstack.update(callFrames, this._sourceIDMap);
     381        this.sidebarPanes.callstack.update(callFrames);
    373382        this.sidebarPanes.callstack.selectedCallFrame = callFrames[0];
    374383
     
    431440        this.viewsContainerElement.removeChildren();
    432441
    433         if (this._sourceIDMap) {
    434             for (var sourceID in this._sourceIDMap) {
    435                 var object = this._sourceIDMap[sourceID];
    436                 if (object instanceof WebInspector.Resource) {
    437                     object.removeAllScripts();
    438                     delete object._resourcesView;
    439                 }
    440             }
    441         }
    442 
    443         this._sourceIDMap = {};
     442        var scripts = WebInspector.debuggerModel.queryScripts(function(s) { return !!s.resource; });
     443        for (var i = 0; i < scripts.length; ++i)
     444            delete scripts[i].resource._resourcesView;
    444445
    445446        this.sidebarPanes.watchExpressions.refreshExpressions();
     
    488489    _scriptOrResourceForURLAndLine: function(url, line)
    489490    {
    490         var scriptWithMatchingUrl = null;
    491         for (var sourceID in this._sourceIDMap) {
    492             var scriptOrResource = this._sourceIDMap[sourceID];
    493             if (scriptOrResource instanceof WebInspector.Script) {
    494                 if (scriptOrResource.sourceURL !== url)
    495                     continue;
    496                 scriptWithMatchingUrl = scriptOrResource;
    497                 if (scriptWithMatchingUrl.startingLine <= line && scriptWithMatchingUrl.startingLine + scriptWithMatchingUrl.linesCount > line)
    498                     return scriptWithMatchingUrl;
    499             } else {
    500                 var resource = scriptOrResource;
    501                 if (resource.url === url)
    502                     return resource;
    503             }
    504         }
    505         return scriptWithMatchingUrl;
     491        var scripts = WebInspector.debuggerModel.scriptsForURL(url);
     492        for (var i = 0; i < scripts.length; ++i) {
     493            var script = scripts[i];
     494            if (script.resource)
     495                return script.resource;
     496            if (script.startingLine <= line && script.startingLine + script.linesCount > line)
     497                return script;
     498        }
     499        return null;
    506500    },
    507501
     
    722716        this.sidebarPanes.watchExpressions.refreshExpressions();
    723717
    724         var scriptOrResource = this._sourceIDMap[currentFrame.sourceID];
     718        var script = WebInspector.debuggerModel.scriptForSourceID(currentFrame.sourceID);
     719        var scriptOrResource = script.resource || script;
    725720        this._showScriptOrResource(scriptOrResource, {line: currentFrame.line});
    726721
  • trunk/WebCore/inspector/front-end/SourceFrame.js

    r73913 r74119  
    221221        for (var i = 0; i < breakpoints.length; ++i)
    222222            this._addBreakpoint(breakpoints[i]);
    223         WebInspector.debuggerModel.addEventListener("breakpoint-added", this._breakpointAdded, this);
     223        WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.BreakpointAdded, this._breakpointAdded, this);
    224224
    225225        this._textViewer.endUpdates();
     
    820820    {
    821821        var sourceID = this._sourceIDForLine(lineNumber);
    822         WebInspector.debuggerModel.setBreakpoint(sourceID, this._url, lineNumber, true, "");
     822        WebInspector.debuggerModel.setBreakpoint(sourceID, lineNumber, true, "");
    823823        if (!WebInspector.panels.scripts.breakpointsActivated)
    824824            WebInspector.panels.scripts.toggleBreakpointsClicked();
  • trunk/WebCore/inspector/front-end/SourceView.js

    r73730 r74119  
    3333    this.element.addStyleClass("source");
    3434
     35    var scripts = WebInspector.debuggerModel.scriptsForURL(resource.url);
    3536    var canEditScripts = WebInspector.panels.scripts.canEditScripts() && resource.type === WebInspector.Resource.Type.Script;
    36     this.sourceFrame = new WebInspector.SourceFrame(this.element, resource.scripts, canEditScripts);
     37    this.sourceFrame = new WebInspector.SourceFrame(this.element, scripts, canEditScripts);
    3738    resource.addEventListener("finished", this._resourceLoadingFinished, this);
    3839    this._frameNeedsSetup = true;
  • trunk/WebCore/inspector/front-end/inspector.js

    r74103 r74119  
    193193            pane.addBreakpointItem(new WebInspector.BreakpointItem(event.data));
    194194        }
    195         WebInspector.debuggerModel.addEventListener("breakpoint-added", breakpointAdded);
     195        WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.BreakpointAdded, breakpointAdded);
    196196        return pane;
    197197    },
Note: See TracChangeset for help on using the changeset viewer.