Re: [webauthn] `CredentialRequestOptions` make otherwise valid values invalid in an undesirable way

Why should the default value for non-required members be the empty dictionary rather than `undefined` or `null`? It seems to me like if something is optional with no default value, then the default should be that it isn't there at all.

It seems to me like that behaviour would break all sorts of things. To take an example from the WebAuthn spec, [`CollectedClientData`][ccd] has this definition:

```
dictionary CollectedClientData {
    required DOMString           type;
    required DOMString           challenge;
    required DOMString           origin;
    TokenBinding                 tokenBinding;
};

dictionary TokenBinding {
    required TokenBindingStatus status;
    DOMString id;
};
```

Now, let's assume that heycam/webidl#76 is implemented and say I create a `CollectedClientData` instance and do not set the`tokenBinding` member. Since `CollectedClientData` is a dictionary and the `tokenBinding` member is not required, this would mean that the `tokenBinding` member in the result will be set to the empty dictionary. But since that dictionary is of type [`TokenBinding`][tb] which has a required member, the empty dictionary is an invalid value.

This is probably just another example of the very problem pointed out in the OP, but this example is much easier for me to think about. I imagine this kind of construction (an optional value with a required subcomponent if it's present) is _very_ common, and it seems to me like heycam/webidl#76 would invalidate _all_ such constructions. So unless I'm mistaken somewhere in my analysis (please point it out if I am), I think heycam/webidl#76 should be wontfixed.

[ccd]: https://w3c.github.io/webauthn/#dictdef-collectedclientdata
[tb]: https://w3c.github.io/webauthn/#dictdef-tokenbinding

-- 
GitHub Notification of comment by emlun
Please view or discuss this issue at https://github.com/w3c/webauthn/issues/750#issuecomment-401752095 using your GitHub account

Received on Monday, 2 July 2018 10:19:15 UTC