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 20553 - HTMLOptionsCollection.add() method throws in most browsers for out of range values
Summary: HTMLOptionsCollection.add() method throws in most browsers for out of range v...
Status: RESOLVED WORKSFORME
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: 2013-01-02 22:47 UTC by contributor
Modified: 2013-03-06 22:58 UTC (History)
4 users (show)

See Also:


Attachments

Description contributor 2013-01-02 22:47:13 UTC
Specification: http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html
Multipage: http://www.whatwg.org/C#htmloptionscollection-0
Complete: http://www.whatwg.org/c#htmloptionscollection-0

Comment:
The add() method throws in the majority of browsers for a differing out of
range values. In Chrome/Safari/IE/Opera it throws for all of -2, NaN,
Infinity, -Infinity. In Firefox it only throws for +/- Infinity. Nothing
throws on -1 or on positive values out of range. Per WebIDL's ECMAScript
binding the conversion of non-finites to long should not throw unless
[EnforceRange] is specified. Throwing for <-1 would require prose. It's
unclear that throwing at all is useful here, but I wanted to note current
browser behavior.

Posted from: 2620:0:1002:1005:ae16:2dff:fe07:52dc
User agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.45 Safari/537.17
Comment 1 Joshua Bell 2013-01-02 22:51:10 UTC
Cleaned up the summary.

Repro code to try:

[1000, -1, -2, Infinity, -Infinity, NaN].forEach(function(x) { try { document.createElement('select').options.add(document.createElement('option'), x); } catch (e) { console.log(x + ": " + e); } })

Relevant WebIDL number->long conversion spec:

http://dev.w3.org/2006/webapi/WebIDL/#es-long

... which would indicate, lacking an [EnforceRange] attribute, that non-finites should yield 0 and hence not throw.
Comment 2 Ian 'Hixie' Hickson 2013-03-06 22:04:19 UTC
http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2134

Firefox exactly matches the spec today as far as I can tell. Since there's no compelling reason to do anything else, I've left the spec as is.
Comment 3 Joshua Bell 2013-03-06 22:58:45 UTC
SGTM. Looks like Firefox updated since I last checked.

I have a Chrome patch in progress that match that behavior.