Skip to content

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

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

lukewarlow
Copy link
Member

@lukewarlow lukewarlow commented Jul 15, 2025

Introduce enumerated attribute reflection IDL

  • [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.

  • At least two implementers are interested (and none opposed):

  • Tests are written and can be reviewed and commented upon at:

  • Implementation bugs are filed:

    • Chromium: …
    • Gecko: …
    • WebKit: …
    • Deno (only for timers, structured clone, base64 utils, channel messaging, module resolution, web workers, and web storage): …
    • Node.js (only for timers, structured clone, base64 utils, channel messaging, and module resolution): …
  • 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 )

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.
@lukewarlow
Copy link
Member Author

The second commit here is the interesting part for this specific PR, if you have feedback on the underlying stuff comment on #11450

@lukewarlow
Copy link
Member Author

lukewarlow commented Jul 16, 2025

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].

[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>;
Copy link
Member Author

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>;
Copy link
Member Author

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.

- Swap code for span
- Add var to clampedMin and clampedMax
- Correct plural
This is used to apply the reflection code only for the setter.
… 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy