Re: Unclear behavior of dictionary member default values

On Fri, Jun 8, 2012 at 10:14 AM, Jonas Sicking <jonas@sicking.cc> wrote:
> On Fri, Jun 8, 2012 at 12:17 AM, Anne van Kesteren <annevk@annevk.nl> wrote:
>> On Fri, Jun 8, 2012 at 8:46 AM, Boris Zbarsky <bzbarsky@mit.edu> wrote:
>>> It's not quite clear to me what the right behavior of dictionary member
>>> default values is.  Specifically:
>>>
>>> 1)  For a dictionary argument, does the implementation actually need to keep
>>> track of whether a member with a default value was present or not?  Or can
>>> it simply set the member to that default value and treat it as present?
>>>
>>> 2)  For dictionary return values, what, if anything, should happen with
>>> default values?  Should they end up on the JS object if the relevant member
>>> was not present in the dictionary?
>>
>> I think the default value concept is actually problematic as the
>> dictionary argument is typically optional. When that is the case you
>> still need to handle the case for when it is omitted and define the
>> default values in prose. (I'd be interested in seeing examples of
>> specifications where this is not the case.)
>
> The way I would prefer for it to work is that dictionaries should
> always be optional arguments. And passing null or undefined as the
> argument value should be equivalent as passing an empty object. So for
>
> interface Foo {
>  func(optional FuncDict params);
> };
>
> dictionary FuncDict {
>  DOMString x = "val";
> };
>
> All of the following should IMHO be equivalent:
>
> myFooObj.func();
> myFooObj.func(undefined);
> myFooObj.func(null);
> myFooObj.func({});
> myFooObj.func({x: "val"});

Absolutely.  I'm not too concerned about the null case (null is
"missing, but not undefined", but I'm not sure exactly where the line
should be drawn between it acting similarly or different to
undefined), but all the rest should definitely have identical results.

~TJ

Received on Friday, 8 June 2012 17:36:30 UTC