W3C home > Mailing lists > Public > public-script-coord@w3.org > April to June 2011

Re: indexed properties on NodeLists and HTMLCollections

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Fri, 06 May 2011 12:58:29 -0400
Message-ID: <4DC428B5.4000605@mit.edu>
To: Allen Wirfs-Brock <allen@wirfs-brock.com>
CC: Cameron McCormack <cam@mcc.id.au>, public-script-coord@w3.org
On 5/6/11 12:42 PM, Allen Wirfs-Brock wrote:
> Let me take a shot a describe a semantics for the nodelist in your
> example. I /think/ what I describe is consistent with the common
> behavior across current browsers but I may be wrong.

Sadly, it's not.

> 1) all own enumerable properties of the list object correspond to
> elements of the collection. (let's call such properties elements).
> Elements may be either symbolically named or array indexed property.

This is doesn't match browser behavior in many cases (e.g. named 
properties due to element IDs on nodelists are gettable but not 
enumerable in Safari, Chrome, Opera, Firefox, modulo some Firefox bugs; 
I haven't tested IE).

> 2) normal ES prototype shadowing occurs. In particular, elements shadow
> like-named properties defined on the prototype chain

This is not true for named properties due to element IDs on nodelists, 
as long as the property on the prototype chain is present before the 
named property becomes relevant for the nodelist.  This part is fully 
interoperable across all browsers, and I would expect the web to break 
if normal shadowing happened here.

> 3) element properties manifest themselves as accessor properties.
> [[Put]]/[[Get]]/[[Delete]]/[[DefineOwnProperty]] of elements have DOM
> side-effects.

This is incorrect.  Nodelists are read-only views on current DOM state. 
  If [[Put]] and [[Delete]] of named properties were passed through to 
the DOM, we would not be having this discussion, since you wouldn't be 
able to end up with expandos on lists.

> 4) the ES5 attributes of elements are configurable: true, enumerable: true.

They're not; see above.

> 5) "type checking" is enforced on [[Put]] operations for elements.
> Setting an element to a invalid value (a non-Node) the list throws

This would almost certainly break the web.  In particular, it would make 
expandos set on nodelists throw.  That's not what _any_ browser does.

> Given these semantic rules we can see what the testcase would do:
>
> step 2, creates/replaces an element named "myExpando"

Sorry, no.  Not compatible with the web.

Try again?  :(

-Boris
Received on Friday, 6 May 2011 16:59:00 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 8 May 2013 19:30:03 UTC