Bug 219378

Summary: Web Inspector: InspectorFrontendAPIDispatcher should not ignore all exceptions
Product: WebKit Reporter: BJ Burg <bburg>
Component: Web InspectorAssignee: BJ Burg <bburg>
Status: RESOLVED FIXED    
Severity: Normal CC: bburg, ews-watchlist, hi, inspector-bugzilla-changes, joepeck, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch v1
none
Patch v1.1 - Fix failing test.
none
Patch v1.2 - fix Debug Mac none

Description BJ Burg 2020-11-30 16:15:38 PST
This makes it extremely difficult to debug problems when hacking, and it would be good to at least log exceptions that are raised by internal evaluations.
Comment 1 BJ Burg 2020-11-30 16:25:15 PST
Created attachment 415074 [details]
Patch v1
Comment 2 BJ Burg 2020-11-30 16:27:35 PST
I noticed a few tests timing out locally, so I'm interested to see if this happens on the bots. In theory it shouldn't have caused tests to be any slower because it's still calling the underlying ScriptController method.
Comment 3 Devin Rousso 2020-12-01 10:53:31 PST
Comment on attachment 415074 [details]
Patch v1

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

r=mews

> Source/WebCore/inspector/InspectorFrontendClientLocal.cpp:328
> +Optional<bool> InspectorFrontendClientLocal::evaluationResultToBoolean(InspectorFrontendAPIDispatcher::EvaluationResult result)

Rather than `Optional<bool>` should we always just `.valueOr(false)`?

> Source/WebCore/inspector/InspectorFrontendClientLocal.cpp:334
> +    if (valueOrException)

I'd make this `if (!valueOrException)` so that we early-return for failure (that seems to be our usual pattern too)

> Source/WebCore/inspector/InspectorFrontendClientLocal.h:137
> +    Optional<bool> evaluationResultToBoolean(InspectorFrontendAPIDispatcher::EvaluationResult);

Why not make this `static` in the `.cpp`?

> Source/WebKit/WebProcess/Inspector/WebInspectorUIExtensionController.cpp:59
> +    if (!result.has_value()) {

I don't think the `has_value` is needed as `operator bool` does the same thing

> Source/WebKit/WebProcess/Inspector/WebInspectorUIExtensionController.cpp:65
> +        default:

NIT: I personally prefer avoiding `default` so that if new enum values are added then there's a compile error (which brings visibility to the usage here, causing the programmer to make a conscious decision about it instead of it being silent)

> Source/WebKit/WebProcess/Inspector/WebInspectorUIExtensionController.cpp:77
> +    if (!valueOrException.has_value()) {

ditto (:59)
Comment 4 BJ Burg 2020-12-02 10:00:33 PST
(In reply to Devin Rousso from comment #3)
> Comment on attachment 415074 [details]
> Patch v1
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=415074&action=review
> 
> r=mews
> 
> > Source/WebCore/inspector/InspectorFrontendClientLocal.cpp:328
> > +Optional<bool> InspectorFrontendClientLocal::evaluationResultToBoolean(InspectorFrontendAPIDispatcher::EvaluationResult result)
> 
> Rather than `Optional<bool>` should we always just `.valueOr(false)`?

I was hesitant, but it's probably OK since this is a private method only used by this class.

> 
> > Source/WebCore/inspector/InspectorFrontendClientLocal.cpp:334
> > +    if (valueOrException)
> 
> I'd make this `if (!valueOrException)` so that we early-return for failure
> (that seems to be our usual pattern too)
> 
> > Source/WebCore/inspector/InspectorFrontendClientLocal.h:137
> > +    Optional<bool> evaluationResultToBoolean(InspectorFrontendAPIDispatcher::EvaluationResult);
> 
> Why not make this `static` in the `.cpp`?

To call JSC::JSValue::toBoolean(), we need to access the global object via m_frontendAPIDispatcher. So we'd have to pass around that context anyway. Easier to make it an instance method IMO.


> > Source/WebKit/WebProcess/Inspector/WebInspectorUIExtensionController.cpp:59
> > +    if (!result.has_value()) {
> 
> I don't think the `has_value` is needed as `operator bool` does the same
> thing

Given that this patch deals with JSValues that could be `true` or `false`, I found it hard to quickly understand when operator bool is checking the truthiness of JSValue or the Optional. This makes it explicit.

> 
> > Source/WebKit/WebProcess/Inspector/WebInspectorUIExtensionController.cpp:65
> > +        default:
> 
> NIT: I personally prefer avoiding `default` so that if new enum values are
> added then there's a compile error (which brings visibility to the usage
> here, causing the programmer to make a conscious decision about it instead
> of it being silent)

OK

> > Source/WebKit/WebProcess/Inspector/WebInspectorUIExtensionController.cpp:77
> > +    if (!valueOrException.has_value()) {
> 
> ditto (:59)
Comment 5 BJ Burg 2020-12-04 10:41:23 PST
Created attachment 415429 [details]
Patch v1.1 - Fix failing test.
Comment 6 BJ Burg 2020-12-04 11:27:21 PST
Created attachment 415437 [details]
Patch v1.2 - fix Debug Mac
Comment 7 EWS 2020-12-04 13:06:45 PST
Committed r270453: <https://trac.webkit.org/changeset/270453>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 415437 [details].
Comment 8 Radar WebKit Bug Importer 2020-12-04 13:07:17 PST
<rdar://problem/71990522>