W3C home > Mailing lists > Public > public-html@w3.org > July 2008

Re: HTMLCollection item() vs. namedItem() with [] syntax (detailed review of the DOM)

From: Garrett Smith <dhtmlkitchen@gmail.com>
Date: Fri, 25 Jul 2008 19:09:28 -0700
Message-ID: <c9e12660807251909l17480a43ieeff678eb2c1662d@mail.gmail.com>
To: public-html <public-html@w3.org>
On Thu, Jul 10, 2008 at 10:16 AM, Garrett Smith <dhtmlkitchen@gmail.com> wrote:
> On Thu, Jul 10, 2008 at 12:22 AM, Cameron McCormack <cam@mcc.id.au> wrote:
>>
>> Cameron McCormack:
>>> > > That's different from what I currently have in the Bindings spec,
>>> > > which is basically "do a ToUint32() on the property name, and if the
>>> > > result is a non-negative integer, use the index getter, otherwise use
>>> > > the name getter".
>>

Is this in reference to " [IndexGetter]" on "OrderedMap"
http://www.w3.org/TR/DOM-Bindings/#IndexGetter

?

The major browsers allow access of items in a collection via
property-access operators.

The browser adds named properties to the Collection object in all of
the major browsers.

====================================
<form><input></form>

javascript:alert(({}).hasOwnProperty.call(document.forms[0].elements, 0));
====================================

FF3, IE7, Saf3: true
Op9: false[1]

====================================
javascript:alert("0"in document.forms[0].elements)
FF3, IE7, Saf3, Op9: true
====================================

[1] Opera 9 bug: does not return true for hasOwnProperty on a Host object.

Any assumption that there is a modified [[Get]] for the collection
would be wrong.

Garrett


>> Simon Pieters:
>>> > Hmm, seems like ToUint32 converts things like NaN and Infinity to 0.
>
> When used in property access, the Expression is converted to a string
> value. NaN and +Infinity will be a "NaN" and "Infinity" respectively.
>
> Try it:
>
> (function() {
>    var a = [];
>    a.NaN = 12;
>    a.Infinity = 13;
>    a[0] = "z";
>    alert(a[NaN]);
>    alert(a[1/0]);
>
> // no property named "0x0" - so undefined;
>    alert(a["0x0"]);
>
> // -0.0 => 0, resolve the "0" property on a.
>    alert(a[-0.0]);
> })()
>
>
>>> > Browsers don't do that. So I don't think that's good enough... e.g., we
>>> > want ["0x0"], [1/0], etc., to use the name getter.
>>
>
> A string value of the Expression will be used. If the Expression is
> "0x0", then the property "0x0" (or undefined) will be returned.
>
> [snip]
>
> Garrett
>
>> --
>> Cameron McCormack ≝ http://mcc.id.au/
>
Received on Saturday, 26 July 2008 02:10:03 UTC

This archive was generated by hypermail 2.3.1 : Monday, 29 September 2014 09:38:56 UTC