[webkit-dev] Do we have a style preference about const member functions?

Darin Adler darin at apple.com
Fri Jun 3 07:50:46 PDT 2011


On Jun 2, 2011, at 1:32 AM, Ryosuke Niwa wrote:

> All functions passed to enclosingNodeOfType in htmlediting.cpp are such clients:
> 
> Node* enclosingNodeOfType(const Position& p, bool (*nodeIsOfType)(const Node*), EditingBoundaryCrossingRule rule)
> 
> It takes a boolean function that takes const pointer to a DOM node.  It is critical that nodeIsOfType does not modify DOM

This points to a place where const does not work well. Having the single node pointer that is the argument to the function be const does not express “must not modify DOM”.

If there was some way to express “must not modify DOM” that would be great, but that just expresses “must not modify this DOM node”.

It happens that the predicate takes a node argument. You could imagine a similar function that takes a Range. You can see that that’s an even clearer. There’s no way to pass a range to a function and also say “must not modify DOM”. I don’t think const is a good way to express this.

    -- Darin



More information about the webkit-dev mailing list