Skip to content

Consider a pattern for dictionary arguments which must have at least one member #903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
domenic opened this issue Jul 27, 2020 · 4 comments

Comments

@domenic
Copy link
Member

domenic commented Jul 27, 2020

This is a continuation of #130.

There are a number of places on the platform that end up marking their dictionary arguments as "optional", even though they're not really optional. They just have a requirement that can't be expressed in IDL today: at least one member must be present. Examples:

I think we might have reached the point where it's worth making this pattern first-class. It would remove a bit of spec boilerplate in each spec, and it would make the IDL less confusing for readers (see e.g. whatwg/dom#332).

I suggest something like

partial interface MutationObserver {
  void observe(Node target, [OneMemberRequired] MutationObserverInit options);
};

I believe this explicitness sidesteps the problems mentioned in #130, where we were worried that people would not properly mark truly-optional trailing dictionaries as optional. You have to really know what you're doing to use this kind of extended attribute.

We could also use a keyword (onememberrequired MutationObserverInit options) for symmetry with optional. In general the dividing line between syntax and extended attributes is kind of blurry in Web IDL; see some discussion in #857 (comment).

@annevk
Copy link
Member

annevk commented Aug 4, 2020

It doesn't seem like this would simplify the logic for observe(). And I'm also not sure how it would help getUserMedia() as what it really wants are true or dictionary values, not just any values.

@domenic
Copy link
Member Author

domenic commented Mar 2, 2021

Another instance: WICG/navigation-api#52

@saschanaz
Copy link
Member

saschanaz commented Mar 5, 2021

It doesn't seem like this would simplify the logic for observe().

IMO this one is more about the syntax rather than about simplifying logic. I can imagine an author write an operation with the one-member-required behavior in mind and then get yelled by IDL validator. It also affects TypeScript code generation, BTW.

@domenic
Copy link
Member Author

domenic commented Mar 5, 2021

I'm mostly interested in this for logic-simplification; comments are fine for readers. But I think we have enough cases now where it would simplify the logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants