Closed domenic closed 7 years ago
Using this "as enums" when spec's updated with new values, say X means that users that would like to fall back to "" as default have to do either:
Enum: foo.hint = X; if (foo.hint != X) foo.hint = "";
Or possibly, if this is possible? if ((foo.hint = X) != X) foo.hint = "";
TypeError: try { foo.hint = X; } catch(TypeError) { foo.hint = ""; }
I'm not sure which one I like best. Eew to both. :(
Maybe go with enums since they have presedence and both seem to generate about equally-ugly code?
That makes sense to me. However, I want to understand your scenario a bit more. I think as-enums gives good behavior in reality. Consider wanting to set it to "animation" in browsers that support that, and fall back to "fluid" in other browsers. I think you'd do:
track.mediaContentTypeHint = "fluid";
track.mediaContentTypeHint = "animation";
and everything would work perfectly. I don't understand in what scenario you'd write the explicit-test-and-set-to-empty-string code.
I guess the other scenario would be if track is stale and is:
track.mediaContentTypeHint = "inappropriateForAnimation"; // Old value from before, worse than "" // ... track.mediaContentTypeHint = "animation";
But setting them in order of what you want makes sense to me too, then you get the most appropriate value. Act-as-enum sounds good to me then (with different values depending on .kind == "audio"/"video").
Per https://heycam.github.io/webidl/#dfn-attribute-setter (step 4), enumeration types ignore attempts to set them to invalid values. They just leave the previous value in place. If we want to be consistent with enumeration types, we'd want to use this behavior. So your algorithm for the setter (#2) would just bail out if it sees an incorrect value.
If we think this is bad behavior, we should consider two possibilities:
mediaContentTypeHint
only have a getter, then adding a seperate setter functionsetMediaContentTypeHint()
that throws, ortrySetMediaContentTypeHint()
that returns a boolean and resets it tonull
, or similar.Notably I don't think it'd be OK to make it reset to
null
upon encountering an invalid value. That would be just too surprising.