This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.
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
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.
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.
SGTM. Looks like Firefox updated since I last checked. I have a Chrome patch in progress that match that behavior.