Changeset 199897 in webkit


Ignore:
Timestamp:
Apr 22, 2016 12:53:37 PM (8 years ago)
Author:
timothy@apple.com
Message:

Web Inspector: Debugger statement in console does not provide any call frames and debugger UI is confused

https://bugs.webkit.org/show_bug.cgi?id=156919
rdar://problem/25857118

This makes console expressions show up in the Debugger tab sidebar if a ScriptContentView is shown for them.
We now also show call frames that originate from a console expression, so the call frames in the sidebar is not empty.
Also fix a bug where when there are no call frames we auto resume the debugger and don't leave it in a broken state.

Reviewed by Joseph Pecoraro.

  • Localizations/en.lproj/localizedStrings.js: Updated.
  • UserInterface/Base/Utilities.js:

(appendWebInspectorSourceURL): Don't append if another sourceURL is already added.
(appendWebInspectorConsoleEvaluationSourceURL): Added.
(isWebInspectorConsoleEvaluationScript): Added.
(isWebKitInternalScript): Return false for isWebInspectorConsoleEvaluationScript().

  • UserInterface/Controllers/DebuggerManager.js:

(WebInspector.DebuggerManager.prototype.debuggerDidPause): Resume if call frames is empty. This is not as common now
since console expression call frames are not skipped.
(WebInspector.DebuggerManager.prototype.scriptDidParse): Change an early return for isWebInspectorInternalScript() that
was skipping adding internal scripts to the known script lists, but it should only do that when the debug UI is disabled.

  • UserInterface/Controllers/JavaScriptLogViewController.js:

(WebInspector.JavaScriptLogViewController.prototype.consolePromptTextCommitted):
Call appendWebInspectorConsoleEvaluationSourceURL so the console expressions are tagged before evaluateInInspectedWindow
added the internal sourceURL name.

  • UserInterface/Models/Script.js:

(WebInspector.Script): Assign unique identifiers to console scripts so they are named correctly.
(WebInspector.Script.resetUniqueDisplayNameNumbers): Reset _nextUniqueConsoleDisplayNameNumber.
(WebInspector.Script.prototype.get displayName): Special case console expressions with a better name.

  • UserInterface/Views/DebuggerSidebarPanel.js:

(WebInspector.DebuggerSidebarPanel.prototype.treeElementForRepresentedObject): Add a script tree element on demand
like the ResourceSidebarPanel does for anonymous scripts.
(WebInspector.DebuggerSidebarPanel.prototype._addScript): Return treeElement so treeElementForRepresentedObject can use it.

Location:
trunk/Source/WebInspectorUI
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebInspectorUI/ChangeLog

    r199852 r199897  
     12016-04-22  Timothy Hatcher  <timothy@apple.com>
     2
     3        Web Inspector: Debugger statement in console does not provide any call frames and debugger UI is confused
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=156919
     6        rdar://problem/25857118
     7
     8        This makes console expressions show up in the Debugger tab sidebar if a ScriptContentView is shown for them.
     9        We now also show call frames that originate from a console expression, so the call frames in the sidebar is not empty.
     10        Also fix a bug where when there are no call frames we auto resume the debugger and don't leave it in a broken state.
     11
     12        Reviewed by Joseph Pecoraro.
     13
     14        * Localizations/en.lproj/localizedStrings.js: Updated.
     15
     16        * UserInterface/Base/Utilities.js:
     17        (appendWebInspectorSourceURL): Don't append if another sourceURL is already added.
     18        (appendWebInspectorConsoleEvaluationSourceURL): Added.
     19        (isWebInspectorConsoleEvaluationScript): Added.
     20        (isWebKitInternalScript): Return false for isWebInspectorConsoleEvaluationScript().
     21
     22        * UserInterface/Controllers/DebuggerManager.js:
     23        (WebInspector.DebuggerManager.prototype.debuggerDidPause): Resume if call frames is empty. This is not as common now
     24        since console expression call frames are not skipped.
     25        (WebInspector.DebuggerManager.prototype.scriptDidParse): Change an early return for isWebInspectorInternalScript() that
     26        was skipping adding internal scripts to the known script lists, but it should only do that when the debug UI is disabled.
     27
     28        * UserInterface/Controllers/JavaScriptLogViewController.js:
     29        (WebInspector.JavaScriptLogViewController.prototype.consolePromptTextCommitted):
     30        Call appendWebInspectorConsoleEvaluationSourceURL so the console expressions are tagged before evaluateInInspectedWindow
     31        added the internal sourceURL name.
     32
     33        * UserInterface/Models/Script.js:
     34        (WebInspector.Script): Assign unique identifiers to console scripts so they are named correctly.
     35        (WebInspector.Script.resetUniqueDisplayNameNumbers): Reset _nextUniqueConsoleDisplayNameNumber.
     36        (WebInspector.Script.prototype.get displayName): Special case console expressions with a better name.
     37
     38        * UserInterface/Views/DebuggerSidebarPanel.js:
     39        (WebInspector.DebuggerSidebarPanel.prototype.treeElementForRepresentedObject): Add a script tree element on demand
     40        like the ResourceSidebarPanel does for anonymous scripts.
     41        (WebInspector.DebuggerSidebarPanel.prototype._addScript): Return treeElement so treeElementForRepresentedObject can use it.
     42
    1432016-04-21  Joseph Pecoraro  <pecoraro@apple.com>
    244
  • trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js

    r199635 r199897  
    182182localizedStrings["Conditional expression"] = "Conditional expression";
    183183localizedStrings["Console"] = "Console";
     184localizedStrings["Console Evaluation %d"] = "Console Evaluation %d";
    184185localizedStrings["Console Profile Recorded"] = "Console Profile Recorded";
    185186localizedStrings["Console errors, click to show the Console tab"] = "Console errors, click to show the Console tab";
  • trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js

    r199789 r199897  
    12571257function appendWebInspectorSourceURL(string)
    12581258{
     1259    if (string.includes("//# sourceURL"))
     1260        return string;
    12591261    return "\n//# sourceURL=__WebInspectorInternal__\n" + string;
    12601262}
    12611263
     1264function appendWebInspectorConsoleEvaluationSourceURL(string)
     1265{
     1266    if (string.includes("//# sourceURL"))
     1267        return string;
     1268    return "\n//# sourceURL=__WebInspectorConsoleEvaluation__\n" + string;
     1269}
     1270
    12621271function isWebInspectorInternalScript(url)
    12631272{
     
    12651274}
    12661275
     1276function isWebInspectorConsoleEvaluationScript(url)
     1277{
     1278    return url === "__WebInspectorConsoleEvaluation__";
     1279}
     1280
    12671281function isWebKitInternalScript(url)
    12681282{
     1283    if (isWebInspectorConsoleEvaluationScript(url))
     1284        return false;
    12691285    return url && url.startsWith("__Web") && url.endsWith("__");
    12701286}
  • trunk/Source/WebInspectorUI/UserInterface/Controllers/DebuggerManager.js

    r199602 r199897  
    546546        this._activeCallFrame = this._callFrames[0];
    547547
     548        if (!this._activeCallFrame) {
     549            console.assert("We should always have one call frame. This could indicate we are hitting an exception or debugger statement in an internal injected script.");
     550            this._didResumeInternal();
     551            return;
     552        }
     553
    548554        if (!wasStillPaused)
    549555            this.dispatchEventToListeners(WebInspector.DebuggerManager.Event.Paused);
     
    579585        }
    580586
    581         if (isWebInspectorInternalScript(sourceURL))
     587        if (!WebInspector.isDebugUIEnabled() && isWebKitInternalScript(sourceURL))
    582588            return;
    583589
     
    600606                return;
    601607        }
     608
     609        // Console expressions are not added to the UI by default.
     610        if (isWebInspectorConsoleEvaluationScript(script.sourceURL))
     611            return;
    602612
    603613        this.dispatchEventToListeners(WebInspector.DebuggerManager.Event.ScriptAdded, {script});
  • trunk/Source/WebInspectorUI/UserInterface/Controllers/JavaScriptLogViewController.js

    r192908 r199897  
    229229        }
    230230
     231        text = appendWebInspectorConsoleEvaluationSourceURL(text);
     232
    231233        WebInspector.runtimeManager.evaluateInInspectedWindow(text, WebInspector.RuntimeManager.ConsoleObjectGroup, true, false, false, true, true, printResult.bind(this));
    232234    }
  • trunk/Source/WebInspectorUI/UserInterface/Models/Script.js

    r199852 r199897  
    4646            WebInspector.sourceMapManager.downloadSourceMap(sourceMapURL, this._url, this);
    4747
     48        if (isWebInspectorConsoleEvaluationScript(this._sourceURL)) {
     49            // Assign a unique number to the script object so it will stay the same.
     50            this._uniqueDisplayNameNumber = this.constructor._nextUniqueConsoleDisplayNameNumber++;
     51        }
     52
    4853        this._scriptSyntaxTree = null;
    4954    }
     
    5459    {
    5560        WebInspector.Script._nextUniqueDisplayNameNumber = 1;
     61        WebInspector.Script._nextUniqueConsoleDisplayNameNumber = 1;
    5662    }
    5763
     
    94100        if (this._url)
    95101            return WebInspector.displayNameForURL(this._url, this.urlComponents);
     102
     103        if (isWebInspectorConsoleEvaluationScript(this._sourceURL)) {
     104            console.assert(this._uniqueDisplayNameNumber);
     105            return WebInspector.UIString("Console Evaluation %d").format(this._uniqueDisplayNameNumber);
     106        }
    96107
    97108        if (this._sourceURL) {
     
    248259
    249260WebInspector.Script._nextUniqueDisplayNameNumber = 1;
     261WebInspector.Script._nextUniqueConsoleDisplayNameNumber = 1;
  • trunk/Source/WebInspectorUI/UserInterface/Views/DebuggerSidebarPanel.js

    r199602 r199897  
    209209            representedObject = representedObject.mainResource;
    210210
    211         return this.contentTreeOutline.getCachedTreeElement(representedObject);
     211        let treeElement = this.contentTreeOutline.findTreeElement(representedObject);
     212        if (treeElement)
     213            return treeElement;
     214
     215        // Only special case Script objects.
     216        if (!(representedObject instanceof WebInspector.Script)) {
     217            console.error("Didn't find a TreeElement for representedObject", representedObject);
     218            return null;
     219        }
     220
     221        // If the Script has a URL we should have found it earlier.
     222        if (representedObject.url) {
     223            console.error("Didn't find a ScriptTreeElement for a Script with a URL.");
     224            return null;
     225        }
     226
     227        // Since the Script does not have a URL we consider it an 'anonymous' script. These scripts happen from calls to
     228        // window.eval() or browser features like Auto Fill and Reader. They are not normally added to the sidebar, but since
     229        // we have a ScriptContentView asking for the tree element we will make a ScriptTreeElement on demand and add it.
     230
     231        return this._addScript(representedObject);
    212232    }
    213233
     
    430450        // COMPATIBILITY(iOS 9): Backends could send the frontend built-in code, filter out JSC internals.
    431451        if (!script.url && !script.sourceURL)
    432             return;
     452            return null;
    433453
    434454        // Don't add breakpoints if the script is represented by a Resource. They were
    435455        // already added by _resourceAdded.
    436456        if (script.resource)
    437             return;
     457            return null;
    438458
    439459        let treeElement = this._addTreeElementForSourceCodeToContentTreeOutline(script);
     
    443463        if (!this.contentBrowser.currentContentView)
    444464            this.showDefaultContentViewForTreeElement(treeElement);
     465
     466        return treeElement;
    445467    }
    446468
Note: See TracChangeset for help on using the changeset viewer.