-
Notifications
You must be signed in to change notification settings - Fork 165
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
Investigate banning nullable enums #213
Comments
Should optional dictionary members of enum type also be required to have a default value? Otherwise undefined can mean something other than one of the enum values. |
I think that would break |
Optional enum values (in dictionaries, and as arguments) may make sense as a "use the default" kind of thing, especially when the default is computed in a complicated way from other arguments or dictionary members, or depends on prior state or whatnot. I looked at where nullable enums are used in Gecko's IDL. Apart from codegen tests and some nonstandard APIs, they are not used. In the nonstandard APIs, there are some cases in which null is used to indicate "object is not in a state that can provide this data right now". And boy are there a lot of uses like that. :( Those APIs were all written by JS hackers, for what it's worth, so it's a data point in terms of what "authors" expect. |
I found a nullable enum in Blink and Gecko: Found via https://crbug.com/662898 because it doesn't match the spec. |
Yes, I found that too and filed https://bugzilla.mozilla.org/show_bug.cgi?id=1313966 on Gecko at the time. I didn't include it in #213 (comment) as a result. |
Do you recall if there were any others that are web exposed and could be risky to change? |
There aren't any. |
Great, thanks for checking! |
Here's a new one: https://wicg.github.io/media-capabilities/#screen-extension The |
Yeah, I don't see why using two types is better than a single type for |
From a JS dev perspective, empty strings as falsy values in enums are icky (see |
@tobie that's also an argument against null though. |
Well, not really. |
Null is just as falsy though, so if you want to avoid that you should do something else. |
Well, all of this is pretty subjective anyway. The point I was trying to make is that replacing |
I noticed that |
Found some more nullable enums: Edit: I found these by elaborate grepping in https://github.com/tidoust/reffy-reports/tree/master/whatwg/idl: |
Yeah, this one is a bit weird. It might have been nicer to have an explicit "default" value or something... @birtles do you recall why null was picked here? I should have asked this in https://bugzilla.mozilla.org/show_bug.cgi?id=1429671... This one hasn't had wide review yet, so hard to say what the story there is. The prose talks about a default value of "", the IDL has no default value at all. I would assume that this IDL has nothing to do with whatever reality exists here, if any.
I think here null is used to mean "we don't know". Not sure why that couldn't be an enum value, but its possible that these specs don't fully control the value set of these enums or something... @jan-ivar do you know? |
@alexshalamov, can you comment on the Web NFC case? Since it's an optional dictionary member, I believe just using undefined to mean missing would be fine. I've filed w3c/web-nfc#149. |
We could have a "default" value, I guess. The reasoning at the time is mostly covered in w3c/csswg-drafts#2072 (comment), where consistency with That is you can write: elem.animate({
backgroundColor: ['red', 'green', 'blue', 'orange', 'purple'],
offset: [0, null, null, 0.95, 1],
}, 1000); (where So, it made sense that i.e. elem.animate({
backgroundColor: ['red', 'green', 'blue', 'orange', 'purple'],
offset: [0, null, null, 0.95, 1],
composite: ['replace', null, null, null, 'replace'],
}, 1000); With a default value that would become: elem.animate({
backgroundColor: ['red', 'green', 'blue', 'orange', 'purple'],
offset: [0, null, null, 0.95, 1],
composite: ['replace', 'auto', 'auto', 'auto', 'replace'],
}, 1000); Which could work. We haven't shipped composite modes in any browser but we are planning to ship |
“auto” looks way more legible and obvious, fwiw. I’d encourage you to change it. |
Ok, I've filed a PR to change Web animations and written a patch for Firefox and wpt should that PR be accepted. |
I've updated Web Animations (and Firefox implementation) so that it no longer uses nullable enums. |
I cannot think of a single scenario where that would be preferable over an additional enum value. Of course, it might be too late to change this.
The text was updated successfully, but these errors were encountered: