<?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>24746</bug_id>
          
          <creation_ts>2014-02-20 18:52:26 +0000</creation_ts>
          <short_desc>HTMLSelectElement remove should take (HTMLElement or long)</short_desc>
          <delta_ts>2014-02-21 17:24:05 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WHATWG</product>
          <component>HTML</component>
          <version>unspecified</version>
          <rep_platform>Other</rep_platform>
          <op_sys>other</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>http://www.whatwg.org/specs/web-apps/current-work/#the-select-element</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P3</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>Unsorted</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>contributor</reporter>
          <assigned_to name="Ian &apos;Hixie&apos; Hickson">ian</assigned_to>
          <cc>bzbarsky</cc>
    
    <cc>erik.arvidsson</cc>
    
    <cc>ian</cc>
    
    <cc>mike</cc>
    
    <cc>Ms2ger</cc>
          
          <qa_contact>contributor</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>100979</commentid>
    <comment_count>0</comment_count>
    <who name="">contributor</who>
    <bug_when>2014-02-20 18:52:26 +0000</bug_when>
    <thetext>Specification: http://www.whatwg.org/specs/web-apps/current-work/multipage/the-button-element.html
Multipage: http://www.whatwg.org/C#the-select-element
Complete: http://www.whatwg.org/c#the-select-element
Referrer: http://www.whatwg.org/specs/web-apps/current-work/multipage/

Comment:
HTMLSelectElement remove should take (HTMLElement or long)

Posted from: 2620:0:1003:1017:2e41:38ff:fea6:f2aa
User agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.3 Safari/537.36</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>100980</commentid>
    <comment_count>1</comment_count>
    <who name="Erik Arvidsson">erik.arvidsson</who>
    <bug_when>2014-02-20 18:55:02 +0000</bug_when>
    <thetext>The IDL in the spec says 

  void remove(long index);

but it needs to be

  void remove((HTMLElement or long) child);

and of course the prose needs to be updated too.

Tested in Chrome, Firefox and IE. They all pass the following:

  test(&apos;remove&apos;, function() {
    var select = document.createElement(&apos;select&apos;);

    var a = document.createElement(&apos;option&apos;);
    a.text = &apos;a&apos;;
    select.appendChild(a);

    var b = document.createElement(&apos;option&apos;);
    b.text = &apos;b&apos;;
    select.appendChild(b);

    var c = document.createElement(&apos;option&apos;);
    c.text = &apos;c&apos;;
    select.appendChild(c);

    select.remove(a);
    assert.equal(select.firstChild, b);
    assert.equal(select.lastChild, c);

    select.remove(1);
    assert.equal(select.firstChild, b);
    assert.equal(select.lastChild, b);
  });</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>100982</commentid>
    <comment_count>2</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-02-20 18:57:42 +0000</bug_when>
    <thetext>Does this apply to HTMLOptionsCollection also?

Basically remove() is like add()&apos;s second argument in both cases?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>100993</commentid>
    <comment_count>3</comment_count>
    <who name="Erik Arvidsson">erik.arvidsson</who>
    <bug_when>2014-02-20 20:07:36 +0000</bug_when>
    <thetext>(In reply to Ian &apos;Hixie&apos; Hickson from comment #2)
&gt; Does this apply to HTMLOptionsCollection also?

Blink/WebKit allows an element in HTMLOptionsCollection remove
Gecko and Trident do not and they only accept an index</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>100996</commentid>
    <comment_count>4</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-02-20 20:21:32 +0000</bug_when>
    <thetext>I guess I&apos;ll go with consistency and hope that Firefox/IE follow suit.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101028</commentid>
    <comment_count>5</comment_count>
    <who name="Erik Arvidsson">erik.arvidsson</who>
    <bug_when>2014-02-20 21:18:43 +0000</bug_when>
    <thetext>(In reply to Ian &apos;Hixie&apos; Hickson from comment #4)
&gt; I guess I&apos;ll go with consistency and hope that Firefox/IE follow suit.

Makes sense to me</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101042</commentid>
    <comment_count>6</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-02-20 22:07:23 +0000</bug_when>
    <thetext>Actually I can&apos;t get select.remove() to work with an element. All objects seem to be treated as zero, in all browsers I tested.

   http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2826
   http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2828
   http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2825
   http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2827

It works in your test because you try to remove the first entry, which is treated like zero.

I&apos;ve updated the spec to convert object arguments to zero.

Please reopen the bug if I made a mistake here.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101043</commentid>
    <comment_count>7</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-02-20 22:10:16 +0000</bug_when>
    <thetext>test from comment 1, for posterity:
   http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2829</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101044</commentid>
    <comment_count>8</comment_count>
    <who name="">contributor</who>
    <bug_when>2014-02-20 22:10:34 +0000</bug_when>
    <thetext>Checked in as WHATWG revision r8481.
Check-in comment: Turns out select.remove() and select.options.remove() convert object arguments to zero.
http://html5.org/tools/web-apps-tracker?from=8480&amp;to=8481</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101047</commentid>
    <comment_count>9</comment_count>
    <who name="Erik Arvidsson">erik.arvidsson</who>
    <bug_when>2014-02-20 22:14:22 +0000</bug_when>
    <thetext>You are right. Sorry for the misleading test.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101089</commentid>
    <comment_count>10</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2014-02-21 04:09:12 +0000</bug_when>
    <thetext>Uh, why did this need a spec change?  IDL will coerce an object to the 0 value of &quot;long&quot; unless it has a valueOf that says otherwise.  That&apos;s because ToNumber() will return NaN, and converting NaN to a long gives 0...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101090</commentid>
    <comment_count>11</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2014-02-21 04:10:04 +0000</bug_when>
    <thetext>In particular, I expect the new spec behavior is not compatible with UA behavior if someone does:

  remove({ valueOf: function() { return 1; } });</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101111</commentid>
    <comment_count>12</comment_count>
    <who name="Erik Arvidsson">erik.arvidsson</who>
    <bug_when>2014-02-21 15:24:05 +0000</bug_when>
    <thetext>BZ is right. I&apos;m sorry for causing all this mess. The old spec was correct and WebKit/Blink behavior was following the spec except that our IDL was misleading.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101113</commentid>
    <comment_count>13</comment_count>
    <who name="Erik Arvidsson">erik.arvidsson</who>
    <bug_when>2014-02-21 15:33:26 +0000</bug_when>
    <thetext>Lets revert back to the old behavior because that is what Blink, Gecko, Trident does.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101119</commentid>
    <comment_count>14</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-02-21 17:23:50 +0000</bug_when>
    <thetext>Ah, yeah, I misunderstood the ToPrimitive logic in the JS spec. Thanks bz!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101120</commentid>
    <comment_count>15</comment_count>
    <who name="">contributor</who>
    <bug_when>2014-02-21 17:24:00 +0000</bug_when>
    <thetext>Checked in as WHATWG revision r8497.
Check-in comment: Revert r8481 since I misunderstood how ToNumber works on objects.
http://html5.org/tools/web-apps-tracker?from=8496&amp;to=8497</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>