Bug 137004 - Use downcast<SVG*Element>() instead of toSVG*Element()
Summary: Use downcast<SVG*Element>() instead of toSVG*Element()
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords:
Depends on: 136839
Blocks:
  Show dependency treegraph
 
Reported: 2014-09-22 09:23 PDT by Chris Dumez
Modified: 2014-09-22 23:01 PDT (History)
6 users (show)

See Also:


Attachments
Patch (124.44 KB, patch)
2014-09-22 09:27 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (131.48 KB, patch)
2014-09-22 10:34 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (147.49 KB, patch)
2014-09-22 15:51 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (147.71 KB, patch)
2014-09-22 16:30 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2014-09-22 09:23:09 PDT
Use downcast<SVG*Element>() instead of toSVG*Element() and get rid of the transition macros for SVG Elements.
Comment 1 Chris Dumez 2014-09-22 09:27:27 PDT
Created attachment 238484 [details]
Patch
Comment 2 Chris Dumez 2014-09-22 10:34:58 PDT
Created attachment 238486 [details]
Patch
Comment 3 Benjamin Poulain 2014-09-22 14:41:38 PDT
Comment on attachment 238486 [details]
Patch

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

IMHO, you should review the use of pointers in the cases with:
    if (foo and foo->isBar())
        downcast<Bar>(foo)->bang();

Some of them use "downcast<Bar>(foo)->bang();", other do "downcast<Bar>(*foo).bang();". Unifying the style would be nice.

> Source/WebCore/accessibility/AccessibilityNodeObject.cpp:1503
> +        return downcast<SVGElement>(m_node)->title();

downcast<SVGElement>(*m_node).title()

> Source/WebCore/accessibility/AccessibilityRenderObject.cpp:2886
> +    SVGSVGElement* rootElement = downcast<SVGDocument>(doc)->rootElement();

ditto.

> Source/WebCore/css/CSSCursorImageValue.cpp:53
>      return 0;

nullptr

> Source/WebCore/rendering/RenderTableCell.cpp:183
> -        // Nowrap is set, but we didn't actually use it because of the
> +        // Nowrap is set, but we didtoSVGImageElementn't actually use it because of the

hahahaha

> Source/WebCore/rendering/svg/RenderSVGResourceClipper.cpp:99
> -        SVGGraphicsElement* styled = toSVGGraphicsElement(childNode);
> +        SVGGraphicsElement* styled = downcast<SVGGraphicsElement>(childNode);

Looks like this should be a ref.

> Source/WebCore/rendering/svg/RenderSVGResourceContainer.cpp:215
> -    SVGGraphicsElement* element = toSVGGraphicsElement(object->node());
> +    SVGGraphicsElement* element = downcast<SVGGraphicsElement>(object->node());

ditto.

> Source/WebCore/rendering/svg/RenderSVGTextPath.cpp:51
> -    SVGPathElement* pathElement = toSVGPathElement(targetElement);
> +    SVGPathElement* pathElement = downcast<SVGPathElement>(targetElement);

ditto.

> Source/WebCore/rendering/svg/RenderSVGTransformableContainer.cpp:44
>      SVGUseElement* useElement = 0;

nullptr

> Source/WebCore/rendering/svg/SVGRenderSupport.cpp:255
> +            if (SVGElement* element = child->node()->isSVGElement() ? downcast<SVGElement>(child->node()) : 0) {

nullptr

> Source/WebCore/rendering/svg/SVGRenderingContext.cpp:109
> +        SVGGraphicsElement& graphicsElement = *downcast<SVGGraphicsElement>(renderer.element());

I would put the dereference inside the downcast... not important though.

> Source/WebCore/rendering/svg/SVGTextLayoutEngine.cpp:429
> -    SVGElement* lengthContext = toSVGElement(text->parent()->element());
> +    SVGElement* lengthContext = downcast<SVGElement>(text->parent()->element());
>      
>      RenderObject* textParent = text->parent();
>      bool definesTextLength = textParent ? parentDefinesTextLength(textParent) : false;

There is something very very wrong going here, you should add a test.

text->parent() can be null apparently since it is checked by the ternary operator. BUT, it is used for lengthContext.

> Source/WebCore/svg/SVGDocument.cpp:48
>      return 0;

nullptr

> Source/WebCore/svg/SVGSVGElement.cpp:667
>              if (element->hasTagName(SVGNames::svgTag)) {

Can this be isSVGSVGElement()?

> Source/WebCore/svg/SVGTextContentElement.cpp:294
>          return 0;

nullptr

> Source/WebCore/svg/SVGTextContentElement.cpp:300
>          return 0;

nullptr

> Source/WebCore/svg/animation/SVGSMILElement.cpp:171
> +    SVGElement* svgTarget = target && target->isSVGElement() ? downcast<SVGElement>(target) : 0;

nullptr
Comment 4 Darin Adler 2014-09-22 15:15:11 PDT
(In reply to comment #3)
> Some of them use "downcast<Bar>(foo)->bang();", other do "downcast<Bar>(*foo).bang();". Unifying the style would be nice.

downcast<Bar>(foo)->bang() -- prettier
downcast<Bar>(*foo).bang() -- clearer to the compiler when generating the code for downcast that foo can't be null, but modern compilers probably get this right already, since it knows that foo was dereferenced a couple lines earlier

I’ve been using downcast<Bar>(*foo).bang() because I never want to depend on the compiler to not add a bogus null check.
Comment 5 Chris Dumez 2014-09-22 15:51:34 PDT
Created attachment 238500 [details]
Patch
Comment 6 Chris Dumez 2014-09-22 16:30:58 PDT
Created attachment 238504 [details]
Patch
Comment 7 WebKit Commit Bot 2014-09-22 17:55:12 PDT
Comment on attachment 238504 [details]
Patch

Clearing flags on attachment: 238504

Committed r173859: <http://trac.webkit.org/changeset/173859>
Comment 8 WebKit Commit Bot 2014-09-22 17:55:17 PDT
All reviewed patches have been landed.  Closing bug.
Comment 9 Csaba Osztrogonác 2014-09-22 22:36:50 PDT
(In reply to comment #7)
> (From update of attachment 238504 [details])
> Clearing flags on attachment: 238504
> 
> Committed r173859: <http://trac.webkit.org/changeset/173859>
It broke the debug builds, please fix.
Comment 10 Chris Dumez 2014-09-22 22:43:24 PDT
(In reply to comment #9)
> (In reply to comment #7)
> > (From update of attachment 238504 [details] [details])
> > Clearing flags on attachment: 238504
> > 
> > Committed r173859: <http://trac.webkit.org/changeset/173859>
> It broke the debug builds, please fix.

Thanks for notifying me. I'll take a look now.
Comment 11 Chris Dumez 2014-09-22 23:01:06 PDT
(In reply to comment #10)
> (In reply to comment #9)
> > (In reply to comment #7)
> > > (From update of attachment 238504 [details] [details] [details])
> > > Clearing flags on attachment: 238504
> > > 
> > > Committed r173859: <http://trac.webkit.org/changeset/173859>
> > It broke the debug builds, please fix.
> 
> Thanks for notifying me. I'll take a look now.

http://trac.webkit.org/changeset/173866 should fix the build but I'll watch the bots to make sure.