Re: [HTMLCollection] an error in approved TC?

Hi Ms2ger,

On Aug 7, 2013 11:04 PM, "Ms2ger" <ms2ger@gmail.com> wrote:
>
> 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.
>

OK, it falls on an Array Index Property Name case. Thanks for the
clarification!

> HTH
> Ms2ger
>
> [*] http://dev.w3.org/2006/webapi/WebIDL/#dfn-array-index-property-name
> [§] http://dom.spec.whatwg.org/#dom-htmlcollection-item
>

Received on Thursday, 8 August 2013 10:38:09 UTC