Re: indexed properties on NodeLists and HTMLCollections

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 

> 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 

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....


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