[heycam/webidl] Can a dictionary with default values ever have a not present member? (#852)

Consider

```webidl
dictionary D {
  DOMString a;
  DOMString b = "";
};

interface I {
  D output();
};
```

with the spec text

> output():
> 1. Return a new `D`.

If JavaScript code calls the `output()` method, do they get `{}`, or do they get `{ b: "" }`?

---

My understanding was that they would get `{}`. From what I can tell, default values only apply when using dictionaries as inputs. This is circumstantially supported by text such as

> In the ECMAScript binding, a value of undefined is treated as not present, or will trigger the default value where applicable.

(only talks about the input, not the output) or

> Dictionary members can also optionally have a default value, which is the value to use for the dictionary member when passing a value to a platform object that does not have a specified value.

which doesn't make a lot of sense, but again is only talking about output, not input, or

> On a given dictionary value, the presence of each dictionary member is optional, unless that member is specified as required

which only mentions the presence being guaranteed if the value is `required`, and doesn't say anything about default values.

And finally, the normative algorithms in https://heycam.github.io/webidl/#es-dictionary where "An ECMAScript value esDict is converted to an IDL dictionary type value" takes into account default values but "An IDL dictionary value V is converted to an ECMAScript Object value" does not mention them.

---

However, there is one sentence which implies that maybe it should be `{ b: "" }`:

> Dictionary members with default values are always considered to be present.

If this is the case, then  "An IDL dictionary value V is converted to an ECMAScript Object value" step 3.1.2 "If the dictionary member named key is present in V" would trigger, and we would define the `b` property.

It's not anywhere formally defined that the value of _V_[_key_] is the default value given in the IDL definition, which is a bit suspicious, but maybe that was just an oversight.

So... we're unsure what to do in Chromium here.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/heycam/webidl/issues/852

Received on Friday, 13 March 2020 15:18:15 UTC