Chromium Code Reviews| Index: Source/core/dom/Node.cpp |
| diff --git a/Source/core/dom/Node.cpp b/Source/core/dom/Node.cpp |
| index b34efbfa762918f7197678e562d135280e0f1bac..a8e04bd6dbd65ca8de69708a7a5f7b5ebb4de80c 100644 |
| --- a/Source/core/dom/Node.cpp |
| +++ b/Source/core/dom/Node.cpp |
| @@ -1704,8 +1704,10 @@ unsigned short Node::compareDocumentPositionInternal(const Node* otherNode, Shad |
| // If either of start1 or start2 is null, then we are disconnected, since one of the nodes is |
| // an orphaned attribute node. |
| - if (!start1 || !start2) |
| - return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC; |
| + if (!start1 || !start2) { |
| + unsigned short direction = (this > otherNode) ? DOCUMENT_POSITION_PRECEDING : DOCUMENT_POSITION_FOLLOWING; |
|
adamk
2013/07/24 22:22:14
These pointer comparisons look totally bogus to me
|
| + return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | direction; |
| + } |
| Vector<const Node*, 16> chain1; |
| Vector<const Node*, 16> chain2; |
| @@ -1739,10 +1741,10 @@ unsigned short Node::compareDocumentPositionInternal(const Node* otherNode, Shad |
| // If one node is in the document and the other is not, we must be disconnected. |
| // If the nodes have different owning documents, they must be disconnected. Note that we avoid |
| // comparing Attr nodes here, since they return false from inDocument() all the time (which seems like a bug). |
| - if (start1->inDocument() != start2->inDocument()) |
| - return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC; |
| - if (treatment == TreatShadowTreesAsDisconnected && start1->treeScope() != start2->treeScope()) |
| - return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC; |
| + if (start1->inDocument() != start2->inDocument() || (treatment == TreatShadowTreesAsDisconnected && start1->treeScope() != start2->treeScope())) { |
| + unsigned short direction = (this > otherNode) ? DOCUMENT_POSITION_PRECEDING : DOCUMENT_POSITION_FOLLOWING; |
| + return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | direction; |
| + } |
| // We need to find a common ancestor container, and then compare the indices of the two immediate children. |
| const Node* current; |
| @@ -1756,7 +1758,7 @@ unsigned short Node::compareDocumentPositionInternal(const Node* otherNode, Shad |
| // If the two elements don't have a common root, they're not in the same tree. |
| if (chain1[index1 - 1] != chain2[index2 - 1]) { |
| - unsigned short direction = (start1 > start2) ? DOCUMENT_POSITION_PRECEDING : DOCUMENT_POSITION_FOLLOWING; |
| + unsigned short direction = (this > otherNode) ? DOCUMENT_POSITION_PRECEDING : DOCUMENT_POSITION_FOLLOWING; |
| return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | direction; |
| } |