Re: [FileAPI] Why is FileList a sequence?

Ian Hickson:
> Web Apps 1.0 will change if you need it to. Don't constrain on my account 
> here. I'll do whatever you think we should do. The only places I use it 
> are in an argument to a method because I want to allow authors to pass in 
> literal JS Arrays of values, and on a NodeList descendant where I just 
> wanted the user of the API to be able to get a JS Array of values. I don't 
> think there's much implementation compatibility constraint here.

OK.

The latter isn’t a good use, BTW, as mentioned in the reply to Anne,
because it would mean a fresh Array object is constructed each time you
get the values property of PropertyNodeList.  So for what you might
expect to be a common usage pattern,

  for (var i = 0; i < myPropertiesCollection.values.length; i++) {
    doSomethingWith(myPropertiesCollection.values[i]);
  }

it’s going to result in a lot of wasted work.  To make it clear that’s
going to happen, I’d recommend making it a method instead.

Or if you want to retain the property style access, you could use T[]
instead, and state that it is a read only array.  The object returned by
the property wouldn’t be a real JS Array, though.

(Or you could go the route of defining an interface with index getters.)

> (Are the other two implemented by any browsers?)

Not that I’m aware of.

I think sequence<T> is fine for the purpose of accepting a JS Array of
items as a method argument.  Presumably the requirement to have
something like that in WA 1.0 isn’t going away, and there isn’t another
way to do that in Web IDL currently, so unless there are concrete
problems with sequence<T> or anyone has ideas on how to do it better,
I’ll just leave it alone for now.

-- 
Cameron McCormack ≝ http://mcc.id.au/

Received on Friday, 11 March 2011 01:41:54 UTC