<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>19555</bug_id>
          
          <creation_ts>2012-10-16 15:21:06 +0000</creation_ts>
          <short_desc>Node.getDocumentPosition should return 0x23 or 0x25 for disconnected nodes, not 0x01</short_desc>
          <delta_ts>2012-11-10 19:04:13 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>DOM</component>
          <version>unspecified</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>13044</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Aryeh Gregor">ayg</reporter>
          <assigned_to name="Anne">annevk</assigned_to>
          <cc>bzbarsky</cc>
    
    <cc>mike</cc>
    
    <cc>Ms2ger</cc>
    
    <cc>www-dom</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>76396</commentid>
    <comment_count>0</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2012-10-16 15:21:06 +0000</bug_when>
    <thetext>See discussion here:

https://bugzilla.mozilla.org/show_bug.cgi?id=486002

IE, Firefox, and Opera all implement the DOM Level 3 Core spec.  That means that for any two given disconnected nodes, they&apos;ll return either

  Node.DOCUMENT_POSITION_DISCONNECTED |
  Node.DOCUMENT_POSITION_PRECEDING |
  Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC

or

  Node.DOCUMENT_POSITION_DISCONNECTED |
  Node.DOCUMENT_POSITION_FOLLOWING |
  Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC

consistently, as long as each one&apos;s root node has no parent.  (In practice, Gecko does a pointer comparison between pointers to the root nodes, where the pointer used is unique and stable for any given node.  Probably IE/Opera are similar.)

This is meant to be used for sorting arbitrary lists of nodes uniquely.  In fact, jQuery exposes a function that does exactly that.  But the current spec says to just return 0x01, which very well might break jQuery.  jQuery relies on the sort being a total order because it passes a function based on it to JS&apos; .sort() method, which has undefined behavior for bogus sort functions.

In practice, the method is horrible enough (bitfields in JS!) that I don&apos;t think it&apos;s worth making it prettier.  I say we should just spec it like DOM Level 3 Core.  People can use .contains(), and we could add .isBefore()/.isAfter() methods to round it out if we want.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>77201</commentid>
    <comment_count>1</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2012-10-28 12:25:56 +0000</bug_when>
    <thetext>Anne and I discussed on IRC.  Result:

&lt;annevk&gt; I have to pack a few more things and go, maybe add a pointer to the bug about this discussion and just go with the DOM3 behavior for now
&lt;annevk&gt; it&apos;s evil, but I can&apos;t think of anything better</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>77202</commentid>
    <comment_count>2</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-10-28 13:13:42 +0000</bug_when>
    <thetext>So what about pure JavaScript implementations of the DOM? There was some vague plan to eventually move in that direction...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>77234</commentid>
    <comment_count>3</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2012-10-29 01:22:07 +0000</bug_when>
    <thetext>I don&apos;t think there&apos;s a problem for pure-JS impls per se, apart from the general difficulties of returning something consistent when you can&apos;t use the pointer value.  Which is not specific to JS: it&apos;s a problem for any implementation that moves nodes in memory (e.g. might well be a problem for Servo)...

I really wish I had better ideas here.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>77406</commentid>
    <comment_count>4</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2012-10-30 12:08:57 +0000</bug_when>
    <thetext>It&apos;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 &lt; 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).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>78122</commentid>
    <comment_count>5</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-11-09 15:34:03 +0000</bug_when>
    <thetext>https://github.com/whatwg/dom/tree/75f3a2e8cb623eed07765716671904405a5814e4
http://dom.spec.whatwg.org/#dom-node-comparedocumentposition</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>78179</commentid>
    <comment_count>6</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2012-11-10 19:04:13 +0000</bug_when>
    <thetext>Updated test:

https://dvcs.w3.org/hg/webapps/rev/03c049b18564

It doesn&apos;t yet try to test for consistency.  That should maybe be a separate test file.

(In reply to comment #5)
&gt; https://github.com/whatwg/dom/tree/75f3a2e8cb623eed07765716671904405a5814e4

Did you mean:

https://github.com/whatwg/dom/commit/75f3a2e8cb623eed07765716671904405a5814e4

Blech, non-truncated commit id&apos;s . . .</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>