Re: Selectors: name find method and find signature

On 9/13/13 3:19 PM, Domenic Denicola wrote:
> From: Boris Zbarsky [mailto:bzbarsky@MIT.EDU]
>
>> Consider this IDL:
>>
>>    dictionary Dict1 {
>>      long a = 5;
>>    };
>>
>>    dictionary Dict2 {
>>      sequence<Dict1> dicts;
>>    }
>>
>>    void foo(optional Dict2 arg);
>>
>> How would you express eqivalent semantics with destructuring?
>
> ```js
> function foo({ dicts: [...dict1s] } = undefined) { }
> ```
>
> gets pretty close. (`= undefined` is unnecessary, of course, but I include it for clarity.)

It does?

> All that remains is some kind of annotation to ensure that every element of `dict1s` also gets destructured

Ah, you mean "the hard part" is all that remains?  ;)  What happens when 
the nesting is deeper?

> as `let { a } = dict1s[0]` etc.

No, this doesn't do what.  What's needed here is a "destructuring" 
in-place so that foo ends up with a single object representing "arg" 
that's safe to use and that it can pass to other functions that want to 
work with it.  That's what WebIDL gives me right now and what 
destructuring most emphatically does not do.  With destructuring the 
best that can be done is to manually break the input up into its 
component pieces and then rebuild it from scratch.

Now obviously destructuring can be an implementation strategy for 
implementing the current WebIDL behavior, but what WebIDL does right now 
does not just turn into some simple destructuring one-liner.

>> How does destructuring take care of making sure that arg.dicts is a new array?
>
> As you can see this is taken care of.

No, it's not.  that I can see.  What I end up with in the function is a 
variable called "dicts1", which is an array.  I end up with a variable 
called "dicts" which is also an array (but not a "safe" one).  What I 
don't end up with is an object named "arg" which is a safe object and 
which has a property named "dicts" which is a safe array.

>> How does it ensure arg.dicts[0] is a new object with an "a" property, not whatever was passed in?
>
> Indeed, there is no way to set up a destructuring pattern for every element in a sequence, but destructuring is still the approach you will want to use, i.e. `let { a } = dict1s[i]` in a loop.

Again, that's a reasonable implementation strategy, but it's something I 
don't want people to have to write by hand every time given that there's 
a perfectly simple declarative way of describing this sort of 
datastructure, and then we can auto-generate the boilerplate 
destructuring and rematerializing bits.  Because when doing it by hand, 
it's too easy to forget to do it...

-Boris

Received on Friday, 13 September 2013 19:51:01 UTC