Re: Web IDL sequenceT and item() method

2011-12-12 Thread Lachlan Hunt

On 2011-12-11 13:55, Marcos Caceres wrote:

On Fri, 09 Dec 2011 19:51:48 +0100, Glenn Adamsgl...@skynav.com 
(mailto:gl...@skynav.com)  wrote:

If the answer is that no item() method is implied, then does the use of
sequenceT  in these newer specs entail dropping this method (with
respect to prior DOM specs)?


I'm also unsure as to the purpose of sequence in practice. Perhaps
some examples of expected usage would help a bit?


I use it in Selectors API for the refNodes parameter, which needs to 
accept any collection of nodes, whether it be a NodeList, Array, jQuery 
object or any other generic numerically indexed object.


e.g. These should all work

var list = document.getElementsByTagName(section)
document.querySelectorAll(:scopeh1, list)

document.querySelectorAll(:scopeh1, $(section)) // JQuery $()

document.querySelectorAll(:scopeh1, [elm1, elm2, elm3])

--
Lachlan Hunt - Opera Software
http://lachy.id.au/
http://www.opera.com/



Re: Web IDL sequenceT and item() method

2011-12-11 Thread Anne van Kesteren

On Fri, 09 Dec 2011 19:51:48 +0100, Glenn Adams gl...@skynav.com wrote:

If the answer is that no item() method is implied, then does the use of
sequenceT in these newer specs entail dropping this method (with  
respect to prior DOM specs)?


The DOM specifications probably need to move back to using interface  
rather than sequence. I was hoping sequence would define the whole  
collection thing magically, but it never turned out that way. Still not  
quite sure what the real use case is for sequence.



--
Anne van Kesteren
http://annevankesteren.nl/



Re: Web IDL sequenceT and item() method

2011-12-11 Thread Marcos Caceres


On Sunday, 11 December 2011 at 12:21, Anne van Kesteren wrote:

 On Fri, 09 Dec 2011 19:51:48 +0100, Glenn Adams gl...@skynav.com 
 (mailto:gl...@skynav.com) wrote:
  If the answer is that no item() method is implied, then does the use of
  sequenceT in these newer specs entail dropping this method (with 
  respect to prior DOM specs)?
 
 
 
 The DOM specifications probably need to move back to using interface 
 rather than sequence. I was hoping sequence would define the whole 
 collection thing magically, but it never turned out that way. Still not 
 quite sure what the real use case is for sequence.
 

I'm also unsure as to the purpose of sequence in practice. Perhaps some 
examples of expected usage would help a bit? 




Re: Web IDL sequenceT and item() method

2011-12-11 Thread Boris Zbarsky

On 12/11/11 7:21 AM, Anne van Kesteren wrote:

The DOM specifications probably need to move back to using interface
rather than sequence. I was hoping sequence would define the whole
collection thing magically, but it never turned out that way. Still not
quite sure what the real use case is for sequence.


Last I checked, defining an interface that takes an in parameter that 
can be a nodelist or JS Array of nodes needs to use sequence, no?  Or am 
I confusing it with array again?


-Boris




Re: Web IDL sequenceT and item() method

2011-12-11 Thread Glenn Adams
In DOM-4 WD, NodeList is now defined as an interface, and not using
sequenceT. [1]

[1] http://www.w3.org/TR/domcore/#interface-nodelist

From what I can tell, WebIDL sequenceT does not entail providing an
item() method, which effectively makes it unusable for any of the
pre-existing DOM interfaces with ECMAScript bindings. It may be worth
modifying WebIDL to generate an item() method in its ECMAScript binding.

On Sun, Dec 11, 2011 at 8:21 AM, Boris Zbarsky bzbar...@mit.edu wrote:

 On 12/11/11 7:21 AM, Anne van Kesteren wrote:

 The DOM specifications probably need to move back to using interface
 rather than sequence. I was hoping sequence would define the whole
 collection thing magically, but it never turned out that way. Still not
 quite sure what the real use case is for sequence.


 Last I checked, defining an interface that takes an in parameter that can
 be a nodelist or JS Array of nodes needs to use sequence, no?  Or am I
 confusing it with array again?

 -Boris





Re: Web IDL sequenceT and item() method

2011-12-11 Thread Cameron McCormack

On 11/12/11 11:55 PM, Marcos Caceres wrote:

I'm also unsure as to the purpose of sequence in practice. Perhaps some 
examples of expected usage would help a bit?


Sequences are for pass by value lists of values.  As with the array 
type, they allow you to pass in a JS array to an operation:


  interface A {
void f(sequencefloat xs);
  };

  getA().f([10, 20, 30]);

or indeed anything that feels enough like an array:

  var o = { length: 3 };
  o[0] = 10;
  o[1] = 20;
  o[2] = 30;
  getA().f(o);

When used as an operation return type, a new JS array is created:

  interface B {
sequencefloat f();
  };

  var a = getB().f();
  assert(a instanceof Array);
  var b = getB().f();
  assert(a != b);

The array type T[] is used for array-like objects for which references 
can be kept by platform objects or by user script, and possibly modified 
by either of them.


If we were ever going to extend one of the built in types with item(), 
it would be the array type T[], which corresponds to a platform object 
that looks a bit like a JS array but is different in various ways (extra 
prototype object in the chain, non-sparse, can be read only / fixed length).


To get an object that is like a T[] but with other custom members, you 
currently have to use [ArrayClass] on an interface:


  [ArrayClass]
  interface FixedLengthWritableNodeList {
readonly attribute unsigned long length;
getter Node item(unsigned long index);
setter void (unsigned long index, Node value);
  };

All [ArrayClass] means is that 
Object.getPrototypeOf(FixedLengthWritableNodeList.prototype) will be 
Array.prototype instead of Object.prototype.  So you can see you need to 
hook up the length and getters/setters yourself there.




Re: Web IDL sequenceT and item() method

2011-12-11 Thread Cameron McCormack

On 12/12/11 2:21 AM, Boris Zbarsky wrote:

Last I checked, defining an interface that takes an in parameter that
can be a nodelist or JS Array of nodes needs to use sequence, no? Or am
I confusing it with array again?


The confusing thing is probably that for the case where you want to take 
in an array as a parameter, and the receiving object will not modify the 
array or keep a hold of it, both sequenceT and T[] will work.




Web IDL sequenceT and item() method

2011-12-09 Thread Glenn Adams
Hi Cameron,

Does the ECMAScript binding for the IDL sequenceT type imply the
existence of an item() method as a element accessor, where an element is a
property whose property name is an array index? If so, then could describe
how it is implied?

The reason I ask is because I'm wondering about compatibility with earlier
DOM specs, e.g., NodeList, CSSRuleList, etc., where an explicit item()
method is defined, and which, in recent newer specifications based on Web
IDL, has been re-expressed in terms of sequenceT. In my review of ECMA
262 3rd and 5th editions, I don't see an explicit mention of an item()
method on Array objects (or their prototype), which are the ECMAScript
binding for IDL sequenceT.

If the answer is that no item() method is implied, then does the use of
sequenceT in these newer specs entail dropping this method (with respect
to prior DOM specs)?

Regards,
Glenn