This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 24746 - HTMLSelectElement remove should take (HTMLElement or long)
Summary: HTMLSelectElement remove should take (HTMLElement or long)
Status: RESOLVED FIXED
Alias: None
Product: WHATWG
Classification: Unclassified
Component: HTML (show other bugs)
Version: unspecified
Hardware: Other other
: P3 normal
Target Milestone: Unsorted
Assignee: Ian 'Hixie' Hickson
QA Contact: contributor
URL: http://www.whatwg.org/specs/web-apps/...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-20 18:52 UTC by contributor
Modified: 2014-02-21 17:24 UTC (History)
5 users (show)

See Also:


Attachments

Description contributor 2014-02-20 18:52:26 UTC
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
Comment 1 Erik Arvidsson 2014-02-20 18:55:02 UTC
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('remove', function() {
    var select = document.createElement('select');

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

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

    var c = document.createElement('option');
    c.text = 'c';
    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);
  });
Comment 2 Ian 'Hixie' Hickson 2014-02-20 18:57:42 UTC
Does this apply to HTMLOptionsCollection also?

Basically remove() is like add()'s second argument in both cases?
Comment 3 Erik Arvidsson 2014-02-20 20:07:36 UTC
(In reply to Ian 'Hixie' Hickson from comment #2)
> 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
Comment 4 Ian 'Hixie' Hickson 2014-02-20 20:21:32 UTC
I guess I'll go with consistency and hope that Firefox/IE follow suit.
Comment 5 Erik Arvidsson 2014-02-20 21:18:43 UTC
(In reply to Ian 'Hixie' Hickson from comment #4)
> I guess I'll go with consistency and hope that Firefox/IE follow suit.

Makes sense to me
Comment 6 Ian 'Hixie' Hickson 2014-02-20 22:07:23 UTC
Actually I can'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've updated the spec to convert object arguments to zero.

Please reopen the bug if I made a mistake here.
Comment 7 Ian 'Hixie' Hickson 2014-02-20 22:10:16 UTC
test from comment 1, for posterity:
   http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2829
Comment 8 contributor 2014-02-20 22:10:34 UTC
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&to=8481
Comment 9 Erik Arvidsson 2014-02-20 22:14:22 UTC
You are right. Sorry for the misleading test.
Comment 10 Boris Zbarsky 2014-02-21 04:09:12 UTC
Uh, why did this need a spec change?  IDL will coerce an object to the 0 value of "long" unless it has a valueOf that says otherwise.  That's because ToNumber() will return NaN, and converting NaN to a long gives 0...
Comment 11 Boris Zbarsky 2014-02-21 04:10:04 UTC
In particular, I expect the new spec behavior is not compatible with UA behavior if someone does:

  remove({ valueOf: function() { return 1; } });
Comment 12 Erik Arvidsson 2014-02-21 15:24:05 UTC
BZ is right. I'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.
Comment 13 Erik Arvidsson 2014-02-21 15:33:26 UTC
Lets revert back to the old behavior because that is what Blink, Gecko, Trident does.
Comment 14 Ian 'Hixie' Hickson 2014-02-21 17:23:50 UTC
Ah, yeah, I misunderstood the ToPrimitive logic in the JS spec. Thanks bz!
Comment 15 contributor 2014-02-21 17:24:00 UTC
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&to=8497