[Webkit-unassigned] [Bug 137418] Implement closest() API

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Fri Oct 3 23:33:51 PDT 2014


https://bugs.webkit.org/show_bug.cgi?id=137418


Darin Adler <darin at apple.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
 Attachment #239265|review?                     |review-
               Flag|                            |




--- Comment #2 from Darin Adler <darin at apple.com>  2014-10-03 23:33:48 PST ---
(From update of attachment 239265)
View in context: https://bugs.webkit.org/attachment.cgi?id=239265&action=review

review- because of the bad cast

> Source/WebCore/dom/Element.cpp:2329
> +    SelectorQuery* selectorQuery = document().selectorQueryForString(selector, ec);
> +    if (selectorQuery)
> +        return selectorQuery->closest(*this);
> +    return nullptr;

WebKit coding style prefers early return, meaning:

    if (!selectorQuery)
        return nullptr;

> Source/WebCore/dom/SelectorQuery.cpp:128
> +    Element* currentNode = (Element *) &rootNode;

The formatting here isn’t right, but more importantly this is a bad cast if the root node is a document node. That needs to be fixed.

> Source/WebCore/dom/SelectorQuery.cpp:151
> +    unsigned selectorCount = m_selectors.size();
> +    for (unsigned i = 0; i < selectorCount; ++i) {
> +        Element* closestElement = selectorClosest(m_selectors[i], targetElement, targetElement);

This should use a modern for loop:

    for (auto& selector : m_selectors) {
        if (Element* closestElement = selectorClosest(selector, targetElement, targetElement))
            return closestElement;
    }

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.


More information about the webkit-unassigned mailing list