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 1 commit 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.

  • Implementation bugs are filed:

    • Chromium: …
    • Gecko: …
    • WebKit: …
    • Servo: ...
    • Ladybird: ...
    • JSDOM: ...
  • 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 )
/embedded-content.html ( diff )
/form-control-infrastructure.html ( diff )
/form-elements.html ( diff )
/forms.html ( diff )
/iframe-embed-object.html ( diff )
/image-maps.html ( diff )
/images.html ( diff )
/infrastructure.html ( diff )
/input.html ( diff )
/interaction.html ( diff )
/media.html ( diff )
/popover.html ( diff )
/scripting.html ( diff )
/semantics.html ( diff )
/tables.html ( diff )
/text-level-semantics.html ( diff )
/urls-and-fetching.html ( diff )

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

source Outdated
[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.

source Outdated
[<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.

@lukewarlow lukewarlow force-pushed the reflect-enum-idl branch 2 times, most recently from a651540 to 33e6fc8 Compare July 16, 2025 18:28
- [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.
attribute">extended attributes</span> must either take no arguments, or take a string. They must
not appear on anything other than an enum.</p>

<p>TODO: Define how [InvalidValueDefault], [MissingValueDefault], and [EmptyValueDefault] actually
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @annevk and @domenic I'm curious how you think I should go about this.

I think the idea is solid it's mostly a question of how to thread it editorially?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's easier if you put them on the enum values. Does IDL then give you the ability to inspect them as go over the enum values? That will make it possible to inspect them from the relevant places in prose I'd think.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going on the value only works when you specify a keyword, but sometimes you simply want the empty string or null value (depending on DOMString vs DOMString?).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But are they really part of the enum at that point?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're part of the reflection behaviour of the IDL attribute, which is ultimately what we want to codify in IDL. But yes strictly they're not one of the keywords.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4. If attributeDefinition indicates it is an [enumerated attribute](https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#enumerated-attribute) and the [reflected IDL attribute](https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#reflected-idl-attribute) is defined to be [limited to only known values](https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#limited-to-only-known-values):

      4.1 If contentAttributeValue does not correspond to any state of attributeDefinition (e.g., it is null and there is no [missing value default](https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#missing-value-default)), or if it is in a state of attributeDefinition with no associated keyword value, then return the empty string.

I guess you could change this slightly such that the lack of InvalidValueDefault etc results in the "" or null being returned?

@@ -7548,6 +7549,12 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute

<h4>CORS settings attributes</h4>

<div w-nodev><pre><code class="idl">[<span data-x="xattr-InvalidValueDefault">InvalidValueDefault</span>="<span data-x="attr-crossorigin-anonymous-keyword">anonymous</span>", <span data-x="xattr-MissingValueDefault">MissingValueDefault</span>]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nicer if these attributes go directly on the keywords below so we don't have to repeat the keywords. I realize it's novel IDL syntax, but I think that's syntax we want to have in engines anyway.

@@ -7548,6 +7549,12 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute

<h4>CORS settings attributes</h4>

<div w-nodev><pre><code class="idl">[<span data-x="xattr-InvalidValueDefault">InvalidValueDefault</span>="<span data-x="attr-crossorigin-anonymous-keyword">anonymous</span>", <span data-x="xattr-MissingValueDefault">MissingValueDefault</span>]
enum <dfn enum>CORSSettingsKeywords</dfn> {
"<dfn attr-value for="audio/crossorigin,video/crossorigin,img/crossorigin,link/crossorigin,script/crossorigin" data-x="attr-crossorigin-anonymous-keyword">anonymous</dfn>",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be the dfns? I think this will also get quite confusing if we expose them both as attr-value and enum values. Not sure how to resolve that.

<p>The <code data-x="xattr-ReflectEnum">[ReflectEnum]</code> <span>extended attribute</span> must
take an identifier. It must only be used on attributes with a type of <code
data-x="idl-DOMString">DOMString</code>. Additionally, it must only appear alongside <code
data-x="xattr-Reflect">[Reflect]</code>. The provided identifier must be that of an IDL enum,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReflectEnum should be mutually exclusive with Reflect, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reflect triggers the reflection and takes the attribute name string. ReflectEnum limits to only known values and takes the enum identifier. So they are used together. (ReflectEnum is more like ReflectDefault in that sense)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's an idea: make Reflect without argument implied if ReflectEnum, ReflectDefault, or ReflectRange are present. Because in the vast majority of (all?) cases it's just noise.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#11518 - PR to do that here.

attribute">extended attributes</span> must either take no arguments, or take a string. They must
not appear on anything other than an enum.</p>

<p>TODO: Define how [InvalidValueDefault], [MissingValueDefault], and [EmptyValueDefault] actually
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's easier if you put them on the enum values. Does IDL then give you the ability to inspect them as go over the enum values? That will make it possible to inspect them from the relevant places in prose I'd think.

@@ -13936,6 +13976,13 @@ Transport Protocol">HTTP&lt;/abbr> today.&lt;/p></code></pre> <!-- DO NOT REWRAP

<h5>The <code data-x="attr-dir">dir</code> attribute</h5>

<div w-nodev><pre><code class="idl">[<span data-x="xattr-InvalidValueDefault">InvalidValueDefault</span>, <span data-x="xattr-MissingValueDefault">MissingValueDefault</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.

Cases like this are where the idea of putting them on the values doesn't work.

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.

2 participants
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