Changeset 117417 in webkit


Ignore:
Timestamp:
May 17, 2012 2:03:20 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

showNodePath will be useful for debugging purpose.
https://bugs.webkit.org/show_bug.cgi?id=86450

This patch implements showNodePath, which outputs node information in
a xpath-like format, e.g. /HTML/BODY/DIV[@id="test" and position()=0]/P[0]

Patch by Takashi Sakamoto <tasak@google.com> on 2012-05-17
Reviewed by Hajime Morita.

No new tests, just adding debugging interface.

  • dom/Node.cpp:

(WebCore::Node::showNodePathForThis):
(WebCore):
(showNodePath):

  • dom/Node.h:

(Node):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r117413 r117417  
     12012-05-17  Takashi Sakamoto  <tasak@google.com>
     2
     3        showNodePath will be useful for debugging purpose.
     4        https://bugs.webkit.org/show_bug.cgi?id=86450
     5
     6        This patch implements showNodePath, which outputs node information in
     7        a xpath-like format, e.g. /HTML/BODY/DIV[@id="test" and position()=0]/P[0]
     8
     9        Reviewed by Hajime Morita.
     10
     11        No new tests, just adding debugging interface.
     12
     13        * dom/Node.cpp:
     14        (WebCore::Node::showNodePathForThis):
     15        (WebCore):
     16        (showNodePath):
     17        * dom/Node.h:
     18        (Node):
     19
    1202012-05-17  Pravin D  <pravind.2k4@gmail.com>
    221
  • trunk/Source/WebCore/dom/Node.cpp

    r117353 r117417  
    22302230}
    22312231
     2232void Node::showNodePathForThis() const
     2233{
     2234    Vector<const Node*, 16> chain;
     2235    const Node* node = this;
     2236    while (node->parentOrHostNode()) {
     2237        chain.append(node);
     2238        node = node->parentOrHostNode();
     2239    }
     2240    for (unsigned index = chain.size(); index > 0; --index) {
     2241        const Node* node = chain[index - 1];
     2242        if (node->isShadowRoot()) {
     2243            int count = 0;
     2244            for (ShadowRoot* shadowRoot = oldestShadowRootFor(node); shadowRoot && shadowRoot != node; shadowRoot = shadowRoot->youngerShadowRoot())
     2245                ++count;
     2246            fprintf(stderr, "/#shadow-root[%d]", count);
     2247            continue;
     2248        }
     2249
     2250        switch (node->nodeType()) {
     2251        case ELEMENT_NODE: {
     2252            fprintf(stderr, "/%s", node->nodeName().utf8().data());
     2253
     2254            const Element* element = toElement(node);
     2255            const AtomicString& idattr = element->getIdAttribute();
     2256            bool hasIdAttr = !idattr.isNull() && !idattr.isEmpty();
     2257            if (node->previousSibling() || node->nextSibling()) {
     2258                int count = 0;
     2259                for (Node* previous = node->previousSibling(); previous; previous = previous->previousSibling())
     2260                    if (previous->nodeName() == node->nodeName())
     2261                        ++count;
     2262                if (hasIdAttr)
     2263                    fprintf(stderr, "[@id=\"%s\" and position()=%d]", idattr.string().utf8().data(), count);
     2264                else
     2265                    fprintf(stderr, "[%d]", count);
     2266            } else if (hasIdAttr)
     2267                fprintf(stderr, "[@id=\"%s\"]", idattr.string().utf8().data());
     2268            break;
     2269        }
     2270        case TEXT_NODE:
     2271            fprintf(stderr, "/text()");
     2272            break;
     2273        case ATTRIBUTE_NODE:
     2274            fprintf(stderr, "/@%s", node->nodeName().utf8().data());
     2275            break;
     2276        default:
     2277            break;
     2278        }
     2279    }
     2280    fprintf(stderr, "\n");
     2281}
     2282
    22322283static void traverseTreeAndMark(const String& baseIndent, const Node* rootNode, const Node* markedNode1, const char* markedLabel1, const Node* markedNode2, const char* markedLabel2)
    22332284{
     
    29232974}
    29242975
     2976void showNodePath(const WebCore::Node* node)
     2977{
     2978    if (node)
     2979        node->showNodePathForThis();
     2980}
     2981
    29252982#endif
  • trunk/Source/WebCore/dom/Node.h

    r117353 r117417  
    552552    void showNode(const char* prefix = "") const;
    553553    void showTreeForThis() const;
     554    void showNodePathForThis() const;
    554555    void showTreeAndMark(const Node* markedNode1, const char* markedLabel1, const Node* markedNode2 = 0, const char* markedLabel2 = 0) const;
    555556    void showTreeForThisAcrossFrame() const;
     
    862863// Outside the WebCore namespace for ease of invocation from gdb.
    863864void showTree(const WebCore::Node*);
    864 #endif
    865 
    866 #endif
     865void showNodePath(const WebCore::Node*);
     866#endif
     867
     868#endif
Note: See TracChangeset for help on using the changeset viewer.