Bug 237604 - Use PropertyRegistry consistently in svgAttributeChanged
Summary: Use PropertyRegistry consistently in svgAttributeChanged
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: SVG (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Rob Buis
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-03-08 06:59 PST by Rob Buis
Modified: 2022-03-10 07:54 PST (History)
11 users (show)

See Also:


Attachments
Patch (22.45 KB, patch)
2022-03-08 07:01 PST, Rob Buis
no flags Details | Formatted Diff | Diff
Patch (20.26 KB, patch)
2022-03-09 08:51 PST, Rob Buis
no flags Details | Formatted Diff | Diff
Patch (21.12 KB, patch)
2022-03-10 01:59 PST, Rob Buis
no flags Details | Formatted Diff | Diff
Patch (24.15 KB, patch)
2022-03-10 04:19 PST, Rob Buis
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Rob Buis 2022-03-08 06:59:18 PST
Use PropertyRegistry consistently in svgAttributeChanged.
Comment 1 Rob Buis 2022-03-08 07:01:41 PST
Created attachment 454118 [details]
Patch
Comment 2 Nikolas Zimmermann 2022-03-09 02:25:47 PST
Comment on attachment 454118 [details]
Patch

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

Unofficial review: Looks good, just a few comments.

> Source/WebCore/ChangeLog:8
> +        Use PropertyRegistry consistently in svgAttributeChanged.

This is a bit too thin, I'd state that most svgAttributeChanged() methods start with if (PropReg::isKnownAttr(...)) and some are missing, and that you're unifying this for consistency reasons.

> Source/WebCore/svg/SVGFEBlendElement.cpp:86
> +    if (PropertyRegistry::isKnownAttribute(attrName)) {

out of curiosity, did you check that each of the isKnownAttribute() functions has exactly the same attributes registered as we atually handle in svgAttributeChanged().
Could be that we missed something in the past, that's now fixed, by this usage pattern (no explicit check for all the attribute names, but instead use isKnownAttribute()).

> Source/WebCore/svg/SVGFEComponentTransferElement.cpp:65
> +void SVGFEComponentTransferElement::svgAttributeChanged(const QualifiedName& attrName)

This needs a test :/

> Source/WebCore/svg/SVGImageElement.cpp:107
> +        else {

else if (auto* ..
Comment 3 Rob Buis 2022-03-09 08:51:38 PST
Created attachment 454244 [details]
Patch
Comment 4 Rob Buis 2022-03-09 08:54:20 PST
Comment on attachment 454118 [details]
Patch

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

>> Source/WebCore/ChangeLog:8
>> +        Use PropertyRegistry consistently in svgAttributeChanged.
> 
> This is a bit too thin, I'd state that most svgAttributeChanged() methods start with if (PropReg::isKnownAttr(...)) and some are missing, and that you're unifying this for consistency reasons.

Done.

>> Source/WebCore/svg/SVGFEBlendElement.cpp:86
>> +    if (PropertyRegistry::isKnownAttribute(attrName)) {
> 
> out of curiosity, did you check that each of the isKnownAttribute() functions has exactly the same attributes registered as we atually handle in svgAttributeChanged().
> Could be that we missed something in the past, that's now fixed, by this usage pattern (no explicit check for all the attribute names, but instead use isKnownAttribute()).

I did by cross checking all changed files. One thing I missed though is that SVGFEDiffuseLightingElement::svgAttributeChanged incorrectly checked for SVGNames::lighting_colorAttr!

>> Source/WebCore/svg/SVGFEComponentTransferElement.cpp:65
>> +void SVGFEComponentTransferElement::svgAttributeChanged(const QualifiedName& attrName)
> 
> This needs a test :/

Ok I removed this part since it is not high priority at all.

>> Source/WebCore/svg/SVGImageElement.cpp:107
>> +        else {
> 
> else if (auto* ..

Done.
Comment 5 Nikolas Zimmermann 2022-03-10 01:38:32 PST
(In reply to Rob Buis from comment #4)
> > This needs a test :/
> 
> Ok I removed this part since it is not high priority at all.

Can you still create a ticket, add a FIXME that the svgAttributeChanged() implementation is missing with a ref to the new ticket?

Other than that, the last iteration looks great, unofficial r=me :-)
Comment 6 Rob Buis 2022-03-10 01:59:49 PST
Created attachment 454327 [details]
Patch
Comment 7 Martin Robinson 2022-03-10 03:27:44 PST
Comment on attachment 454327 [details]
Patch

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

Looks good to me, assuming that PropertyRegistry::isKnownAttribute works knowing the calling class. I would also add ASSERTs in the places where the code is making assumptions about what the remaining attributes to handle are.

> Source/WebCore/svg/SVGFEBlendElement.cpp:94
> +    if (PropertyRegistry::isKnownAttribute(attrName)) {
>          InstanceInvalidationGuard guard(*this);
> -        primitiveAttributeChanged(attrName);
> -        return;
> -    }
> -
> -    if (attrName == SVGNames::inAttr || attrName == SVGNames::in2Attr) {
> -        InstanceInvalidationGuard guard(*this);
> -        invalidate();
> +        if (attrName == SVGNames::modeAttr)
> +            primitiveAttributeChanged(attrName);
> +        else
> +            invalidate();
>          return;
>      }
>  

I believe in all the cases where the code assumes that a particular attribute is being handled in an else or a default code path, an assertion will make things a lot more understandable for the reader. Before it was easier to see what behavior corresponded to what attribute and the assertion will help to maintain the same readability. So here you could ASSERT(attrName == SVGNames::inAttr || attrName == SVGNames::in2Attr) in the else path.

> Source/WebCore/svg/SVGPathElement.cpp:69
> -    if (attrName == SVGNames::dAttr) {
> +    if (PropertyRegistry::isKnownAttribute(attrName)) {
>          InstanceInvalidationGuard guard(*this);

I think in these cases as well, an assertion could make the code a bit more understandable.
Comment 8 Rob Buis 2022-03-10 04:19:09 PST
Created attachment 454332 [details]
Patch
Comment 9 EWS 2022-03-10 07:53:41 PST
Committed r291108 (248270@main): <https://commits.webkit.org/248270@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 454332 [details].
Comment 10 Radar WebKit Bug Importer 2022-03-10 07:54:22 PST
<rdar://problem/90098010>