Changeset 55231 in webkit


Ignore:
Timestamp:
Feb 25, 2010 5:45:27 AM (14 years ago)
Author:
pfeldman@chromium.org
Message:

2010-02-23 Pavel Feldman <pfeldman@chromium.org>

Reviewed by Timothy Hatcher.

Web Inspector: Scripts panel shows blank source when stopping on a breakpoint on refresh.

https://bugs.webkit.org/show_bug.cgi?id=35232

  • inspector/front-end/Panel.js: (WebInspector.Panel.prototype.canShowSourceLine): (WebInspector.Panel.prototype.showSourceLine):
  • inspector/front-end/ResourcesPanel.js: (WebInspector.ResourcesPanel.prototype.canShowSourceLine): (WebInspector.ResourcesPanel.prototype.showSourceLine):
  • inspector/front-end/Script.js: (WebInspector.Script):
  • inspector/front-end/ScriptView.js: (WebInspector.ScriptView.prototype.setupSourceFrameIfNeeded):
  • inspector/front-end/ScriptsPanel.js: (WebInspector.ScriptsPanel.prototype.show): (WebInspector.ScriptsPanel.prototype.get searchableViews): (WebInspector.ScriptsPanel.prototype.addScript): (WebInspector.ScriptsPanel.prototype._resourceLoadingFinished): (WebInspector.ScriptsPanel.prototype.addBreakpoint): (WebInspector.ScriptsPanel.prototype.removeBreakpoint): (WebInspector.ScriptsPanel.prototype.reset): (WebInspector.ScriptsPanel.prototype.canShowSourceLine): (WebInspector.ScriptsPanel.prototype.showSourceLine): (WebInspector.ScriptsPanel.prototype._scriptOrResourceForURLAndLine): (WebInspector.ScriptsPanel.prototype.showView): (WebInspector.ScriptsPanel.prototype._sourceFrameForScriptOrResource): (WebInspector.ScriptsPanel.prototype._showScriptOrResource): (WebInspector.ScriptsPanel.prototype._addScriptToFilesMenu.optionCompare): (WebInspector.ScriptsPanel.prototype._addScriptToFilesMenu):
  • inspector/front-end/SourceView.js: (WebInspector.SourceView.prototype._addBreakpoint):
  • inspector/front-end/inspector.js: (WebInspector.documentClick.followLink): (WebInspector.documentClick): (WebInspector._choosePanelToShowSourceLine): (WebInspector.canShowSourceLine): (WebInspector.showSourceLine):
Location:
trunk/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r55230 r55231  
     12010-02-25  Pavel Feldman  <pfeldman@chromium.org>
     2
     3        Reviewed by Timothy Hatcher.
     4
     5        Web Inspector: Scripts panel shows blank source when stopping on a breakpoint on refresh.
     6
     7        https://bugs.webkit.org/show_bug.cgi?id=35232
     8
     9        * inspector/front-end/Panel.js:
     10        (WebInspector.Panel.prototype.canShowSourceLine):
     11        (WebInspector.Panel.prototype.showSourceLine):
     12        * inspector/front-end/ResourcesPanel.js:
     13        (WebInspector.ResourcesPanel.prototype.canShowSourceLine):
     14        (WebInspector.ResourcesPanel.prototype.showSourceLine):
     15        * inspector/front-end/Script.js:
     16        (WebInspector.Script):
     17        * inspector/front-end/ScriptView.js:
     18        (WebInspector.ScriptView.prototype.setupSourceFrameIfNeeded):
     19        * inspector/front-end/ScriptsPanel.js:
     20        (WebInspector.ScriptsPanel.prototype.show):
     21        (WebInspector.ScriptsPanel.prototype.get searchableViews):
     22        (WebInspector.ScriptsPanel.prototype.addScript):
     23        (WebInspector.ScriptsPanel.prototype._resourceLoadingFinished):
     24        (WebInspector.ScriptsPanel.prototype.addBreakpoint):
     25        (WebInspector.ScriptsPanel.prototype.removeBreakpoint):
     26        (WebInspector.ScriptsPanel.prototype.reset):
     27        (WebInspector.ScriptsPanel.prototype.canShowSourceLine):
     28        (WebInspector.ScriptsPanel.prototype.showSourceLine):
     29        (WebInspector.ScriptsPanel.prototype._scriptOrResourceForURLAndLine):
     30        (WebInspector.ScriptsPanel.prototype.showView):
     31        (WebInspector.ScriptsPanel.prototype._sourceFrameForScriptOrResource):
     32        (WebInspector.ScriptsPanel.prototype._showScriptOrResource):
     33        (WebInspector.ScriptsPanel.prototype._addScriptToFilesMenu.optionCompare):
     34        (WebInspector.ScriptsPanel.prototype._addScriptToFilesMenu):
     35        * inspector/front-end/SourceView.js:
     36        (WebInspector.SourceView.prototype._addBreakpoint):
     37        * inspector/front-end/inspector.js:
     38        (WebInspector.documentClick.followLink):
     39        (WebInspector.documentClick):
     40        (WebInspector._choosePanelToShowSourceLine):
     41        (WebInspector.canShowSourceLine):
     42        (WebInspector.showSourceLine):
     43
    1442010-02-25  Ben Murdoch  <benm@google.com>
    245
  • trunk/WebCore/inspector/front-end/Panel.js

    r54812 r55231  
    374374    },
    375375
    376     canShowSourceLineForURL: function(url)
     376    canShowSourceLine: function(url, line)
    377377    {
    378378        return false;
    379379    },
    380380
    381     showSourceLineForURL: function(url, line)
     381    showSourceLine: function(url, line)
    382382    {
    383383        return false;
  • trunk/WebCore/inspector/front-end/ResourcesPanel.js

    r55052 r55231  
    455455    },
    456456
    457     canShowSourceLineForURL: function(url)
     457    canShowSourceLine: function(url, line)
    458458    {
    459459        return !!WebInspector.resourceForURL(url);
    460460    },
    461461
    462     showSourceLineForURL: function(url, line)
     462    showSourceLine: function(url, line)
    463463    {
    464464        this.showResource(WebInspector.resourceForURL(url), line);
  • trunk/WebCore/inspector/front-end/Script.js

    r45186 r55231  
    3333    this.errorMessage = errorMessage;
    3434
     35    this.linesCount = 0;
     36    var lastIndex = source.indexOf("\n");
     37    while (lastIndex !== -1) {
     38        lastIndex = source.indexOf("\n", lastIndex + 1)
     39        this.linesCount++;
     40    }
     41
    3542    // if no URL, look for "//@ sourceURL=" decorator
    3643    // note that this sourceURL comment decorator is behavior that FireBug added
  • trunk/WebCore/inspector/front-end/ScriptView.js

    r54657 r55231  
    5353        this.attach();
    5454
    55         this.sourceFrame.setContent("text/javascript", this.script.source);
     55        var prefix = "";
     56        for (var i = 0; i < this.script.startingLine - 1; ++i)
     57            prefix += "\n";
     58
     59        this.sourceFrame.setContent("text/javascript", prefix + this.script.source);
    5660        this._sourceFrameSetup = true;
    5761        delete this._frameNeedsSetup;
  • trunk/WebCore/inspector/front-end/ScriptsPanel.js

    r55077 r55231  
    239239            this.visibleView.show(this.viewsContainerElement);
    240240        }
    241         // Hide any views that are visible that are not this panel's current visible view.
    242         // This can happen when a ResourceView is visible in the Resources panel then switched
    243         // to the this panel.
    244         for (var sourceID in this._sourceIDMap) {
    245             var scriptOrResource = this._sourceIDMap[sourceID];
    246             var view = this._sourceViewForScriptOrResource(scriptOrResource);
    247             if (!view || view === this.visibleView)
    248                 continue;
    249             view.visible = false;
    250         }
    251241        if (this._attachDebuggerWhenShown) {
    252242            InspectorBackend.enableDebugger(false);
     
    257247    get searchableViews()
    258248    {
    259         var views = [];
    260 
    261         const visibleView = this.visibleView;
    262         if (visibleView && visibleView.performSearch) {
    263             visibleView.alreadySearching = true;
    264             views.push(visibleView);
    265         }
    266 
    267         for (var sourceID in this._sourceIDMap) {
    268             var scriptOrResource = this._sourceIDMap[sourceID];
    269             var view = this._sourceViewForScriptOrResource(scriptOrResource);
    270             if (!view || !view.performSearch || view.alreadySearching)
    271                 continue;
    272 
    273             view.alreadySearching = true;
    274             views.push(view);
    275         }
    276 
    277         for (var i = 0; i < views.length; ++i)
    278             delete views[i].alreadySearching;
    279 
    280         return views;
     249        return [ this.visibleView ];
    281250    },
    282251
     
    289258    {
    290259        var script = new WebInspector.Script(sourceID, sourceURL, source, startingLine, errorLine, errorMessage);
    291 
    292         if (sourceURL in WebInspector.resourceURLMap) {
    293             var resource = WebInspector.resourceURLMap[sourceURL];
     260        this._sourceIDMap[sourceID] = script;
     261
     262        var resource = WebInspector.resourceURLMap[sourceURL];
     263        if (resource) {
     264            if (resource.finished) {
     265                // Resource is finished, bind the script right away.
     266                resource.addScript(script);
     267                this._sourceIDMap[sourceID] = resource;
     268            } else {
     269                // Resource is not finished, bind the script later.
     270                if (!resource._scriptsPendingResourceLoad) {
     271                    resource._scriptsPendingResourceLoad = [];
     272                    resource.addEventListener("finished", this._resourceLoadingFinished, this);
     273                }
     274                resource._scriptsPendingResourceLoad.push(script);
     275            }
     276        }
     277        this._addScriptToFilesMenu(script);
     278    },
     279
     280    _resourceLoadingFinished: function(e)
     281    {
     282        var resource = e.target;
     283        for (var i = 0; i < resource._scriptsPendingResourceLoad.length; ++i) {
     284            // Bind script to resource.
     285            var script = resource._scriptsPendingResourceLoad[i];
    294286            resource.addScript(script);
    295         }
    296 
    297         sourceURL = script.sourceURL;
    298 
    299         if (sourceID)
    300             this._sourceIDMap[sourceID] = (resource || script);
    301         this._addScriptToFilesMenu(script);
    302     },
    303 
    304     scriptOrResourceForID: function(id)
    305     {
    306         return this._sourceIDMap[id];
    307     },
    308 
    309     scriptForURL: function(url)
    310     {
    311         return this._scriptsForURLsInFilesSelect[url];
     287            this._sourceIDMap[script.sourceID] = resource;
     288
     289            // Remove script from the files list.
     290            script.filesSelectOption.parentElement.removeChild(script.filesSelectOption);
     291           
     292            // Move breakpoints to the resource's frame.
     293            if (script._scriptView) {
     294                var sourceFrame = script._scriptView.sourceFrame;
     295                for (var j = 0; j < sourceFrame.breakpoints; ++j) {
     296                    var resourceFrame = this._sourceFrameForScriptOrResource(resource);
     297                    resourceFrame.addBreakpoint(sourceFrame.breakpoints[j]);
     298                }
     299            }
     300        }
     301        // Adding first script will add resource.
     302        this._addScriptToFilesMenu(resource._scriptsPendingResourceLoad[0]);
     303        delete resource._scriptsPendingResourceLoad;
    312304    },
    313305
     
    321313        var sourceFrame;
    322314        if (breakpoint.url) {
    323             if (breakpoint.url in WebInspector.resourceURLMap) {
    324                 var resource = WebInspector.resourceURLMap[breakpoint.url];
     315            var resource = WebInspector.resourceURLMap[breakpoint.url];
     316            if (resource && resource.finished)
    325317                sourceFrame = this._sourceFrameForScriptOrResource(resource);
    326             }
    327318        }
    328319
     
    341332
    342333        var sourceFrame;
    343         if (breakpoint.url && breakpoint.url in WebInspector.resourceURLMap) {
     334        if (breakpoint.url) {
    344335            var resource = WebInspector.resourceURLMap[breakpoint.url];
    345             sourceFrame = this._sourceFrameForScriptOrResource(resource);
     336            if (resource && resource.finished)
     337                sourceFrame = this._sourceFrameForScriptOrResource(resource);
    346338        }
    347339
     
    454446        this._updateBackAndForwardButtons();
    455447
    456         this._scriptsForURLsInFilesSelect = {};
     448        this._resourceForURLInFilesSelect = {};
    457449        this.filesSelectElement.removeChildren();
    458450        this.functionsSelectElement.removeChildren();
     
    498490    },
    499491
    500     canShowSourceLineForURL: function(url)
    501     {
    502         return InspectorBackend.debuggerEnabled() &&
    503             !!(WebInspector.resourceForURL(url) || this.scriptForURL(url));
    504     },
    505 
    506     showSourceLineForURL: function(url, line)
    507     {
    508         var resource = WebInspector.resourceForURL(url);
    509         if (resource)
    510             this.showResource(resource, line);
    511         else
    512             this.showScript(this.scriptForURL(url), line);
    513     },
    514 
    515     showScript: function(script, line)
    516     {
    517         this._showScriptOrResource(script, {line: line, shouldHighlightLine: true});
    518     },
    519 
    520     showResource: function(resource, line)
    521     {
    522         this._showScriptOrResource(resource, {line: line, shouldHighlightLine: true});
     492    canShowSourceLine: function(url, line)
     493    {
     494        if (!InspectorBackend.debuggerEnabled())
     495            return false;
     496        return !!this._scriptOrResourceForURLAndLine(url, line);
     497    },
     498
     499    showSourceLine: function(url, line)
     500    {
     501        var scriptOrResource = this._scriptOrResourceForURLAndLine(url, line);
     502        this._showScriptOrResource(scriptOrResource, {line: line, shouldHighlightLine: true});
     503    },
     504
     505    _scriptOrResourceForURLAndLine: function(url, line)
     506    {
     507        for (var sourceID in this._sourceIDMap) {
     508            var scriptOrResource = this._sourceIDMap[sourceID];
     509            if (scriptOrResource instanceof WebInspector.Script) {
     510                var script = scriptOrResource;
     511                if (script.startingLine <= line && script.startingLine + script.linesCount > line)
     512                    return script;
     513            } else {
     514                var resource = scriptOrResource;
     515                if (resource.url === url)
     516                    return resource;
     517            }
     518        }
     519        return null;
    523520    },
    524521
     
    527524        if (!view)
    528525            return;
    529         this._showScriptOrResource((view.resource || view.script));
     526        this._showScriptOrResource(view.resource || view.script);
    530527    },
    531528
     
    577574    _sourceFrameForScriptOrResource: function(scriptOrResource)
    578575    {
    579         if (scriptOrResource instanceof WebInspector.Resource) {
    580             if (!WebInspector.panels.resources)
    581                 return null;
     576        if (scriptOrResource instanceof WebInspector.Resource)
    582577            return WebInspector.panels.resources.sourceFrameForResource(scriptOrResource);
    583         }
    584578        if (scriptOrResource instanceof WebInspector.Script)
    585579            return this.sourceFrameForScript(scriptOrResource);
     
    654648            // so use the force option to force the script into the menu.
    655649            if (!option) {
    656                 this._addScriptToFilesMenu(scriptOrResource, {force: true});
     650                this._addScriptToFilesMenu(scriptOrResource, true);
    657651                option = scriptOrResource.filesSelectOption;
    658652            }
    659653
    660654            console.assert(option);
    661         } else {
    662             var script = this.scriptForURL(url);
    663             if (script)
    664                option = script.filesSelectOption;
    665         }
     655        } else
     656            option = scriptOrResource.filesSelectOption;
    666657
    667658        if (option)
     
    669660    },
    670661
    671     _addScriptToFilesMenu: function(script, options)
    672     {
    673         var force = options && options.force;
    674 
     662    _addScriptToFilesMenu: function(script, force)
     663    {
    675664        if (!script.sourceURL && !force)
    676665            return;
    677666
    678         if (script.resource && this._scriptsForURLsInFilesSelect[script.sourceURL])
    679             return;
    680 
    681         this._scriptsForURLsInFilesSelect[script.sourceURL] = script;
     667        if (script.resource) {
     668            if (this._resourceForURLInFilesSelect[script.resource.url])
     669                return;
     670            this._resourceForURLInFilesSelect[script.resource.url] = script.resource;
     671        }
     672 
     673        var displayName = script.sourceURL ? WebInspector.displayNameForURL(script.sourceURL) : WebInspector.UIString("(program)");
    682674
    683675        var select = this.filesSelectElement;
    684 
    685676        var option = document.createElement("option");
    686         option.representedObject = (script.resource || script);
    687         option.text = (script.sourceURL ? WebInspector.displayNameForURL(script.sourceURL) : WebInspector.UIString("(program)"));
     677        option.representedObject = script.resource || script;
     678        option.url = displayName;
     679        option.startingLine = script.startingLine;
     680        option.text = script.resource ? displayName : String.sprintf("%s (%d - %d)", displayName, script.startingLine, script.startingLine + script.linesCount);
    688681
    689682        function optionCompare(a, b)
    690683        {
    691             var aTitle = a.text.toLowerCase();
    692             var bTitle = b.text.toLowerCase();
    693             if (aTitle < bTitle)
     684            if (a.url < b.url)
    694685                return -1;
    695             else if (aTitle > bTitle)
     686            else if (a.url > b.url)
    696687                return 1;
    697688
    698             var aSourceID = a.representedObject.sourceID;
    699             var bSourceID = b.representedObject.sourceID;
    700             if (aSourceID < bSourceID)
     689            if (typeof a.startingLine !== "number")
    701690                return -1;
    702             else if (aSourceID > bSourceID)
    703                 return 1;
    704             return 0;
     691            if (typeof b.startingLine !== "number")
     692                return -1;
     693            return a.startingLine - b.startingLine;
    705694        }
    706695
     
    711700            select.insertBefore(option, select.childNodes.item(insertionIndex));
    712701
    713         script.filesSelectOption = option;
     702        if (script.resource)
     703            script.resource.filesSelectOption = option;
     704        else
     705            script.filesSelectOption = option;
    714706
    715707        // Call _showScriptOrResource if the option we just appended ended up being selected.
  • trunk/WebCore/inspector/front-end/SourceView.js

    r54657 r55231  
    9393    {
    9494        var sourceID = null;
    95         var closestStartingLine = 0;
    9695        var scripts = this.resource.scripts;
    9796        for (var i = 0; i < scripts.length; ++i) {
    9897            var script = scripts[i];
    99             if (script.startingLine <= line && script.startingLine >= closestStartingLine) {
    100                 closestStartingLine = script.startingLine;
     98            if (script.startingLine <= line && script.startingLine + script.linesCount > line) {
    10199                sourceID = script.sourceID;
     100                break;
    102101            }
    103102        }
  • trunk/WebCore/inspector/front-end/inspector.js

    r55172 r55231  
    623623    {
    624624        // FIXME: support webkit-html-external-link links here.
    625         if (WebInspector.canShowSourceLineForURL(anchor.href, anchor.preferredPanel)) {
     625        if (WebInspector.canShowSourceLine(anchor.href, anchor.lineNumber, anchor.preferredPanel)) {
    626626            if (anchor.hasStyleClass("webkit-html-external-link")) {
    627627                anchor.removeStyleClass("webkit-html-external-link");
     
    629629            }
    630630
    631             WebInspector.showSourceLineForURL(anchor.href, anchor.lineNumber, anchor.preferredPanel);
     631            WebInspector.showSourceLine(anchor.href, anchor.lineNumber, anchor.preferredPanel);
    632632        } else {
    633633            var profileString = WebInspector.ProfileType.URLRegExp.exec(anchor.href);
    634634            if (profileString)
    635                 WebInspector.showProfileForURL(anchor.href);
     635                WebInspector.showProfile(anchor.href, anchor.lineNumber);
    636636        }
    637637    }
     
    14661466}
    14671467
    1468 WebInspector._choosePanelToShowSourceLineForURL = function(url, preferredPanel)
     1468WebInspector._choosePanelToShowSourceLine = function(url, line, preferredPanel)
    14691469{
    14701470    preferredPanel = preferredPanel || "resources";
    14711471    var panel = this.panels[preferredPanel];
    1472     if (panel && panel.canShowSourceLineForURL(url))
     1472    if (panel && panel.canShowSourceLine(url, line))
    14731473        return panel;
    14741474    panel = this.panels.resources;
    1475     return panel.canShowSourceLineForURL(url) ? panel : null;
    1476 }
    1477 
    1478 WebInspector.canShowSourceLineForURL = function(url, preferredPanel)
    1479 {
    1480     return !!this._choosePanelToShowSourceLineForURL(url, preferredPanel);
    1481 }
    1482 
    1483 WebInspector.showSourceLineForURL = function(url, line, preferredPanel)
    1484 {
    1485     this.currentPanel = this._choosePanelToShowSourceLineForURL(url, preferredPanel);
     1475    return panel.canShowSourceLine(url, line) ? panel : null;
     1476}
     1477
     1478WebInspector.canShowSourceLine = function(url, line, preferredPanel)
     1479{
     1480    return !!this._choosePanelToShowSourceLine(url, line, preferredPanel);
     1481}
     1482
     1483WebInspector.showSourceLine = function(url, line, preferredPanel)
     1484{
     1485    this.currentPanel = this._choosePanelToShowSourceLine(url, line, preferredPanel);
    14861486    if (!this.currentPanel)
    14871487        return false;
    1488     this.currentPanel.showSourceLineForURL(url, line);
     1488    this.currentPanel.showSourceLine(url, line);
    14891489    return true;
    14901490}
Note: See TracChangeset for help on using the changeset viewer.