- From: Ms2ger <ms2ger@gmail.com>
- Date: Wed, 07 Aug 2013 16:04:09 +0200
- To: Jungkee Song <jungkee.song@samsung.com>
- CC: public-webapps-testsuite@w3.org
Hi Jungkee, On 08/06/2013 03:31 PM, Jungkee Song wrote: > Hi, > > In the following approved TC, I found an assertion that needs review: > http://w3c-test.org/html/tests/approved/the-elements-of-html/forms/the-form- > element/form-elements-matches.html > > var form = document.getElementById("form"); > var i = document.createElement("input"); > i.name = "2"; > form.appendChild(i); > > assert_equals(form.elements["2"], undefined, '["2"]'); > > Shouldn't the above assertion rather be: > assert_equals(form.elements["2"], i, '["2"]'); > > See the definition of HTMLCollection: > http://dom.spec.whatwg.org/#interface-htmlcollection I believe this test to be correct. However, it relies on the little-known fact that all property names in JS are strings, and foo[2] is just a shorthand for foo["2"]. The distinction made is not between strings and numbers (what would you do with objects?) but instead looks at the subset of strings that are "array index property name"s [*]. This all means that form.elements["2"] calls into the indexed getter [§], and there is no element with index 2. HTH Ms2ger [*] http://dev.w3.org/2006/webapi/WebIDL/#dfn-array-index-property-name [§] http://dom.spec.whatwg.org/#dom-htmlcollection-item
Received on Wednesday, 7 August 2013 14:04:39 UTC