Bug 196725 - Web Inspector: REGRESSION: lazy agents used outside of frontend/instrumentation can be accessed before being created
Summary: Web Inspector: REGRESSION: lazy agents used outside of frontend/instrumentati...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Devin Rousso
URL:
Keywords: InRadar
Depends on:
Blocks: 195971
  Show dependency treegraph
 
Reported: 2019-04-08 21:08 PDT by Devin Rousso
Modified: 2019-04-10 16:15 PDT (History)
7 users (show)

See Also:


Attachments
Patch (8.27 KB, patch)
2019-04-08 21:13 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (8.27 KB, patch)
2019-04-09 12:51 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 Devin Rousso 2019-04-08 21:08:19 PDT
`WebCore::InspectorFrontendClientLocal::showMainResourceForFrame` and `WebKit::WebInspector::showMainResourceForFrame` both access `WebCore::InspectorController::pageAgent`, even though the underlying `m_pageAgent` isn't instantiated until the first frontend connects.
Comment 1 Devin Rousso 2019-04-08 21:08:40 PDT
<rdar://problem/49669810>
Comment 2 Devin Rousso 2019-04-08 21:13:59 PDT
Created attachment 367025 [details]
Patch
Comment 3 Devin Rousso 2019-04-09 12:51:04 PDT
Created attachment 367064 [details]
Patch
Comment 4 Timothy Hatcher 2019-04-10 15:19:49 PDT
Comment on attachment 367064 [details]
Patch

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

> Source/WebCore/inspector/InspectorController.h:110
> -    InspectorPageAgent* pageAgent() const { return m_pageAgent; }
> +
> +    InspectorDOMAgent& ensureDOMAgent();
> +    WEBCORE_EXPORT InspectorPageAgent& ensurePageAgent();

Why not just have pageAgent() and a domAgent() getter create the agents if needed and drop the need for the ensure functions?
Comment 5 Devin Rousso 2019-04-10 15:34:53 PDT
Comment on attachment 367064 [details]
Patch

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

>> Source/WebCore/inspector/InspectorController.h:110
>> +    WEBCORE_EXPORT InspectorPageAgent& ensurePageAgent();
> 
> Why not just have pageAgent() and a domAgent() getter create the agents if needed and drop the need for the ensure functions?

I vaguely remember there being a discussion about this style on one of the webkit-* mailing lists.  I prefer the "ensure" as it makes it clearer to callers that this function might create an object, rather than just return whatever currently exists.
Comment 6 WebKit Commit Bot 2019-04-10 16:15:14 PDT
Comment on attachment 367064 [details]
Patch

Clearing flags on attachment: 367064

Committed r244167: <https://trac.webkit.org/changeset/244167>
Comment 7 WebKit Commit Bot 2019-04-10 16:15:15 PDT
All reviewed patches have been landed.  Closing bug.