<?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>27887</bug_id>
          
          <creation_ts>2015-01-23 19:18:15 +0000</creation_ts>
          <short_desc>&quot;Mutation method macro&quot; should handle empty nodes</short_desc>
          <delta_ts>2015-06-12 13:02:45 +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>MOVED</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="Joshua Bell">jsbell</reporter>
          <assigned_to name="Anne">annevk</assigned_to>
          <cc>annevk</cc>
    
    <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>117461</commentid>
    <comment_count>0</comment_count>
    <who name="Joshua Bell">jsbell</who>
    <bug_when>2015-01-23 19:18:15 +0000</bug_when>
    <thetext>https://dom.spec.whatwg.org/#mutation-method-macro (as of rev b7563aa)

Given one of the operations that references it, e.g.:

void prepend((Node or DOMString)... nodes);

Per Web IDL, the variadic argument can be omitted entirely, so e.g. myDiv.prepend() should not throw (unless specified to in prose).

The various operations don&apos;t specify special handling when called with no arguments. They execute the mutation method macro, which has:

1. Let /node/ be null.
2. Replace each string in /nodes/ with a Text node whose data is the string value.
3. If /nodes/ contains more than one node, set /node/ to a new DocumentFragment and append each node in /nodes/ to it. Rethrow any exceptions.
Otherwise, set /node/ to the single node /nodes/ contains.

Step 3 doesn&apos;t appear to handle the case if /nodes/ contains zero nodes. It&apos;s not more than one, but yet not a single node.

Proposed fix:

Replace &quot;contains more than one node&quot; with &quot;contains exactly one node&quot;.

This would result in an empty DocumentFragment, which turns most of the ParentNode/ChildNode operations into no-ops when called with no argument except `replaceWith` which acts like `remove`.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>117462</commentid>
    <comment_count>1</comment_count>
    <who name="Joshua Bell">jsbell</who>
    <bug_when>2015-01-23 19:21:06 +0000</bug_when>
    <thetext>Oops, not &quot;contains exactly one&quot; since that inverts the meaning of the test.

&quot;Contains more or less than one node&quot;, or flip the then/otherwise clauses, or explicitly handle 0. Whatevs.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>120933</commentid>
    <comment_count>2</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2015-06-12 13:02:45 +0000</bug_when>
    <thetext>This is now https://github.com/whatwg/dom/issues/44 since it got reported again and GitHub is somewhat nicer. I like your suggestion.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>