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

Array-with-item in WebIDL

From: Jonas Sicking <jonas@sicking.cc>
Date: Wed, 10 Jun 2015 12:45:59 +0800
Message-ID: <CA+c2ei8Nyq75AYXbuDQg9uDp3Qv7YCYSMUN3a7sLkbC=0ekXag@mail.gmail.com>
To: "public-script-coord@w3.org" <public-script-coord@w3.org>
Hi All,

As you may know, we have a number of types, at least DOMStringList,
FileList and DOMRectList which are essentially JS Array objects.
Except that they now are DOM objects and so lack a bunch of the useful
functions on the Array prototype. This often cause developers to do
ugly hacks like

var realArray = Array.prototype.slice.call(domObject, 0);

Generally speaking, this is fixable by changing DOMStringList into
sequence<DOMString> in the webidl. This would cause these functions to
return real JS Arrays instead.

The only thing preventing us from doing this is that the DOM classes
for historical reasons have a .item() function on them. This .item()
function is redundant and most developers simply use domObject[n]
rather than domObject.item(n). Sadly the .item() functions seem used
enough that switching to Arrays isn't web compatible.

I was thinking we could introduce a sequence_with_item<...> type in
WebIDL. This would simply map to a real Array object, but one which
has a .item function added to it. Either by adding a .item function on
the returned object itself, or by making the return object have a
different prototype, but otherwise be a normal Array.

Obviously an alternative is to just leave things as status-quo.

/ Jonas
Received on Wednesday, 10 June 2015 04:46:57 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 10 June 2015 04:46:58 UTC