-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Introduce enumerated attribute reflection extended attributes #11455
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
base: main
Are you sure you want to change the base?
Conversation
A number of extended attributes are added which trigger IDL attribute reflection: - [Reflect] and [Reflect=string] cover basic content attribute reflection cases. - [ReflectURL] and [ReflectURL=string] covers reflection of USV attributes, which represent URLs. - [ReflectNonNegative] and [ReflectNonNegative=string] covers reflection of long attributes that should be limited to only non-negative numbers. - [ReflectPositive] and [ReflectPositive=string] covers reflection of double and unsigned long attributes which should be limited to positive numbers. - [ReflectPositiveWithFallback] and [ReflectPositiveWithFallback=string] covers reflection of double and unsigned long attributes which should be limited to positive numbers with fallback. Additionally: - [ReflectRange=(integer, integer)] can be used alongside others on unsigned long attributes that should be clamped to a range. - [ReflectDefault=number] can be used alongside others on double, long and unsigned long attributes that should be reflected with a default value.
The second commit here is the interesting part for this specific PR, if you have feedback on the underlying stuff comment on #11450 |
Interestingly some of these attributes have their keywords defined in external specs. one of them (refererpolicy) has an enum definition, so potentially we could update that spec to simply add the [InvalidValueDefault, MissingValueDefaut] attributes to the enum. And refer to it from within the [ReflectEnum]. |
4387065
to
0ede3bc
Compare
[SameObject, PutForwards=<span data-x="dom-DOMTokenList-value">value</span>, <span data-x="xattr-Reflect">Reflect</span>] readonly attribute <span>DOMTokenList</span> <dfn attribute for="HTMLLinkElement" data-x="dom-link-sizes">sizes</dfn>; | ||
[<span>CEReactions</span>, <span data-x="xattr-Reflect">Reflect</span>="<code data-x="attr-link-imagesrcset">imagesrcset</code>"] attribute USVString <dfn attribute for="HTMLLinkElement" data-x="dom-link-imageSrcset">imageSrcset</dfn>; | ||
[<span>CEReactions</span>, <span data-x="xattr-Reflect">Reflect</span>="<code data-x="attr-link-imagesizes">imagesizes</code>"] attribute DOMString <dfn attribute for="HTMLLinkElement" data-x="dom-link-imageSizes">imageSizes</dfn>; | ||
[<span>CEReactions</span>, <span data-x="xattr-Reflect">Reflect</span>="<span data-x="attr-link-referrerpolicy">referrerpolicy</span>", <span data-x="xattr-ReflectEnum">ReflectEnum</span>=<span data-x="enum-referrer-policy">ReferrerPolicy</span>] attribute DOMString <dfn attribute for="HTMLLinkElement" data-x="dom-link-referrerPolicy">referrerPolicy</dfn>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ReferrerPolicy enum in the webappsec referrer policy spec needs [InvalidValueDefault, MissingValueDefault]
added to it for this to be complete.
[<span>CEReactions</span>] attribute DOMString <span data-x="dom-link-rel">rel</span>; | ||
[<span>CEReactions</span>, <span data-x="xattr-Reflect">Reflect</span>] attribute USVString <dfn attribute for="HTMLLinkElement" data-x="dom-link-href">href</dfn>; | ||
[<span>CEReactions</span>, <span data-x="xattr-Reflect">Reflect</span>="<span data-x="attr-link-crossorigin">crossorigin</span>", <span data-x="xattr-ReflectEnum">ReflectEnum</span>=<span>CORSSettingsKeywords</span>] attribute DOMString? <dfn attribute for="HTMLLinkElement" data-x="dom-link-crossOrigin">crossOrigin</dfn>; | ||
[<span>CEReactions</span>, <span data-x="xattr-Reflect">Reflect</span>] attribute DOMString <dfn attribute for="HTMLLinkElement" data-x="dom-link-rel">rel</dfn>; | ||
[<span>CEReactions</span>] attribute DOMString <span data-x="dom-link-as">as</span>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could use ReflectEnum but the current keyword definitions are in the fetch spec. We could define the enum in HTML but then we might end up out of sync, or we need to define the enum in the fetch spec.
0ede3bc
to
a651540
Compare
- Swap code for span - Add var to clampedMin and clampedMax - Correct plural
This is used to apply the reflection code only for the setter.
… instead of ReflectURL
… attribute, otherwise an integer, also clean up the single double usage to actually use a decimal.
- [ReflectEnum=identifier] can be used alongside [Reflect] on DOMString and DOMString? attributes to identify the IDL enum which holds the known value keywords. Additionally, 3 new extended attributes are allowed on enums: - [InvalidValueDefault] and [InvalidValueDefault=string] sets the value to be used when the content attribute has an invalid value. - [MissingValueDefault] and [MissingValueDefault=string] sets the value to be used when the content attribute is missing. - [EmptyValueDefault] and [EmptyValueDefault=string] sets the value to be used when the content attribute is the empty string.
a651540
to
33e6fc8
Compare
Introduce enumerated attribute reflection IDL
Additionally, 3 new extended attributes are allowed on enums:
[InvalidValueDefault] and [InvalidValueDefault=string] sets the value to be used when the content attribute has an invalid value.
[MissingValueDefault] and [MissingValueDefault=string] sets the value to be used when the content attribute is missing.
[EmptyValueDefault] and [EmptyValueDefault=string] sets the value to be used when the content attribute is the empty string.
At least two implementers are interested (and none opposed):
Tests are written and can be reviewed and commented upon at:
Implementation bugs are filed:
Corresponding HTML AAM & ARIA in HTML issues & PRs:
MDN issue is filed: …
The top of this comment includes a clear commit message to use.
(See WHATWG Working Mode: Changes for more details.)
/common-dom-interfaces.html ( diff )
/dom.html ( diff )
/edits.html ( diff )
/embedded-content-other.html ( diff )
/embedded-content.html ( diff )
/form-control-infrastructure.html ( diff )
/form-elements.html ( diff )
/forms.html ( diff )
/grouping-content.html ( diff )
/iframe-embed-object.html ( diff )
/image-maps.html ( diff )
/images.html ( diff )
/index.html ( diff )
/infrastructure.html ( diff )
/input.html ( diff )
/interaction.html ( diff )
/interactive-elements.html ( diff )
/links.html ( diff )
/media.html ( diff )
/obsolete.html ( diff )
/popover.html ( diff )
/scripting.html ( diff )
/semantics.html ( diff )
/tables.html ( diff )
/text-level-semantics.html ( diff )
/urls-and-fetching.html ( diff )