[webkit-dev] Behavior change: is<>(T*) is now doing a null check on the pointer argument

Chris Dumez cdumez at apple.com
Thu Oct 2 12:59:02 PDT 2014


I would like to bring attention to a behavior change I have just landed [1]. The is<>(T*) type checking function is now doing a null-check on the pointer argument instead of simply asserting that the pointer argument should not be null.

Please keep this in mind in your future patches:
- If you know the pointer cannot be null (because a null check was done earlier in the function), then call the is<>(T&) overload taking a reference in argument to avoid the null check: e.g. “if (is<HTMLDivElement>(*node)) …"
- Do not do an explicit null check on the pointer before calling is<>(T*). “if (node && is<HTMLDivElement>(node))” -> "if (is<HTMLDivElement(node))"

This change was made because:
- It simplifies the code a bit as it avoids a lot of explicit null checks.
- It is more consistent with downcast<>(T*) which will correctly cast a null pointer.
- Having a is<>(T*) overload in addition to is<>(T&) was previously only helpful to avoid having to dereference the pointer. Dereferencing is just one ‘*’ character and doesn’t decrease code readability much IMHO. However, getting rid of a lot of explicit null checks does simplify the code quite a bit.

FYI, all Node subclasses should now support is<>() / downcast<>() already. I am in the process of porting non-Node classes over as well for consistency (WorkerGlobalScope class, File class and Event subclasses were already ported for e.g.).
If you try to use is<>() / downcast<>() for a class that doesn’t support it yet, you should now get a clear build error (instead of the obscure linking error we would get previously).

Chris Dumez - Apple Inc.
Cupertino, CA

[1]  http://trac.webkit.org/changeset/174225 <http://trac.webkit.org/changeset/174225>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-dev/attachments/20141002/bddaae90/attachment.html>

More information about the webkit-dev mailing list