Index: Source/core/dom/Node.cpp |
diff --git a/Source/core/dom/Node.cpp b/Source/core/dom/Node.cpp |
index 40451028714cdc68d6d185eb6649bd53ceb980b1..73c249cdb1e28730d1a69233b26657319751f0fe 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; |
+ 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; |
} |