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

Yong Li yong.li.webkit at outlook.com
Mon Sep 30 09:54:35 PDT 2013


I think it can be done by checking the vtable pointer if the classes are virtual.



From: Sam Weinig
Sent: ‎Monday‎, ‎September‎ ‎30‎, ‎2013 ‎12‎:‎53‎ ‎PM
To: Gyuyoung Kim
Cc: Webkit Development List



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

_______________________________________________
webkit-dev mailing list
webkit-dev at lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20130930/f930adce/attachment.html>


More information about the webkit-dev mailing list