<?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>23565</bug_id>
          
          <creation_ts>2013-10-18 18:50:34 +0000</creation_ts>
          <short_desc>cloneNode IDL does not match reality</short_desc>
          <delta_ts>2013-12-20 19:25:19 +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>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>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Boris Zbarsky">bzbarsky</reporter>
          <assigned_to name="Anne">annevk</assigned_to>
          <cc>bugs</cc>
    
    <cc>d</cc>
    
    <cc>erik.arvidsson</cc>
    
    <cc>jonas</cc>
    
    <cc>mike</cc>
    
    <cc>Ms2ger</cc>
    
    <cc>VYV03354</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>94949</commentid>
    <comment_count>0</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-10-18 18:50:34 +0000</bug_when>
    <thetext>The spec has:

  Node cloneNode(optional boolean deep = true);

but the web depends on passing undefined being treated as false.  In particlar, CKEditor depends on it.  See https://bugzilla.mozilla.org/show_bug.cgi?id=926305</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>94995</commentid>
    <comment_count>1</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2013-10-21 10:48:27 +0000</bug_when>
    <thetext>So we want cloneNode() and importNode() to have different signatures?

Note that cloneNode() in Chrome defaults to true as well.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95000</commentid>
    <comment_count>2</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-10-21 13:19:18 +0000</bug_when>
    <thetext>Er, I somehow missed importNode.  importNode needs to change too.

&gt; Note that cloneNode() in Chrome defaults to true as well.

Exactly.  But cloneNode(undefined) uses false, not true.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95005</commentid>
    <comment_count>3</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2013-10-21 14:09:17 +0000</bug_when>
    <thetext>Bah bah bah.

https://github.com/whatwg/dom/commit/70fdc5f9030c22c5ceca9e875e06f8b305529ef8</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95006</commentid>
    <comment_count>4</comment_count>
    <who name="Erik Arvidsson">erik.arvidsson</who>
    <bug_when>2013-10-21 14:16:28 +0000</bug_when>
    <thetext>OK. I&apos;ll update Blink. Should be safe since the default to true case is still hot out of the oven.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95009</commentid>
    <comment_count>5</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-10-21 14:52:12 +0000</bug_when>
    <thetext>&gt; OK. I&apos;ll update Blink.

There should be no need to change anything in Blink.

This testcase:

&lt;body&gt;&lt;script&gt;
  alert(document.body.cloneNode(undefined).childNodes.length);
  alert(document.body.cloneNode().childNodes.length);
&lt;/script&gt;

already alerts &quot;0&quot; and then &quot;2&quot; in my Chrome dev build (32.0.1671.3), which is what the DOM spec _used_ to require before the WebIDL changes to how undefined is handled, and is also what the DOM spec should imo specify once this bug is fixed.

Anne, your changes aren&apos;t what this bug was asking for.  What this bug is asking for is:

  Node cloneNode();  // deep clone specified in prose
  Node cloneNode(boolean deep);

and similar for importNode.

Reopening, since as far as I can tell the intent of the desired change was totally misunderstood.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95010</commentid>
    <comment_count>6</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-10-21 14:53:30 +0000</bug_when>
    <thetext>In particular, the web compat requirement here is that cloneNode(undefined) do a shallow clone.  There is no strong web compat requirement of any sort on cloneNode() with no arguments, since that&apos;s only been non-throwing in Gecko for a short time.  During that time, though, it&apos;s consistently done a deep clone.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95011</commentid>
    <comment_count>7</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-10-21 14:54:29 +0000</bug_when>
    <thetext>&gt; already alerts &quot;0&quot; and then &quot;2&quot; 

Er, &quot;0&quot; and then &quot;1&quot;, since I got rid of the whitespace before &lt;script&gt;.  ;)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95012</commentid>
    <comment_count>8</comment_count>
    <who name="Domenic Denicola">d</who>
    <bug_when>2013-10-21 15:03:15 +0000</bug_when>
    <thetext>&gt; There is no strong web compat requirement of any sort on cloneNode() with no arguments

In that case it would ideally be the same as cloneNode(undefined), right? I.e. shallow clone? I think that&apos;s what Anne&apos;s changes implement?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95013</commentid>
    <comment_count>9</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2013-10-21 15:06:56 +0000</bug_when>
    <thetext>Yeah, I don&apos;t want omitted and undefined to be different if we can avoid it. And since WebKit already had this as false for both cases...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95014</commentid>
    <comment_count>10</comment_count>
    <who name="Ms2ger">Ms2ger</who>
    <bug_when>2013-10-21 15:33:41 +0000</bug_when>
    <thetext>I disagree. It would be better for cloneNode() to throw than to do a shallow clone.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95015</commentid>
    <comment_count>11</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2013-10-21 15:37:55 +0000</bug_when>
    <thetext>We cannot throw for undefined and we want undefined to be false so omitted should also be false.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95031</commentid>
    <comment_count>12</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-10-21 19:18:40 +0000</bug_when>
    <thetext>&gt; In that case it would ideally be the same as cloneNode(undefined), right?

Well, maybe.  There may well be a web compat requirement here anyway, I just can&apos;t tell.  Or put another way, I&apos;m not willing to change the Gecko behavior to have cloneNode with no arguments do a shallow clone, because I&apos;m worried about that causing compat problems at this point and I don&apos;t think theoretical purity is worth breaking compat in this case.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95032</commentid>
    <comment_count>13</comment_count>
    <who name="Erik Arvidsson">erik.arvidsson</who>
    <bug_when>2013-10-21 19:37:07 +0000</bug_when>
    <thetext>bz: How long have you been shipping with optional meaning true? Since you used to throw for no arguments until pretty recently most code out there always pass an argument.

Also IE and WebKit never changed to treat optional as true.

I think this is as close to safe as it can get on the web.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95033</commentid>
    <comment_count>14</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-10-21 19:52:18 +0000</bug_when>
    <thetext>&gt; bz: How long have you been shipping with optional meaning true?

Since Firefox 13.  So in final releases since June 5, 2012.

&gt; until pretty recently

Over a year is pushing it for &quot;pretty recently&quot;.

&gt; I think this is as close to safe as it can get on the web.

I disagree.  :(</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95034</commentid>
    <comment_count>15</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-10-21 19:56:50 +0000</bug_when>
    <thetext>That is, I think there is a good chance of Gecko making this change breaking content, due to content-sniffing and Gecko-only codepaths.  :(

We would _definitely_ break a number of Firefox extensions; I just checked and a bunch of them use cloneNode() with no arguments and expect deep clones.

We might be willing to go through all that breakage if there were a very strong reason to, but in this case, I just don&apos;t think the reasons are strong enough.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95035</commentid>
    <comment_count>16</comment_count>
    <who name="Erik Arvidsson">erik.arvidsson</who>
    <bug_when>2013-10-21 20:24:32 +0000</bug_when>
    <thetext>(In reply to Boris Zbarsky from comment #15)

&gt; We might be willing to go through all that breakage if there were a very
&gt; strong reason to, but in this case, I just don&apos;t think the reasons are
&gt; strong enough.

Compat with IE and Safari seems like reasons strong enough to me.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95053</commentid>
    <comment_count>17</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-10-21 21:49:26 +0000</bug_when>
    <thetext>Mmm, maybe.  I just don&apos;t see an obvious way for us to go about making this change without causing problems for our users, unfortunately.  It&apos;s not clear to me why we should be doing that instead of IE and Safari changing here.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95054</commentid>
    <comment_count>18</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-10-21 21:50:33 +0000</bug_when>
    <thetext>And I should note that at least for me my willingness to implement speculative spec proposals in the DOM spec is at an all-time low due to my experiences with this situation and similar.  :(</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95079</commentid>
    <comment_count>19</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2013-10-22 09:40:15 +0000</bug_when>
    <thetext>bz, I&apos;m sorry. I wish we had seen this one coming and I wish we had thought longer about IDL when it was still fresh, but it seems the only way we learn is extremely slow iteration with lots of drama along the way.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95152</commentid>
    <comment_count>20</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-10-23 06:03:10 +0000</bug_when>
    <thetext>That doesn&apos;t answer my question from comment 17, note.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95153</commentid>
    <comment_count>21</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-10-23 06:14:20 +0000</bug_when>
    <thetext>And one other note.  The compat with Safari/IE argument is no stronger than it was two weeks ago.  So I don&apos;t buy that it&apos;s particularly compelling in this case, if it wasn&apos;t then....</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95169</commentid>
    <comment_count>22</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2013-10-23 10:00:47 +0000</bug_when>
    <thetext>So these are the options as far as I can tell:

1)
  cloneNode() -&gt; cloneNode(true)
  cloneNode(undefined) -&gt; cloneNode(false)

2)
  cloneNode() -&gt; cloneNode(false)
  cloneNode(undefined) -&gt; cloneNode(false)

The latter is the preferred way of treating undefined. It also matches WebKit and IE. The former matches Gecko and Chrome and will require some IDL hack long term to make it work. Chrome only recently switched from 2. Gecko threw for the cloneNode() case until one year ago. It seems to me the safest is to go with 2.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95529</commentid>
    <comment_count>23</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-10-29 22:11:15 +0000</bug_when>
    <thetext>On the other hand, for the common case of cloning, which is deep clones, the API would be _way_ better if it could be just cloneNode().

The only real issue here is that there is legacy content that depends on cloneNode(undefined) doing a shallow clone.  While we need to support that legacy content, I believe that the default behavior for no arguments passed should be the sane one.  That&apos;s why the mailing list discussion initially decided the default here should be &quot;true&quot; to start with.

Does the argument for consistency between undefined and not passed really trump the web developer ergonomics argument here?

&gt; and will require some IDL hack long term to make it work.

That&apos;s putting spec purity ahead of developers, which is just wrong from a priority of constituencies perspective...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95531</commentid>
    <comment_count>24</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-10-29 23:57:15 +0000</bug_when>
    <thetext>And again, it seems to me like we&apos;re allowing the compat between undefined and omitted edge case tail wag the API design dog here...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95538</commentid>
    <comment_count>25</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2013-10-30 13:38:15 +0000</bug_when>
    <thetext>As far as I can tell the developer ergonomics argument applies both ways. Having undefined and omitted not equal each other will be found surprising and lead to subtle bugs.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>95539</commentid>
    <comment_count>26</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2013-10-30 13:54:07 +0000</bug_when>
    <thetext>What is surprising if passing an argument has different behavior than
not passing an argument?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>97824</commentid>
    <comment_count>27</comment_count>
    <who name="Ms2ger">Ms2ger</who>
    <bug_when>2013-12-20 07:53:14 +0000</bug_when>
    <thetext>https://github.com/w3c/web-platform-tests/pull/473</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>97829</commentid>
    <comment_count>28</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-12-20 19:25:19 +0000</bug_when>
    <thetext>We&apos;re going to align with the new spec here, fwiw, since it seems like no one else is interested in doing something different....</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>