[webkit-dev] Type cast by using toFoo()

Sam Weinig weinig at apple.com
Mon Sep 30 09:53:31 PDT 2013


On Sep 30, 2013, at 3:39 AM, Gyuyoung Kim <gyuyoung.kim at webkit.org> wrote:

> Hello WebKittens,
> 
> I have focused on using toFoo() for SVG and CSS instead of using static_cast<>.  Because I think there are some advantages when we use it.
> 
>   - Bad type cast can be detected by using ASSERTION in toFoo(). The toFoo() function has an ASSERTION to check if source value is a proper super class.
>   - Unnecessary local variables can be removed. There are some local variables, which are only used once in WebKit. In those cases, we don’t need to use a local variable. Besides, we can remove unnecessary ASSERTION because toFoo() already has it.
>   - I believe toFoo() can improve code readability.
> 
> Currently, HTML, SVG Elements support toHTML|SVGFooElement() and CSSValue also starts to support toCSSFooValue(). Please check if there is toFoo() when you need to use static_cast<> in HTML, SVG and CSS module.

Nice.

> 
> Finally I plan to add this toFoo() policy to the WebKit style checker.

Can you explain more about this?  How are you going to determine static_casts that are acceptable from ones that aren’t.

-Sam



More information about the webkit-dev mailing list