<?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>14354</bug_id>
          
          <creation_ts>2011-10-02 10:31:15 +0000</creation_ts>
          <short_desc>Rename append/replaceChild/insertBefore(&lt;some text&gt;) to appendText, replaceWithText, insertTextBefore</short_desc>
          <delta_ts>2011-12-17 14:45:42 +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>INVALID</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="Olli Pettay">bugs</reporter>
          <assigned_to name="Anne">annevk</assigned_to>
          <cc>ayg</cc>
    
    <cc>bzbarsky</cc>
    
    <cc>cam</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>57628</commentid>
    <comment_count>0</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2011-10-02 10:31:15 +0000</bug_when>
    <thetext>Current draft allows adding new text nodes using appendChild(string param) etc.

That is not only a bit misleading, since things like
appendChild(&quot;&lt;div&gt;&quot;) doesn&apos;t do what one would expect, but it can also
lead to other unexpected results if one does
for example element.appendChild(anchorElement); 
One could assume that the href (stringifier) of anchorElement gets appended to element, or one could assume that the element gets appended. Both are
perfectly fine interpretations, IMO.
API shouldn&apos;t allow that, but should be clear what happens in each case.

Also, I don&apos;t see any good reasons to re-use the same method names for doing something else than just inserting nodes.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>57671</commentid>
    <comment_count>1</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2011-10-02 19:42:42 +0000</bug_when>
    <thetext>Adding new methods does seem clearer than overloading existing ones.  Is there any reason to overload here?  Are there other methods in the web platform that are overloaded like this?  One advantage of not overloading is it allows easier feature-testing -- you don&apos;t have to try calling it and see if it throws.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>57672</commentid>
    <comment_count>2</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2011-10-02 20:54:13 +0000</bug_when>
    <thetext>FormData.append(), XMLHttpRequest.send(). Are there methods not overloaded like this?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>57675</commentid>
    <comment_count>3</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2011-10-02 21:12:25 +0000</bug_when>
    <thetext>FormData and XHR methods aren&apos;t performance-vise hot.

And even more importantly, is there any reason why append/replaceChild etc
need to be overloaded, and new methods can&apos;t be created?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>57695</commentid>
    <comment_count>4</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2011-10-03 11:04:40 +0000</bug_when>
    <thetext>In Opera this would not be a performance hit. WebKit representatives seemed okay with it as well.

Having additional methods is not at all JavaScript-like.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>57697</commentid>
    <comment_count>5</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2011-10-03 11:39:00 +0000</bug_when>
    <thetext>&gt; In Opera this would not be a performance hit.

On this testcase:      

   (function() {
      var d = document.createElement(&quot;div&quot;);
      var d2 = document.createElement(&quot;div&quot;);
      var start = new Date;
      for (var i = 0; i &lt; 1000000; ++i) d2.appendChild(d);
      alert(new Date - start);
    })()

Opera is about 4x slower than Gecko on my machine.  Overloading wouldn&apos;t be a performance hit for us either if we were that slow.

And we expect this to become much faster, so the relative cost of the overload stuff will be even higher.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>57698</commentid>
    <comment_count>6</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2011-10-03 11:52:56 +0000</bug_when>
    <thetext>I&apos;m not really a benchmark expert but how is that testing appendChild() functionality? After the first time appendChild() could effectively be a no-op in that test if the implementation had some optimization check for that.

(And WebKit appears a lot faster than Gecko on that test.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>57699</commentid>
    <comment_count>7</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2011-10-03 12:00:21 +0000</bug_when>
    <thetext>&gt; After the first time appendChild() could effectively be a no-op
&gt; in that test if the implementation had some optimization check for that.

Sure.  Here&apos;s a version of the test test that doesn&apos;t have that problem:

    (function() {
      var d = document.createElement(&quot;div&quot;);
      var ds = [ document.createElement(&quot;div&quot;), document.createElement(&quot;div&quot;) ];
      var start = new Date;
      for (var i = 0; i &lt; 1000000; ++i) d.appendChild(ds[i % 2]);
      alert(new Date - start);
    })()

or

    (function() {
      var d = document.createElement(&quot;div&quot;);
      d.appendChild(document.createElement(&quot;div&quot;));
      d.appendChild(document.createElement(&quot;div&quot;));
      var start = new Date;
      for (var i = 0; i &lt; 1000000; ++i) d.appendChild(d.firstChild);
      alert(new Date - start);
    })()

which amusingly enough are much slower in WebKit; there is no real difference in Gecko or Presto.

&gt; (And WebKit appears a lot faster than Gecko on that test.)

Sure.  Is I said, we plan to make it a lot faster in Gecko in any case.  I was simply commenting on your claim that there is no performance hit in Presto.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>58033</commentid>
    <comment_count>8</comment_count>
    <who name="Cameron McCormack">cam</who>
    <bug_when>2011-10-11 05:37:13 +0000</bug_when>
    <thetext>We should (if we don&apos;t yet) have a constructor for Text.  Then you can do

  e.appendChild(new Text(&quot;abc&quot;));

which ain&apos;t so bad.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>58415</commentid>
    <comment_count>9</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2011-10-19 06:51:22 +0000</bug_when>
    <thetext>I reverted this change for now. I do not think adding Text node specific methods is the way to go here.

Adding a constructor for Text makes sense, but I&apos;m not sure how it should work for Element.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61749</commentid>
    <comment_count>10</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2011-12-17 14:45:42 +0000</bug_when>
    <thetext>The change in comment 0 was reverted. If anything else needs to happen please file a new bug.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>