<?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>18581</bug_id>
          
          <creation_ts>2012-08-15 18:09:35 +0000</creation_ts>
          <short_desc>pre-insert and replace both check type of &apos;node&apos; in too many places</short_desc>
          <delta_ts>2012-11-28 16:01:46 +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>PC</rep_platform>
          <op_sys>Linux</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>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Zack Weinberg">zackw</reporter>
          <assigned_to name="Anne">annevk</assigned_to>
          <cc>mike</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>72250</commentid>
    <comment_count>0</comment_count>
    <who name="Zack Weinberg">zackw</who>
    <bug_when>2012-08-15 18:09:35 +0000</bug_when>
    <thetext>The pre-insert and replace algorithms (http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#mutation-algorithms) have this structure:

  if (parent is not a Document, DocumentFragment, or Element)
    throw HierarchyRequestError;

  if (parent is a Document) {
    if (node is not a DocumentFragment, DocumentType, Element,
        ProcessingInstruction, or Comment)
      throw HierarchyRequestError;

    more checks;
  }
  else if (node is not a DocumentFragment, Element, Text,
           ProcessingInstruction, or Comment)
    throw HierarchyRequestError;

  more operations;

It would be clearer if they had this structure instead:

  if (parent is not a Document, DocumentFragment, or Element)
    throw HierarchyRequestError;

  if (node is not a DocumentFragment, DocumentType, Element, Text,
      ProcessingInstruction, or Comment)
    throw HierarchyRequestError;

  if ((node is a Text and parent is a Document) or
      (node is a DocumentType and parent is not a Document))
    throw HierarchyRequestError;

  if (parent is a Document)
    more checks;

  more operations;

Specifically, it would be clearer that most of the node type constraints apply regardless of the type of &apos;parent&apos;, and there are just a couple of special cases.

I would also recommend moving step 3 (&quot;If child is not null...&quot;) of the pre-insert algorithm to be step 1 (and pushing the current steps 1 and 2 down); this would provide more parallel structure with the replace algorithm, and would reduce the chance of confusing the reader about which of &apos;child&apos; and &apos;node&apos; is the new node.

I am happy to provide a proper patch to the prose if that would be helpful.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>74186</commentid>
    <comment_count>1</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-09-21 10:02:42 +0000</bug_when>
    <thetext>If you could propose a patch on Overview.src.html in https://github.com/whatwg/dom that would be great. 

(Sorry for responding so hopelessly late, I&apos;ve been on vacation for a while and then focused on the URL Standard.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79000</commentid>
    <comment_count>2</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-11-28 15:50:06 +0000</bug_when>
    <thetext>https://github.com/whatwg/dom/commit/b529cfcd4013c4f85785fa62d784a00b4403d9c8

I did not move step 3 up because that would change what exceptions get thrown.

I now think we should maybe collapse the first bit of pre-insert and replace together so that it&apos;s clear it&apos;s the same algorithm (there is actually a minor difference as child cannot be null in replace, but we can point that out).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79002</commentid>
    <comment_count>3</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2012-11-28 16:01:46 +0000</bug_when>
    <thetext>Only step 1-5 could be shared. I guess for now it&apos;s not worth it, unless we get other major changes. I&apos;ll make note of that in the source.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>