Bug 146377 - Web Inspector: Add source links to functions logged in the console
Summary: Web Inspector: Add source links to functions logged in the console
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: Devin Rousso
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2015-06-26 20:42 PDT by Nikita Vasilyev
Modified: 2015-07-10 16:32 PDT (History)
9 users (show)

See Also:


Attachments
[Image] Expected (12.03 KB, image/png)
2015-06-26 20:42 PDT, Nikita Vasilyev
no flags Details
[Animated GIF] Chrome 43 (stable) behavior (98.99 KB, image/gif)
2015-06-28 22:50 PDT, Nikita Vasilyev
no flags Details
[Animated GIF] Chrome 45 (canary) behavior (86.49 KB, image/gif)
2015-06-28 22:51 PDT, Nikita Vasilyev
no flags Details
Patch (6.22 KB, patch)
2015-07-09 18:51 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff
[Image] Works as expected (124.48 KB, image/png)
2015-07-09 21:49 PDT, Nikita Vasilyev
no flags Details
[Image] Regression (163.15 KB, image/png)
2015-07-09 22:06 PDT, Nikita Vasilyev
no flags Details
Patch (6.96 KB, patch)
2015-07-10 10:26 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (9.24 KB, patch)
2015-07-10 11:55 PDT, Devin Rousso
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-06-26 20:42:47 PDT
Created attachment 255688 [details]
[Image] Expected

Currently, when I know a function name and I want to jump to its definition I need to:

1. >> dir({blah: someObj.myFunction})
   -> ► {blah: someObj.myFunction}
2. Click on ►
3. Right click on "myFunction"
4. Select "Jump to Definition"

It should be improved.
Comment 1 Radar WebKit Bug Importer 2015-06-26 20:43:05 PDT
<rdar://problem/21577210>
Comment 2 Nikita Vasilyev 2015-06-28 22:50:23 PDT
Created attachment 255735 [details]
[Animated GIF] Chrome 43 (stable) behavior
Comment 3 Nikita Vasilyev 2015-06-28 22:51:35 PDT
Created attachment 255736 [details]
[Animated GIF] Chrome 45 (canary) behavior
Comment 4 Devin Rousso 2015-07-09 18:51:22 PDT
Created attachment 256556 [details]
Patch
Comment 5 Nikita Vasilyev 2015-07-09 21:49:23 PDT
Created attachment 256565 [details]
[Image] Works as expected

👍
Comment 6 Joseph Pecoraro 2015-07-09 21:57:19 PDT
Comment on attachment 256556 [details]
Patch

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

r=me, but a few minor things we should cleanup.

> Source/WebInspectorUI/UserInterface/Views/ConsoleMessageView.css:234
> +    font-family: -webkit-system-font, sans-serif;
> +    font-size: 12px;

This should have a comment in the changelog. Why did it look wrong before to justify this change. Seems fine.

> Source/WebInspectorUI/UserInterface/Views/ConsoleMessageView.js:332
> +        if (this._message.type === WebInspector.ConsoleMessage.MessageType.Result || this._message.parameters.length === 1) {

I think this is redundant. A ConsoleMessage Result will/should only have 1 parameter. So just the second check should be fine.

> Source/WebInspectorUI/UserInterface/Views/ConsoleMessageView.js:333
> +            DebuggerAgent.getFunctionDetails(this._message.parameters[0].objectId, function(error, response) {

Not all RemoteObjects have an objectId. Only those that are non-primitives. So this would likely produce an error for primitive RemoteObject's. I'd suggest checking if it is a function first:

    var singleLoggedObject = this._message.parameters;
    if (singleLoggedObject.type === "function") {
        ..
    }

> Source/WebInspectorUI/UserInterface/Views/ConsoleMessageView.js:346
> +                // Need to add 1 to sourceCodeLocation.lineNumber because the first line is index 0.
> +                var link = this._linkifyLocation(sourceCode.url, sourceCodeLocation.lineNumber + 1, sourceCodeLocation.columnNumber);

This is interesting, since linkifyLocation removes the +1. Maybe we should fix the comment (and +1 to columnNumber here):

            // Debugger.Location stack trace line numbers are zero-based.

You may want to change the current "linkifyLocation" to "linkifyCallFrameLocation" or "linkifyOneBasedLocation" and add a new one for zero based.

> Source/WebInspectorUI/UserInterface/Views/ConsoleMessageView.js:347
> +                link.classList.add("console-message-location", "source-link");

Do you need source-link? How is this different from the console-message-location used in network location links (like 404s)?
Comment 7 Nikita Vasilyev 2015-07-09 22:06:28 PDT
Created attachment 256566 [details]
[Image] Regression

CSS warnings don't show up anymore. Reproducible on http://n12v.com.
Comment 8 Nikita Vasilyev 2015-07-09 22:24:09 PDT
Comment on attachment 256556 [details]
Patch

r- because of the regression mentioned above.
Comment 9 Devin Rousso 2015-07-10 10:26:59 PDT
Created attachment 256585 [details]
Patch
Comment 10 Timothy Hatcher 2015-07-10 10:46:37 PDT
Comment on attachment 256585 [details]
Patch

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

> Source/WebInspectorUI/UserInterface/Views/ConsoleMessageView.js:339
> +            if (parameter.type !== "function" || !parameter.objectId)
> +                return;
> +
> +            DebuggerAgent.getFunctionDetails(parameter.objectId, function(error, response) {
> +                if (error)
> +                    return;
> +
> +                var location = response.location;
> +                var sourceCode = WebInspector.debuggerManager.scriptForIdentifier(location.scriptId);
> +
> +                if (!sourceCode || sourceCode.url.startsWith("__WebInspector"))
> +                    return;

Ideally this would be a function on RemoteObject or DebuggerManager to get this and not use the protocol agents directly in a view like this. It could take a RemoteObject and return a SourceCodeLocation if available. Then if more objects get support for a location, the view won't need to change. It would need to return a Promise. You can also use promises with agents like: DebuggerAgent.getFunctionDetails(parameter.objectId).then(...).
Comment 11 Devin Rousso 2015-07-10 11:55:53 PDT
Created attachment 256599 [details]
Patch
Comment 12 WebKit Commit Bot 2015-07-10 16:32:13 PDT
Comment on attachment 256599 [details]
Patch

Clearing flags on attachment: 256599

Committed r186695: <http://trac.webkit.org/changeset/186695>
Comment 13 WebKit Commit Bot 2015-07-10 16:32:19 PDT
All reviewed patches have been landed.  Closing bug.