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: Thu, 05 May 2011 15:24:53 -0400
Message-ID: <4DC2F985.9040403@mit.edu>
To: Allen Wirfs-Brock <allen@wirfs-brock.com>
CC: Cameron McCormack <cam@mcc.id.au>, public-script-coord@w3.org
On 5/5/11 3:00 PM, Allen Wirfs-Brock wrote:
> Ideally (from a JavaScript perspective), we should be designing web APIs
> which only depend upon the standard native JavaScript object semantics
> and which don't require behavioral intercession.

The problem is that it's common for at least past web APIs for an object 
to reflect some part of the DOM and automagically mutate when that part 
of the DOM changes.

This is the case that's a pain to represent with native object semantics.

At the same time, this seems like something web authors want in many 
cases...

> In terms of prioritization of specification techniques within the
> ES/WebIDL binding I suggest:
> 1) normal ES data property and method invocation semantics
> 2) use of ES accessor properties in possibly creative ways
> ------------------- stop here for all new APIs

I think the only way to do that is to disallow [OverrideBuiltins] in new 
APIs.

Of course the non-[[OverrideBuiltins]] behavior is even weirder...

Perhaps the only way to do that is to disallow name/index 
getters/setters altogether.  But web authors seem to want them.

>> var list = document.documentElement.childNodes;
>> // list is a NodeList that happens to be implemented by a Proxy
>> Object.defineOwnProperty(list, "a", { configurable: false, value: 1 });
>> alert(Object.getOwnPropertyDescriptor(list, "a").configurable);
>>
>> would that alert true? If so, is that seen as a problem?
>
> I would expect it to alert true. "a" isn't a property name that is
> "live" as the one of the items of a NodeList

But it is for an HTMLCollection, which is otherwise identical to a NodeList.

Replace document.documentElement.childNodes above with 
document.getElementsByTagName("x") as desired.

> The situation would be different if list was a NamedNodeMap. In that
> case "a" (or any valid nodeName value) could be the name of a "live"
> property that could be dynamically added to the list. You need to
> specify the desired semantics for such a live property when its property
> name already exists

The desired semantics from my point of view as a UA implementor is to 
not have to worry about whether it exists, because checking that is slow....

-Boris
Received on Thursday, 5 May 2011 19:25:24 UTC

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