Changeset 143239 in webkit


Ignore:
Timestamp:
Feb 18, 2013 10:21:59 AM (11 years ago)
Author:
mkwst@chromium.org
Message:

compareDocumentPosition reports disconnected nodes as following each other
https://bugs.webkit.org/show_bug.cgi?id=108274

Reviewed by Dimitri Glazkov.

Source/WebCore:

jQuery has had to implement their own sorting mechanism in Sizzle[1] due
to Node::compareDocumentPosition always reporting disconnected nodes
as following each other. According to spec[2], we should instead be
indicating that the result is (a) disconnected, (b) implementation
specific, and (c) deterministically ordered.

[1]: https://github.com/jquery/sizzle/commit/1c8aec91284af8d8c14447976235d5dd72b0d75e
[2]: http://dom.spec.whatwg.org/#dom-node-comparedocumentposition

Test: fast/dom/compare-document-position-disconnected-nodes.html

  • dom/Node.cpp:

(WebCore::Node::compareDocumentPosition):

After walking the parentNode chain of both Nodes, compare the root.
If the Nodes don't share a root, they're in distinct trees, and
should return as described above. We determine which element
"preceeds" the other in an arbitrary fashion via pointer comparison.

LayoutTests:

  • fast/dom/compare-document-position-disconnected-nodes-expected.txt: Added.
  • fast/dom/compare-document-position-disconnected-nodes.html: Added.
Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r143238 r143239  
     12013-02-18  Mike West  <mkwst@chromium.org>
     2
     3        compareDocumentPosition reports disconnected nodes as following each other
     4        https://bugs.webkit.org/show_bug.cgi?id=108274
     5
     6        Reviewed by Dimitri Glazkov.
     7
     8        * fast/dom/compare-document-position-disconnected-nodes-expected.txt: Added.
     9        * fast/dom/compare-document-position-disconnected-nodes.html: Added.
     10
    1112013-02-18  Stephen White  <senorblanco@chromium.org>
    212
  • trunk/Source/WebCore/ChangeLog

    r143237 r143239  
     12013-02-18  Mike West  <mkwst@chromium.org>
     2
     3        compareDocumentPosition reports disconnected nodes as following each other
     4        https://bugs.webkit.org/show_bug.cgi?id=108274
     5
     6        Reviewed by Dimitri Glazkov.
     7
     8        jQuery has had to implement their own sorting mechanism in Sizzle[1] due
     9        to Node::compareDocumentPosition always reporting disconnected nodes
     10        as following each other. According to spec[2], we should instead be
     11        indicating that the result is (a) disconnected, (b) implementation
     12        specific, and (c) deterministically ordered.
     13
     14        [1]: https://github.com/jquery/sizzle/commit/1c8aec91284af8d8c14447976235d5dd72b0d75e
     15        [2]: http://dom.spec.whatwg.org/#dom-node-comparedocumentposition
     16
     17        Test: fast/dom/compare-document-position-disconnected-nodes.html
     18
     19        * dom/Node.cpp:
     20        (WebCore::Node::compareDocumentPosition):
     21            After walking the parentNode chain of both Nodes, compare the root.
     22            If the Nodes don't share a root, they're in distinct trees, and
     23            should return as described above. We determine which element
     24            "preceeds" the other in an arbitrary fashion via pointer comparison.
     25
    1262013-02-18  Andrey Adaikin  <aandrey@chromium.org>
    227
  • trunk/Source/WebCore/dom/Node.cpp

    r143112 r143239  
    17861786    for (current = start2; current; current = current->parentNode())
    17871787        chain2.append(current);
    1788    
    1789     // Walk the two chains backwards and look for the first difference.
     1788
    17901789    unsigned index1 = chain1.size();
    17911790    unsigned index2 = chain2.size();
     1791
     1792    // If the two elements don't have a common root, they're not in the same tree.
     1793    if (chain1[index1 - 1] != chain2[index2 - 1]) {
     1794        unsigned short direction = (start1 > start2) ? DOCUMENT_POSITION_PRECEDING : DOCUMENT_POSITION_FOLLOWING;
     1795        return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | direction;
     1796    }
     1797
     1798    // Walk the two chains backwards and look for the first difference.
    17921799    for (unsigned i = min(index1, index2); i; --i) {
    17931800        Node* child1 = chain1[--index1];
Note: See TracChangeset for help on using the changeset viewer.