From f8e7dd45f8f3142f5bf7e5e6e0435e82694c3106 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Tue, 24 May 2022 16:02:22 -0400 Subject: [PATCH 1/6] Editorial: algorithmize USVString/DOMString(?) reflection This is easier to read, partially because it spreads out the steps and branches, and partially because of the asserts making some conditions explicit. --- source | 151 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 117 insertions(+), 34 deletions(-) diff --git a/source b/source index 6ce7b1491a8..57c017896ab 100644 --- a/source +++ b/source @@ -7425,40 +7425,123 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute if the content attribute's value is the empty string; and on setting, if the content attribute is not present, it must first be added.

-

If a reflecting IDL attribute is a USVString attribute - whose content attribute is defined to contain a URL, then on getting, if the - content attribute is absent, the IDL attribute must return the empty string. Otherwise, the IDL - attribute must parse the value of the content attribute relative - to the element's node document and if that is successful, return the resulting - URL string. If parsing fails, then the value of the content attribute must be returned - instead, converted to a USVString. On setting, the content attribute must be set to the - specified new value.

- -

If a reflecting IDL attribute is a DOMString attribute - whose content attribute is an enumerated attribute, and the IDL attribute is - limited to only known values, then, on getting, the IDL attribute must return the - keyword value associated with the state the attribute is in, if any, or the empty string if the - attribute is in a state that has no associated keyword value or if the attribute is not in a - defined state (e.g. the attribute is missing and there is no missing value default). If there are multiple keyword values for the state, then - return the conforming one. If there are multiple conforming keyword values, then one will be - designated the canonical keyword; choose that one. On setting, the content attribute - must be set to the specified new value.

- -

If a reflecting IDL attribute is a nullable DOMString - attribute whose content attribute is an enumerated attribute, then, on getting, if - the corresponding content attribute is in its missing value default state then the IDL - attribute must return null, otherwise, the IDL attribute must return the keyword value associated - with the state the attribute is in. If there are multiple keyword values for the state, then - return the conforming one. If there are multiple conforming keyword values, then one will be - designated the canonical keyword; choose that one. On setting, if the new value is - null, the content attribute must be removed, and otherwise, the content attribute must be set to - the specified new value.

- -

If a reflecting IDL attribute is a DOMString or USVString attribute but doesn't fall into any of the above - categories, then the getting and setting must be done in a transparent, case-preserving manner.

+

If a reflecting IDL attribute has the type DOMString:

+ + + +

If a reflecting IDL attribute has the type DOMString?:

+ + + +

If a reflecting IDL attribute has the type USVString:

+ +

If a reflecting IDL attribute is a boolean attribute, then on getting the IDL attribute must return true if the content attribute is set, and false if it is From 9a660de57b6606ffdb98db406aac7d02d8bedfe0 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Tue, 24 May 2022 16:30:22 -0400 Subject: [PATCH 2/6] Editorial: rewrite enumerated attribute explanation Notably this gives an explicit algorithm for determining the state, instead of a couple paragraphs of prose. It also broadens the definition of "canonical keyword" to automatically be determined in simpler cases, instead of only used in tricky cases. --- source | 91 +++++++++++++++++++++++++++++++++------------------------- 1 file changed, 52 insertions(+), 39 deletions(-) diff --git a/source b/source index 57c017896ab..a048fa62144 100644 --- a/source +++ b/source @@ -4589,31 +4589,59 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute

Keywords and enumerated attributes

-

Some attributes are defined as taking one of a finite set of keywords. Such attributes are - called enumerated attributes. The keywords are each - defined to map to a particular state (several keywords might map to the same state, in - which case some of the keywords are synonyms of each other; additionally, some of the keywords can - be said to be non-conforming, and are only in the specification for historical reasons). In - addition, two default states can be given. The first is the invalid value default, the - second is the missing value default.

- -

If an enumerated attribute is specified, the attribute's value must be an ASCII - case-insensitive match for one of the given keywords that are not said to be - non-conforming, with no leading or trailing whitespace.

- -

When the attribute is specified, if its value is an ASCII case-insensitive match - for one of the given keywords then that keyword's state is the state that the attribute - represents. If the attribute value matches none of the given keywords, but the attribute has an - invalid value default, then the attribute represents that - state. Otherwise, there is no default, and invalid values mean that there is no state - represented.

- -

When the attribute is not specified, if there is a missing value default state - defined, then that is the state represented by the (missing) attribute. Otherwise, the absence of - the attribute means that there is no state represented.

+

Some attributes, called enumerated attributes, take + on a finite set of states. The state for such an attribute is derived by combining the + attribute's value, a set of keyword/state mappings given in the specification of each attribute, + and two possible special states that can also be given in the specification of the attribute. + These special states are the invalid value default and the missing + value default.

+ +

Multiple keywords can map to the same state.

The empty string can be a valid keyword.

+

To determine the state of an attribute, use the following steps:

+ +
    +
  1. +

    If the attribute is not specified:

    + +
      +
    1. If the attribute has a missing value default + defined, then return that missing value + default.

    2. + +
    3. Otherwise, return no state.

    4. +
    +
  2. + +
  3. If the attribute's value is an ASCII case-insensitive match for one of the + keywords defined for the attribute, then return the state represented by that keyword.

  4. + +
  5. If the attribute has an invalid value default + defined, then return that invalid value default.

  6. + +
  7. Return no state.

  8. +
+ +

For authoring conformance purposes, if an enumerated attribute is specified, the attribute's + value must be an ASCII case-insensitive match for one of the given keywords that are + not said to be non-conforming, with no leading or trailing whitespace.

+ +

For reflection purposes, states which have any keywords mapping + to them are said to have a canonical keyword. This is determined as follows:

+ + + +

Numbers

@@ -7441,16 +7469,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute is no missing value default), or the content attribute is in a state with no associated keyword value, then return the empty string.

-
  • If there is a single keyword value associated with the state of the content - attribute, then return it.

  • - -
  • If there is a canonical keyword for the state of the content attribute, - then return it.

  • - -
  • Assert: there is only one conforming keyword value associated with the state of the - content attribute.

  • - -
  • Return the single conforming keyword value associated with the state of the content +

  • Return the canonical keyword for the state of the content attribute.

  • @@ -7476,19 +7495,13 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute

    The getter steps are:

      -
    1. Assert: the content attribute is an enumerated attribute:

    2. +
    3. Assert: the content attribute is an enumerated attribute.

    4. Assert: the content attribute is in some state.

    5. If the content attribute is in its missing value default state, then return null.

    6. -
    7. If there is a single keyword value associated with the state of the content attribute, - then return it.

    8. - -
    9. Assert: there is a canonical keyword for the state of the content - attribute.

    10. -
    11. Return the canonical keyword for the state of the content attribute.

    From 5760983458c8e0ab1031280a0dc00dd67070bf46 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Fri, 3 Jun 2022 15:33:30 -0400 Subject: [PATCH 3/6] Review feedback --- source | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/source b/source index a048fa62144..f8dfc0613d5 100644 --- a/source +++ b/source @@ -1398,7 +1398,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute -
    Errors that waste authoring time
    +
    Errors that waste authoring time
    F

    Some constructs are disallowed because historically they have been the cause of a lot of @@ -4608,8 +4608,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute

    1. If the attribute has a missing value default - defined, then return that missing value - default.

    2. + state defined, then return that missing value default + state.

    3. Otherwise, return no state.

    @@ -4618,15 +4618,16 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
  • If the attribute's value is an ASCII case-insensitive match for one of the keywords defined for the attribute, then return the state represented by that keyword.

  • -
  • If the attribute has an invalid value default - defined, then return that invalid value default.

  • +
  • If the attribute has an invalid value default state + defined, then return that invalid value default + state.

  • Return no state.

  • For authoring conformance purposes, if an enumerated attribute is specified, the attribute's - value must be an ASCII case-insensitive match for one of the given keywords that are - not said to be non-conforming, with no leading or trailing whitespace.

    + value must be an ASCII case-insensitive match for one of the conforming keywords for + that attribute, with no leading or trailing whitespace.

    For reflection purposes, states which have any keywords mapping to them are said to have a canonical keyword. This is determined as follows:

    From be10a81827d3ca85d0b7700f3c4a66ea8787b346 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Mon, 6 Jun 2022 15:53:08 -0400 Subject: [PATCH 4/6] DOMString? always limited to only known values --- source | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/source b/source index f8dfc0613d5..dfd4b798706 100644 --- a/source +++ b/source @@ -7454,6 +7454,12 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute if the content attribute's value is the empty string; and on setting, if the content attribute is not present, it must first be added.

    +

    IDL attributes of type DOMString or DOMString? that reflect enumerated content attributes can be limited to only known values. + Per the processing models below, those will cause the getters for such IDL attributes to only + return keywords for those enumerated attributes, or the empty string or null.

    +

    If a reflecting IDL attribute has the type DOMString:

      @@ -7463,7 +7469,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
      1. If the content attribute is an enumerated attribute, and the IDL attribute is - limited to only known values:

        + limited to only known values:

        1. If the content attribute is not in any state (e.g. the attribute is missing and there @@ -7498,6 +7504,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute

          1. Assert: the content attribute is an enumerated attribute.

          2. +
          3. Assert: the IDL attribute is limited to only known values.

          4. +
          5. Assert: the content attribute is in some state.

          6. If the content attribute is in its missing value From cf744a48b3342fe9e771a2bc16ee6f792e04b92b Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Mon, 6 Jun 2022 16:05:23 -0400 Subject: [PATCH 5/6] Be a bit more forward-compatible with popup="" --- source | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/source b/source index dfd4b798706..004fa930171 100644 --- a/source +++ b/source @@ -4598,7 +4598,9 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute

            Multiple keywords can map to the same state.

            -

            The empty string can be a valid keyword.

            +

            The empty string can be a valid keyword. Note that the missing value default applies only when the attribute is missing, not when + it is present with an empty string value.

            To determine the state of an attribute, use the following steps:

            @@ -7508,8 +7510,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
          7. Assert: the content attribute is in some state.

          8. -
          9. If the content attribute is in its missing value - default state, then return null.

          10. +
          11. If the content attribute is in a state with no associated keyword value, then return + null.

          12. Return the canonical keyword for the state of the content attribute.

          13. From da0cf8f8004fcc7d0e4b6dcd2f42ada8f5713db4 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Mon, 6 Jun 2022 16:05:52 -0400 Subject: [PATCH 6/6] Oops --- source | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source b/source index 004fa930171..c3534478373 100644 --- a/source +++ b/source @@ -1398,7 +1398,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
    -
    Errors that waste authoring time
    F +
    Errors that waste authoring time

    Some constructs are disallowed because historically they have been the cause of a lot of