This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 26303 - Add a way to have required dictionary entries
Summary: Add a way to have required dictionary entries
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: WebIDL (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Cameron McCormack
QA Contact: public-webapps-bugzilla
Depends on:
Reported: 2014-07-10 02:35 UTC by Boris Zbarsky
Modified: 2014-08-26 14:45 UTC (History)
7 users (show)

See Also:


Description Boris Zbarsky 2014-07-10 02:35:30 UTC
This has come up a few times now; people keep wanting dictionaries some of whose entries are required to be present.  This is particularly important when writing algorithms that need to operate on separate different dictionaries and hence want to describe all the behavior of the dictionary in IDL, but is helpful for simplifying spec prose in other cases too.
Comment 1 Anne 2014-07-11 16:38:51 UTC
Do you have concrete examples where this is a problem? The few times I've had something like this, IDL syntax would not have helped.
Comment 2 Boris Zbarsky 2014-07-11 17:07:40 UTC
The web crypto spec wants to have a generic algorithm that processes a bunch of different dictionaries.  It wants to enforce some values being present, but has no way to do that right now.  So they're using nullable to indicate "doesn't have to be present", which is really not what we want.

See mail thread at and following
Comment 3 Anne 2014-07-29 12:56:15 UTC
Nullable would indeed be wrong as per that thread. Defaulting to an empty ArrayBuffer is not making it required though. Will we throw TypeError or some such for these cases?

I guess that seems fine. There are some ideas for JavaScript in general to make certain arguments required, not sure how far along that is now. Hard to track JavaScript proposals.
Comment 4 Boris Zbarsky 2014-07-29 13:03:10 UTC
> Defaulting to an empty ArrayBuffer is not making it required though.

Right, they have some optional things that they want to default to empty ArrayBuffers.  They have other things that they want to be required, with no defaulting.

> Will we throw TypeError or some such for these cases?

That would be the idea, yes.
Comment 5 Ms2ger 2014-08-23 11:25:49 UTC
Last few times this came up, we suggested using required arguments, no?
Comment 6 Boris Zbarsky 2014-08-23 13:18:55 UTC
We did, but that doesn't work for APIs like webcrypto which want to take different dictionaries depending on the type of algorithm and some of those dictionaries want to have some required entries.  You can't even really do that with overloading, since the behavior depends on the value of a string argument (the algorithm name).

People clearly shouldn't _abuse_ this functionality to create functions which just have a single dictionary argument instead of several useful ones, but there are use cases where doing this makes sense.