-
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
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
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>; |
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.
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>; |
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.
a651540
to
33e6fc8
Compare
- [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.
33e6fc8
to
67c3c25
Compare
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 |
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.
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.
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.
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.
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?).
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.
But are they really part of the enum at that point?
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.
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.
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.
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>] |
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.
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>", |
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.
Should these be the dfn
s? 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, |
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.
ReflectEnum should be mutually exclusive with Reflect, no?
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.
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)
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.
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.
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.
That's a good idea.
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.
#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 |
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.
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</abbr> today.</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>] |
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.
Cases like this are where the idea of putting them on the values doesn't work.
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.
Implementation bugs are 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 )
/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 )