[webkit-dev] Stricter type checking in downcast<>()

Chris Dumez cdumez at apple.com
Wed Dec 20 12:30:47 PST 2023


I have recently landed stricter type checking in downcast<>() [1]. It is stricter because the check is now happening in release / production builds on some platforms (ARM-based).
My objective is to enable to check in release on all platforms in the near future (still a small performance hit on remaining platforms at the moment).

Because of this, it is now recommended to use dynamicDowncast<>() instead of is<>() + downcast<>(), to avoid duplicating the type check.
dynamicDowncast<>() is also less error-prone and often results in more concise code.

If you have a case where performance matters and you’re confident a type check is not required, you may rely on uncheckedDowncast<>().
uncheckedDowncast<>() behaves the same way downcast<>() used to before my change (type check on debug builds only).

One such example I’ve seen in our codebase is when using a switch statement based on the type:
switch (node.nodeType()) {
    case Node::DOCUMENT_TYPE_NODE:

Please let me know if you have any concerns / questions.

Chris Dumez.

[1] https://commits.webkit.org/272296@main

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20231220/65d1660c/attachment.htm>

More information about the webkit-dev mailing list