Bug 218098

Summary: Duplicate checks in overridingContainingBlockContentXXX()
Product: WebKit Reporter: Sergio Villar Senin <svillar>
Component: WebCore Misc.Assignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: rbuis, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   

Description Sergio Villar Senin 2020-10-22 13:44:47 PDT
RenderBoxModelObject.h defines overridingContainingBlockContentWidth() and overridingContainingBlockContentHeight(). Both of them return an Optional<LayoutUnit> apparently to deal with the case of not having an overriding size in the containing block. However the very same file also defines hasOverridingContainingBlockContentWidth() and hasOverridingContainingBlockContentHeight(). This means that there are multiple occurrences of:

if (hasOverridingContainingBlockContentWidth())
    if (auto width = overridingContainingBlockContentWidth())
       return width.value();

duplicating the checks. We should figure out why that was done like this and remove the extra check if needed.

Note that RenderBox.h replicates the same pattern with hasOverridingContainingBlockContentLogical{Height|Width}()
Comment 1 Radar WebKit Bug Importer 2020-10-29 13:45:16 PDT
<rdar://problem/70823764>
Comment 2 Rob Buis 2021-04-30 09:18:18 PDT
This is probably not possible. The code wants to distinguish between nullopt as in "there is nothing set" and "there is something set but it is not a number":
    if (logicalHeight.isPercentOrCalculated() && hasOverridingContainingBlockContentLogicalHeight())
        return overridingContainingBlockContentLogicalHeight() == WTF::nullopt;

It may be possible to set some magic value not nullopt for "there is something set but it is not a number" but I don't think it is worth it personally.