- From: Arun Ranganathan <arun@mozilla.com>
- Date: Mon, 10 Sep 2012 18:36:45 -0400
- To: Boris Zbarsky <bzbarsky@MIT.EDU>
- Cc: Glenn Maynard <glenn@zewt.org>, public-webapps@w3.org
I've pinged heycam to see if this is a proper use of the sequence type. I'm not sure it allows for such a variation in parameters. -- A* On Sep 9, 2012, at 2:31 PM, Boris Zbarsky wrote: > On 9/9/12 12:13 PM, Glenn Maynard wrote: >> In particular, a Blob represents immutable binary data. That means >> that it has to copy the input anyway. Given that, it doesn't make >> sense to pass the input by reference if the caller _does_ happen to >> have an WebIDL array object. >> >> That doesn't mean it copies the array itself, though. > > That's true, but in most cases (certainly the ones where a JavaScript array will be passed in) that would happen anyway. > >> (Though both ways, this seems like an implementation detail > > It's not quite. > >> I'd expect a mature binding system to let you annotate implementations to say >> things like "make a copy for me instead of passing it in by reference" >> and "don't make a copy even though WebIDL requires it, because we >> fulfill that requirement as a side-effect".) > > Those are both incredibly fragile. Consider some other random spec that has IDL like this. > > interface Foo { > // Returns the argument passed to the constructor > (ArrayBuffer or ArrayBufferView or Blob or DOMString)[] > getInitData(); > }; > Blob implements Foo; > > Now suddenly your annotation is a bug. > > So in practice binding systems aren't particularly likely to implement such annotations because of the increased fragility they introduce. The whole point of having IDL for bindings is to _reduce_ fragility.... > > The upshot is that there are practical drawbacks (slowing down the common use case, as far as I can tell) and at best theoretical benefits (since nothing actually _produces_ platform arrays of the above union!). > > By the way, note that if something produces a DOMString[] and you pass _that_ to a blob constructor as currently defined, then what will happen per spec is that the input will be converted to a sequence<DOMString> and then a new platform array object will be created and the sequence copied into it. So you'll still get passing by value, not by reference. The only way to get passing by reference is if you're given a T[] where T exactly matches your array element type. > > Basically, platform arrays are only useful if you both produce and consume them in the same interface, as far as I can tell... > > -Boris >
Received on Monday, 10 September 2012 22:37:14 UTC