- From: Cameron McCormack <cam@mcc.id.au>
- Date: Fri, 11 Mar 2011 09:29:12 +1300
- To: Anne van Kesteren <annevk@opera.com>
- Cc: Simon Pieters <simonp@opera.com>, Arun Ranganathan <arun@mozilla.com>, public-webapps <public-webapps@w3.org>
Anne van Kesteren: > > > Lets at least remove sequence<T> from the draft then. Cameron McCormack: > > Other specifications use it, and it really serves a different > > purpose from things like NodeList, like passing in native Array > > objects to DOM methods. So I don’t think we should remove it. Anne van Kesteren: > Which specifications use it then? The ones I could find were: Web Applications 1.0, RDFa API and The System Information API (admittedly fewer than I thought!). > And how is that different from using the T[] construct? Think of sequence<T> like vector<T> in C++, and T[] as a vector<T>&. The sequence type allows passing in and receiving a list by value. If you pass an Array object in to a method expecting a sequence<T>, then the implementation copies those elements, can never modify the Array object passed in (apart from the side effects of getters on the Array, I guess!) and will not hold a reference to it after the method is done, either. The array type T[] (which seems to have less buy-in at the moment) is a reference to an object that is a list of items. In the JS binding it maps to a special host object that exposes index properties, has a length property, and inherits from the Array prototype, so it can behave similarly to native Arrays. Passing in an object of this type to a DOM method allows the implementation to keep a reference to that array, and it might change it later. So if your JS has a reference to the object, then its contents can appear to have changed. T[] objects can be writable or read only, too. It would be bad to define an interface like this: interface Cattery { sequence<Cat> kittens; }; because every time you get the kittens property, a new native Array object will be created. If you just want to expose the list of kittens with something array-like, you could do interface Cattery { Cat[] kittens; }; and then getting the kittens property could return the same “array host object” each time. -- Cameron McCormack ≝ http://mcc.id.au/
Received on Thursday, 10 March 2011 20:29:57 UTC