- From: Boris Zbarsky <bzbarsky@MIT.EDU>
- Date: Sun, 09 Sep 2012 14:31:32 -0400
- To: Glenn Maynard <glenn@zewt.org>
- CC: public-webapps@w3.org
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 Sunday, 9 September 2012 18:32:00 UTC