[Bug 19555] Node.getDocumentPosition should return 0x23 or 0x25 for disconnected nodes, not 0x01

https://www.w3.org/Bugs/Public/show_bug.cgi?id=19555

--- Comment #4 from Aryeh Gregor <ayg@aryeh.name> ---
It's always possible to implement this feature by picking a random result when
needed and then remembering it for future calls.  In JS, you could do this for
nodeA.compareDocumentPosition(nodeB):

  var rootA = nodeA;
  while (rootA.parentNode) {
    rootA = rootA.parentNode;
  }
  var rootB = nodeB;
  while (rootB.parentNode) {
    rootB = rootB.parentNode;
  }
  if (rootA != rootB) {
    if (rootA.randomValue === undefined) {
      rootA.randomValue = Math.random();
    }
    if (rootB.randomValue === undefined) {
      rootB.randomValue = Math.random();
    }
    return Node.NODE_DOCUMENT_POSITION_DISCONNECTED |
           Node.NODE_DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC |
           (rootA.randomValue < rootB.randomValue ?
            Node.DOCUMENT_POSITION_PRECEDING :
            Node.DOCUMENT_POSITION_FOLLOWING);
  }
  // Same-root case, not relevant here

This would in practice probably not be impractically expensive, and I believe
it meets the spec (unless Math.random() returns the same value twice).

-- 
You are receiving this mail because:
You are the QA Contact for the bug.

Received on Tuesday, 30 October 2012 12:09:05 UTC