Bug 144372 - Web Inspector: In the console, show function name next to the source link
Summary: Web Inspector: In the console, show function name next to the source link
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nikita Vasilyev
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2015-04-28 20:25 PDT by Nikita Vasilyev
Modified: 2015-05-15 16:22 PDT (History)
8 users (show)

See Also:


Attachments
[Image] (anonymous-function) (44.94 KB, image/png)
2015-04-28 20:31 PDT, Nikita Vasilyev
no flags Details
[Image] WIP (85.52 KB, image/png)
2015-04-29 16:06 PDT, Nikita Vasilyev
no flags Details
[HTML] Test page (893 bytes, text/html)
2015-04-29 16:08 PDT, Nikita Vasilyev
no flags Details
[HTML] Test page (985 bytes, text/html)
2015-04-29 18:28 PDT, Nikita Vasilyev
no flags Details
[Image] WIP (87.67 KB, image/png)
2015-04-29 18:35 PDT, Nikita Vasilyev
no flags Details
Patch (18.21 KB, patch)
2015-04-30 16:25 PDT, Nikita Vasilyev
no flags Details | Formatted Diff | Diff
Animated GIF with the patch applied (320.50 KB, image/gif)
2015-04-30 16:31 PDT, Nikita Vasilyev
no flags Details
Patch (26.42 KB, patch)
2015-05-09 19:32 PDT, Nikita Vasilyev
timothy: review+
timothy: commit-queue-
Details | Formatted Diff | Diff
[Video] Screencast (1.32 MB, video/mp4)
2015-05-09 19:42 PDT, Nikita Vasilyev
no flags Details
Patch (26.34 KB, patch)
2015-05-10 04:31 PDT, Nikita Vasilyev
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nikita Vasilyev 2015-04-28 20:25:15 PDT
As it shown on http://timothy.hatcher.name/console/.
Comment 1 Radar WebKit Bug Importer 2015-04-28 20:25:48 PDT
<rdar://problem/20740069>
Comment 2 Nikita Vasilyev 2015-04-28 20:31:41 PDT
Created attachment 251919 [details]
[Image] (anonymous-function)

I’ve reused CallFrameTreeElement (the class that is used to display stack trace items) and noticed "(anonymous function)" appearing quite often. It would probably make more sense to not show "(anonymous function)" for this case.
Comment 3 Nikita Vasilyev 2015-04-28 20:33:14 PDT
Styling on the image does not match http://timothy.hatcher.name/console/, ignore that for now.
Comment 4 Timothy Hatcher 2015-04-29 05:31:16 PDT
Yeah, we can drop showing the function name for anonymous functions. We might want to show a resource icon next to the file name in that case, so there is something. I worry this might look funny if there is sometimes a function name and icon then no function name and no icon. Having a resource icon would help balance that.
Comment 5 Timothy Hatcher 2015-04-29 05:32:54 PDT
I'd likely only show a resource icon for anonymous functions of you drop showing the function name for them.
Comment 6 Nikita Vasilyev 2015-04-29 16:06:21 PDT
Created attachment 252001 [details]
[Image] WIP

Known issues:

* appendChild’s icon should be "N" as it’s a native function
* very-very long function names should be clipped
Comment 7 Nikita Vasilyev 2015-04-29 16:08:49 PDT
Created attachment 252002 [details]
[HTML] Test page

For manual testing. WIP image of this page is above.
Comment 8 Timothy Hatcher 2015-04-29 17:01:36 PDT
appendXhild should be skipped and the caller should be shown.
Comment 9 Nikita Vasilyev 2015-04-29 17:31:47 PDT
(In reply to comment #8)
> appendXhild should be skipped and the caller should be shown.

Yes, it should.

https://github.com/WebKit/webkit/blob/a6dc3da650f6e2e03df34027d1f5f0dca348ecdb/Source/WebInspectorUI/UserInterface/Views/ConsoleMessageView.js#L600

The problem is that the frame.url is not "[native code]" but the same url as the call frame below it, e.g. "http://.../stacktrace.html".
Comment 10 Nikita Vasilyev 2015-04-29 18:28:52 PDT
Created attachment 252019 [details]
[HTML] Test page
Comment 11 Nikita Vasilyev 2015-04-29 18:35:53 PDT
Created attachment 252021 [details]
[Image] WIP

Known issues:

* Source links of CSS warnings should be styled the same as JS errors and console.* messages.
* Global code shouldn’t have [f] icon
* Clipping of very-very long function names can be improved
Comment 12 Timothy Hatcher 2015-04-29 19:52:00 PDT
Global Code should just have a location link. No need to say global code.
Comment 13 Nikita Vasilyev 2015-04-29 20:09:38 PDT
(In reply to comment #12)
> Global Code should just have a location link. No need to say global code.

I receive "global code" from the payload. I noticed the following in TimelineManager.js:

    var functionName = payload.functionName !== "global code" ? payload.functionName : null;

https://github.com/WebKit/webkit/blob/5b9df00203321d5c6e600f3e2c9712dc25ceaa06/Source/WebInspectorUI/UserInterface/Controllers/TimelineManager.js#L472

I should probably abstract this away from TimelineManager.js and use in the console too.
Comment 14 Timothy Hatcher 2015-04-30 01:12:55 PDT
Yeah, sharing that logic would be good.
Comment 15 Nikita Vasilyev 2015-04-30 16:25:29 PDT
Created attachment 252107 [details]
Patch
Comment 16 Nikita Vasilyev 2015-04-30 16:31:04 PDT
Created attachment 252109 [details]
Animated GIF with the patch applied
Comment 17 Nikita Vasilyev 2015-04-30 16:37:58 PDT
Known issues:

– Clicking a function selects the text instead of acting like a link. It was easier to implement since I just re-used WebInspector.linkifyLocation.
– "global code"
– long method names push file names out of the screen

I’d like to fix all of them but in separate patches. This one took me a week and it’s already fairly big.
Comment 18 Timothy Hatcher 2015-05-05 11:47:03 PDT
I think we should fix the lingering issues instead of landing this half baked. This isn't that large of a patch.
Comment 19 Nikita Vasilyev 2015-05-05 14:19:48 PDT
Okay, I’m working on that.
Comment 20 Nikita Vasilyev 2015-05-09 19:32:30 PDT
Created attachment 252794 [details]
Patch
Comment 21 Nikita Vasilyev 2015-05-09 19:42:46 PDT
Created attachment 252795 [details]
[Video] Screencast
Comment 22 Nikita Vasilyev 2015-05-09 19:44:02 PDT
(In reply to comment #17)
> Known issues:
> 
> – Clicking a function selects the text instead of acting like a link. It was
> easier to implement since I just re-used WebInspector.linkifyLocation.
> – "global code"
> – long method names push file names out of the screen

All three have been fixed.
Comment 23 Timothy Hatcher 2015-05-10 03:36:37 PDT
Comment on attachment 252794 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=252794&action=review

Rebase and fix some of these comments and your are good!

> Source/WebInspectorUI/UserInterface/Base/Main.js:1769
> +WebInspector.resourceForURL = function(url) {
> +    var sourceCode = WebInspector.frameResourceManager.resourceForURL(url);
> +    if (!sourceCode) {
> +        sourceCode = WebInspector.debuggerManager.scriptsForURL(url)[0];

This should be called WebInspector.sourceCodeForURL, since it can return a Resource or a Script, but both a SourceCode subclasses.

> Source/WebInspectorUI/UserInterface/Models/CallFrame.js:119
> +        var sourceCode = WebInspector.frameResourceManager.resourceForURL(url);
> +        if (!sourceCode)
> +            sourceCode = WebInspector.debuggerManager.scriptsForURL(url)[0];

Could use your new WebInspector.sourceCodeForURL here.

> Source/WebInspectorUI/UserInterface/Views/CallFrameView.js:37
> +        WebInspector.linkifyElement(callFrameElement, sourceCodeLocation);
> +        var linkElement = document.createElement("a");

Nit: Add a newline between these lines.

> Source/WebInspectorUI/UserInterface/Views/CallFrameView.js:68
> +    static iconForCallFrame(callFrame)

iconClassNameForCallFrame?

> Source/WebInspectorUI/UserInterface/Views/ConsoleMessageView.js:297
> +        if (firstNonNativeCallFrame)
> +            // JavaScript errors and console.* methods.
> +            callFrame = WebInspector.CallFrame.fromPayload(firstNonNativeCallFrame);
> +        else if (this._message.url && !this._shouldHideURL(this._message.url))
> +            // CSS warnings have no stack traces.
> +            callFrame = WebInspector.CallFrame.fromPayload({
> +                url: this._message.url,
> +                lineNumber: this._message.line,
> +                columnNumber: this._message.column
> +            });

Needs { } since the bodies of the blocks are multiple lines.

I would not expect protocol data for the CallFrame to be used at this level. The calls to WebInspector.CallFrame.fromPayload (and this logic) should move to the Model level in ConsoleMessage. ConsoleMessage should just have a getter for firstNonNativeCallFrame that Does The Right Thing™. Really _firstNonNativeCallFrame should move.

Sigh. In fact ConsoleMessage's stackTrace seems to be a raw protocol object still and not an array of CallFrames. So there is more work here to do. Can you file a follow up for all that? Keeping the code you wrote here is fine for now, but it is all really model level and not view level logic from the poor separation we had before.
Comment 24 Nikita Vasilyev 2015-05-10 04:31:51 PDT
Created attachment 252813 [details]
Patch
Comment 25 WebKit Commit Bot 2015-05-10 05:24:32 PDT
Comment on attachment 252813 [details]
Patch

Clearing flags on attachment: 252813

Committed r184045: <http://trac.webkit.org/changeset/184045>
Comment 26 WebKit Commit Bot 2015-05-10 05:24:37 PDT
All reviewed patches have been landed.  Closing bug.