webidl icon indicating copy to clipboard operation
webidl copied to clipboard

Enums that does not throw?

Open saschanaz opened this issue 5 years ago • 12 comments

https://github.com/w3c/webauthn/commit/a133711055b3b13c700fe2ea2acd62fe749a3f74 (https://github.com/w3c/webauthn/pull/1392)

Web Authentication just dropped their uses of enums because it's not forward compatible; older implementation throws when passing a newly added enum value. They now use DOMString and have proses to ignore unknown enum values:

Client platforms MUST ignore unknown values, treating an unknown value as if the member does not exist.

Should this be supported in IDL level? Is there any other specification that does the same thing?

saschanaz avatar Jun 13 '20 17:06 saschanaz

Is there any other specification that does the same thing?

I think this is what pretty much every attribute reflecting an “enumerated” HTML content attribute does. The Web IDL attributes are typed as DOMString, and there are additional rules for their behavior defined in HTML, though many of these cases are a bit more complex (the validity of tokens is potentially dynamic vis a vis other state, if I understand right):

bathos avatar Jun 13 '20 18:06 bathos

Yes, some HTML IDL attributes e.g. dir may be able to benefit from this feature.

saschanaz avatar Jun 13 '20 19:06 saschanaz

IDL does not throw for enums passed to setters. It only does so for methods and constructors.

@jcjones could you elaborate a bit on https://github.com/w3c/webauthn/issues/1376? It's a little surprising to see specifications deviate from the platform norms.

annevk avatar Jun 14 '20 08:06 annevk

Sure, @annevk: The bug was https://bugzilla.mozilla.org/show_bug.cgi?id=1573245 for the webcompat issue with Chrome. When they added the enum type and began using it, Gecko threw Uncaught (in promise) TypeError: CredentialsContainer.get: 'cable' (value of 'transports' member of PublicKeyCredentialDescriptor) is not a valid value for enumeration AuthenticatorTransport. while parsing the scripts.

All uses of WebAuthn are through passing dictionaries to the methods navigator.credentials.get or navigator.credentials.create, which presumably is why they throw.

It sounds like it would have been more future-proof if Credentials Management had instead returned an interface which could have been manipulated with setters, and had some sort of execute method.

jcjones avatar Jun 15 '20 21:06 jcjones

Thanks, I can see how this might be useful for certain dictionaries, although normally I'd expect the caller to do some kind of feature testing. For IDL we should probably wait until more use cases show up around methods/dictionaries.

annevk avatar Jun 16 '20 08:06 annevk

@annevk

IDL does not throw for enums passed to setters. It only does so for methods and constructors.

Thanks for clarifying/correcting this. I’d never noticed the special casing in create-an-attribute-setter and had assumed HTML not using IDL enums for reflected content attributes was about not-throwing. Is the use of DOMString for these in HTML just cause of the invalid/missing value defaults + sometimes-stateful valid value sets?

bathos avatar Jun 18 '20 00:06 bathos

@bathos I think it's also that HTML has to deal with equivalent setAttribute() calls and those will always take DOMString.

annevk avatar Jun 18 '20 05:06 annevk

Just found that DataTransfer#dropEffect/DataTransfer#effectAllowed also have the same ignoring behavior.

saschanaz avatar Aug 16 '20 20:08 saschanaz

linking to the similar request in #491 for record keeping

dontcallmedom avatar Jun 21 '21 13:06 dontcallmedom

linking to the similar request in #491 for record keeping

Should we close either one?

saschanaz avatar Aug 09 '21 01:08 saschanaz

For developing FLEDGE [0], we'd be interested in enums that don't throw, since we have several "enums" that will grow as we add new functionality. Often, feature detection seems like it needn't be necessary, since ignoring unsupported enum fields on older browsers seems sufficient for our use-cases?

For now, due to this issue, we're using strings instead of enums.

[0] https://github.com/WICG/turtledove/blob/main/FLEDGE.md

caraitto avatar Feb 28 '23 17:02 caraitto

For integers we have Clamp and EnforceRange extended attributes to control throwing or changing the value. If specs want to use enums but not throw it seems useful to add an extended attribute to opt in to no throwing. Should it only work when setting a default value, where unknown values are converted to the default value?

zcorpan avatar Jun 05 '23 15:06 zcorpan