From aa3fe7e2fccf48ba09776b8ec964408171bf86ef Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Thu, 24 Apr 2025 13:32:52 +0100 Subject: [PATCH 01/13] Trusted Types --- dom.bs | 93 +++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 76 insertions(+), 17 deletions(-) diff --git a/dom.bs b/dom.bs index e61c3fc0..50b6ab1e 100644 --- a/dom.bs +++ b/dom.bs @@ -50,9 +50,11 @@ spec:html; type:element

This specification depends on the Infra Standard. [[!INFRA]]

Some of the terms used in this specification are defined in Encoding, -Selectors, Web IDL, XML, and Namespaces in XML. +Selectors, Trusted Types, Web IDL, XML, and +Namespaces in XML. [[!ENCODING]] [[!SELECTORS4]] +[[!TRUSTED-TYPES]] [[!WEBIDL]] [[!XML]] [[!XML-NAMES]] @@ -6633,8 +6635,8 @@ interface Element : Node { sequence<DOMString> getAttributeNames(); DOMString? getAttribute(DOMString qualifiedName); DOMString? getAttributeNS(DOMString? namespace, DOMString localName); - [CEReactions] undefined setAttribute(DOMString qualifiedName, DOMString value); - [CEReactions] undefined setAttributeNS(DOMString? namespace, DOMString qualifiedName, DOMString value); + [CEReactions] undefined setAttribute(DOMString qualifiedName, (TrustedType or DOMString) value); + [CEReactions] undefined setAttributeNS(DOMString? namespace, DOMString qualifiedName, (TrustedType or DOMString) value); [CEReactions] undefined removeAttribute(DOMString qualifiedName); [CEReactions] undefined removeAttributeNS(DOMString? namespace, DOMString localName); [CEReactions] boolean toggleAttribute(DOMString qualifiedName, optional boolean force); @@ -7063,6 +7065,14 @@ steps: value. +

To verify attribute value given a {{TrustedType}} or string value, an +attribute attribute, and an Element element: + +

    +
  1. Return the result of calling get Trusted Types-compliant attribute value + given attribute, with element, and value. [[!TRUSTED-TYPES]] +

+
@@ -7115,6 +7125,10 @@ string namespace (default null):

attribute attr and an element element:
    +
  1. Let verifiedValue be the result of + verifying an attribute value given attr's + value, attr, and element. +

  2. If attr's element is neither null nor element, throw an "{{InUseAttributeError!!exception}}" {{DOMException}}. @@ -7130,6 +7144,8 @@ string namespace (default null):

  3. Otherwise, append attr to element. +

  4. Set attr's value to verifiedValue. +

  5. Return oldAttr.

@@ -7141,18 +7157,32 @@ an optional null or string prefix (default null), and an optional nul namespace (default null):
    -
  1. Let attribute be the result of +
  2. Let attribute be the result of getting an attribute given namespace, localName, and element. -

  3. If attribute is null, create an attribute whose namespace is - namespace, namespace prefix is prefix, - local name is localName, value is value, and - node document is element's node document, then - append this attribute to element, and then - return. +
  4. If attribute is null, then set attribute to an attribute whose + namespace is namespace, namespace prefix is + prefix, local name is localName, value is + value, and node document is element's + node document. + +

  5. Let verifiedValue be the result of + verifying an attribute value given value, + attribute, and element. -

  6. Change attribute to value. +

  7. Set attribute to the result of + getting an attribute given + namespace, localName, and element. + +

  8. If attribute is null, create an attribute whose namespace + is namespace, namespace prefix is prefix, + local name is localName, value is + verifiedValue, and node document is element's + node document, then append this attribute to + element, and then return. + +

  9. Change attribute to verifiedValue.

@@ -7417,14 +7447,26 @@ method steps are:
  • Let attribute be the first attribute in this's attribute list whose qualified name is qualifiedName, and null otherwise. - + +

  • If attribute is null, then set attribute to an attribute + whose local name is qualifiedName, value is + value, and node document is this's node document. + +

  • Let verifiedValue be the result of + verifying an attribute value given value, + attribute, and this. + +

  • Set attribute to the first attribute in this's + attribute list whose qualified name is qualifiedName, + and null otherwise.

  • If attribute is null, create an attribute whose local name is qualifiedName, value is - value, and node document is this's node document, - then append this attribute to this, and then return. + verifiedValue, and node document is this's + node document, then append this attribute + to this, and then return. -

  • Change attribute to value. +

  • Change attribute to verifiedValue.

    The @@ -7437,7 +7479,7 @@ method steps are: qualifiedName given "element".

  • Set an attribute value for this using localName, value, - and also prefix and namespace. + prefix, namespace and true.

    The @@ -8028,7 +8070,24 @@ string value, run these steps:

  • If attribute's element is null, then set attribute's value to value. -

  • Otherwise, change attribute to value. +

  • +

    Otherwise: + +

      +
    1. Let originalElement be attribute's element. + +

    2. Let verifiedValue be the result of + verifying an attribute value given value, + attribute, and this. + +

    3. If attribute's element is null, then set attribute's + value to verifiedValue, and return. + +

    4. If attribute's element is not originalElement, then + return. + +

    5. Change attribute to verifiedValue. +

    The {{Attr/value}} setter steps are to set an existing attribute value with this From 526f42291faaf40b127e5e8541305fbff68a44e3 Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Thu, 24 Apr 2025 13:42:02 +0100 Subject: [PATCH 02/13] Revert change to "set an attribute value" --- dom.bs | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/dom.bs b/dom.bs index 50b6ab1e..e03c9f0d 100644 --- a/dom.bs +++ b/dom.bs @@ -7157,32 +7157,18 @@ an optional null or string prefix (default null), and an optional nul namespace (default null):

      -
    1. Let attribute be the result of +

    2. Let attribute be the result of getting an attribute given namespace, localName, and element. -
    3. If attribute is null, then set attribute to an attribute whose - namespace is namespace, namespace prefix is - prefix, local name is localName, value is - value, and node document is element's - node document. - -

    4. Let verifiedValue be the result of - verifying an attribute value given value, - attribute, and element. - -

    5. Set attribute to the result of - getting an attribute given - namespace, localName, and element. - -

    6. If attribute is null, create an attribute whose namespace - is namespace, namespace prefix is prefix, - local name is localName, value is - verifiedValue, and node document is element's - node document, then append this attribute to - element, and then return. +

    7. If attribute is null, create an attribute whose namespace is + namespace, namespace prefix is prefix, + local name is localName, value is value, and + node document is element's node document, then + append this attribute to element, and then + return. -
    8. Change attribute to verifiedValue. +

    9. Change attribute to value.

    From 00d0eaadffaf32ad98076893dc3c6d2a52541181 Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Thu, 24 Apr 2025 14:11:53 +0100 Subject: [PATCH 03/13] Update setAttributeNS to include TT check --- dom.bs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/dom.bs b/dom.bs index e03c9f0d..bccae19c 100644 --- a/dom.bs +++ b/dom.bs @@ -7464,8 +7464,32 @@ method steps are: [=validate and extract|validating and extracting=] namespace and qualifiedName given "element". -
  • Set an attribute value for this using localName, value, - prefix, namespace and true. +

  • Let attribute be the result of + getting an attribute given + namespace, localName, and element. + +

  • If attribute is null, then set attribute to an attribute whose + namespace is namespace, namespace prefix is + prefix, local name is localName, value is + value, and node document is element's + node document. + +

  • Let verifiedValue be the result of + verifying an attribute value given value, + attribute, and element. + +

  • Set attribute to the result of + getting an attribute given + namespace, localName, and element. + +

  • If attribute is null, create an attribute whose namespace + is namespace, namespace prefix is prefix, + local name is localName, value is + verifiedValue, and node document is element's + node document, then append this attribute to + element, and then return. + +

  • Change attribute to verifiedValue.

    The From f5e3984bb8a536ac64e5dcee92ace1210952eda0 Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Wed, 25 Jun 2025 15:19:13 +0100 Subject: [PATCH 04/13] Remove extra algorithm that called through to TT and call TT directly from the various algorithms, also update call signature to match changes in TT. --- dom.bs | 56 ++++++++++++++++---------------------------------------- 1 file changed, 16 insertions(+), 40 deletions(-) diff --git a/dom.bs b/dom.bs index bccae19c..9ad411ec 100644 --- a/dom.bs +++ b/dom.bs @@ -7065,14 +7065,6 @@ steps: value. -

    To verify attribute value given a {{TrustedType}} or string value, an -attribute attribute, and an Element element: - -

      -
    1. Return the result of calling get Trusted Types-compliant attribute value - given attribute, with element, and value. [[!TRUSTED-TYPES]] -

    -
    @@ -7125,9 +7117,10 @@ string namespace (default null):

    attribute attr and an element element:
      -
    1. Let verifiedValue be the result of - verifying an attribute value given attr's - value, attr, and element. +

    2. Let verifiedValue be the result of calling get + Trusted Types-compliant attribute value with attr's local name, + attr's namespace, element, and attr's + value. [[!TRUSTED-TYPES]]

    3. If attr's element is neither null nor element, throw an "{{InUseAttributeError!!exception}}" {{DOMException}}. @@ -7430,19 +7423,11 @@ method steps are: HTML document, then set qualifiedName to qualifiedName in ASCII lowercase. -

    4. Let attribute be the first attribute in this's - attribute list whose qualified name is qualifiedName, - and null otherwise. - -

    5. If attribute is null, then set attribute to an attribute - whose local name is qualifiedName, value is - value, and node document is this's node document. - -

    6. Let verifiedValue be the result of - verifying an attribute value given value, - attribute, and this. +

    7. Let verifiedValue be the result of calling get + Trusted Types-compliant attribute value with qualifiedName, null, this, and + value. [[!TRUSTED-TYPES]] -

    8. Set attribute to the first attribute in this's +

    9. Let attribute be the first attribute in this's attribute list whose qualified name is qualifiedName, and null otherwise. @@ -7464,21 +7449,11 @@ method steps are: [=validate and extract|validating and extracting=] namespace and qualifiedName given "element". -

    10. Let attribute be the result of - getting an attribute given - namespace, localName, and element. - -

    11. If attribute is null, then set attribute to an attribute whose - namespace is namespace, namespace prefix is - prefix, local name is localName, value is - value, and node document is element's - node document. - -

    12. Let verifiedValue be the result of - verifying an attribute value given value, - attribute, and element. +

    13. Let verifiedValue be the result of calling get + Trusted Types-compliant attribute value with localName, namespace, + element, and value. [[!TRUSTED-TYPES]] -

    14. Set attribute to the result of +

    15. Let attribute be the result of getting an attribute given namespace, localName, and element. @@ -8086,9 +8061,10 @@ string value, run these steps:

      1. Let originalElement be attribute's element. -

      2. Let verifiedValue be the result of - verifying an attribute value given value, - attribute, and this. +

      3. Let verifiedValue be the result of calling get + Trusted Types-compliant attribute value with attribute's + local name, attribute's namespace, this, + and value. [[!TRUSTED-TYPES]]

      4. If attribute's element is null, then set attribute's value to verifiedValue, and return. From df2bccd1f43d361c262620d26e5b496adf29f30c Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Thu, 3 Jul 2025 10:02:09 +0100 Subject: [PATCH 05/13] Revert larger change to setAttributeNs as its no longer neccessary. --- dom.bs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/dom.bs b/dom.bs index 9ad411ec..40691488 100644 --- a/dom.bs +++ b/dom.bs @@ -7453,18 +7453,8 @@ method steps are: Trusted Types-compliant attribute value with localName, namespace, element, and value. [[!TRUSTED-TYPES]] -

      5. Let attribute be the result of - getting an attribute given - namespace, localName, and element. - -

      6. If attribute is null, create an attribute whose namespace - is namespace, namespace prefix is prefix, - local name is localName, value is - verifiedValue, and node document is element's - node document, then append this attribute to - element, and then return. - -

      7. Change attribute to verifiedValue. +

      8. Set an attribute value for this using localName, + verifiedValue, and also prefix and namespace.

      The From eb1b5463767bcc0ac5d7317e56cea531dbad3e7a Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Thu, 3 Jul 2025 13:34:36 +0100 Subject: [PATCH 06/13] Set attr's value to verifiedValue before attribute change steps are fired. --- dom.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dom.bs b/dom.bs index 40691488..9418efde 100644 --- a/dom.bs +++ b/dom.bs @@ -7132,13 +7132,13 @@ string namespace (default null):

    16. If oldAttr is attr, return attr. +

    17. Set attr's value to verifiedValue. +

    18. If oldAttr is non-null, then replace oldAttr with attr.

    19. Otherwise, append attr to element. -

    20. Set attr's value to verifiedValue. -

    21. Return oldAttr.

    From 1e3cef84935091e44985cb3d34d138cda1b98959 Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Tue, 30 Sep 2025 21:13:03 +0100 Subject: [PATCH 07/13] Replace this with originalElement inside set an existing attribute value --- dom.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dom.bs b/dom.bs index 9418efde..4f300a1e 100644 --- a/dom.bs +++ b/dom.bs @@ -8053,8 +8053,8 @@ string value, run these steps:
  • Let verifiedValue be the result of calling get Trusted Types-compliant attribute value with attribute's - local name, attribute's namespace, this, - and value. [[!TRUSTED-TYPES]] + local name, attribute's namespace, + originalElement, and value. [[!TRUSTED-TYPES]]

  • If attribute's element is null, then set attribute's value to verifiedValue, and return. From 6fe40a326ffbd63890a5422f2c38faf63978f64c Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Tue, 30 Sep 2025 21:46:04 +0100 Subject: [PATCH 08/13] Rename originalElement to just element --- dom.bs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dom.bs b/dom.bs index 4f300a1e..b5f167fe 100644 --- a/dom.bs +++ b/dom.bs @@ -8049,17 +8049,17 @@ string value, run these steps:

    Otherwise:

      -
    1. Let originalElement be attribute's element. +

    2. Let element be attribute's element.

    3. Let verifiedValue be the result of calling get Trusted Types-compliant attribute value with attribute's local name, attribute's namespace, - originalElement, and value. [[!TRUSTED-TYPES]] + element, and value. [[!TRUSTED-TYPES]]

    4. If attribute's element is null, then set attribute's value to verifiedValue, and return. -

    5. If attribute's element is not originalElement, then +

    6. If attribute's element is not element, then return.

    7. Change attribute to verifiedValue. From 78773d9f5fe2094a84c161ca93c67808c74372db Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Tue, 28 Oct 2025 13:42:39 +0000 Subject: [PATCH 09/13] Swap element for this in setAttributeNs --- dom.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dom.bs b/dom.bs index b5f167fe..d3db9875 100644 --- a/dom.bs +++ b/dom.bs @@ -7451,7 +7451,7 @@ method steps are:

    8. Let verifiedValue be the result of calling get Trusted Types-compliant attribute value with localName, namespace, - element, and value. [[!TRUSTED-TYPES]] + this, and value. [[!TRUSTED-TYPES]]

    9. Set an attribute value for this using localName, verifiedValue, and also prefix and namespace. From f3148ed7db9b86d79c96ae0557c17d633bf897fc Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Tue, 28 Oct 2025 14:02:01 +0000 Subject: [PATCH 10/13] Drop abstract-op and fix associated formatting --- dom.bs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/dom.bs b/dom.bs index d3db9875..75167c67 100644 --- a/dom.bs +++ b/dom.bs @@ -7117,10 +7117,10 @@ string namespace (default null):

      attribute attr and an element element:
        -
      1. Let verifiedValue be the result of calling get - Trusted Types-compliant attribute value with attr's local name, - attr's namespace, element, and attr's - value. [[!TRUSTED-TYPES]] +

      2. Let verifiedValue be the result of calling + get Trusted Types-compliant attribute value with attr's + local name, attr's namespace, element, and + attr's value. [[!TRUSTED-TYPES]]

      3. If attr's element is neither null nor element, throw an "{{InUseAttributeError!!exception}}" {{DOMException}}. @@ -7423,9 +7423,9 @@ method steps are: HTML document, then set qualifiedName to qualifiedName in ASCII lowercase. -

      4. Let verifiedValue be the result of calling get - Trusted Types-compliant attribute value with qualifiedName, null, this, and - value. [[!TRUSTED-TYPES]] +

      5. Let verifiedValue be the result of calling + get Trusted Types-compliant attribute value with qualifiedName, null, + this, and value. [[!TRUSTED-TYPES]]

      6. Let attribute be the first attribute in this's attribute list whose qualified name is qualifiedName, @@ -7449,8 +7449,8 @@ method steps are: [=validate and extract|validating and extracting=] namespace and qualifiedName given "element". -

      7. Let verifiedValue be the result of calling get - Trusted Types-compliant attribute value with localName, namespace, +

      8. Let verifiedValue be the result of calling + get Trusted Types-compliant attribute value with localName, namespace, this, and value. [[!TRUSTED-TYPES]]

      9. Set an attribute value for this using localName, @@ -8051,8 +8051,8 @@ string value, run these steps:

        1. Let element be attribute's element. -

        2. Let verifiedValue be the result of calling get - Trusted Types-compliant attribute value with attribute's +

        3. Let verifiedValue be the result of calling + get Trusted Types-compliant attribute value with attribute's local name, attribute's namespace, element, and value. [[!TRUSTED-TYPES]] From 383d39c3586f8ec4963d69a1c43eff52ac271e28 Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Tue, 28 Oct 2025 15:38:12 +0000 Subject: [PATCH 11/13] Rename tt algorithm --- dom.bs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dom.bs b/dom.bs index 75167c67..ae4fe588 100644 --- a/dom.bs +++ b/dom.bs @@ -7118,7 +7118,7 @@ string namespace (default null):

          1. Let verifiedValue be the result of calling - get Trusted Types-compliant attribute value with attr's + get trusted type compliant attribute value with attr's local name, attr's namespace, element, and attr's value. [[!TRUSTED-TYPES]] @@ -7424,7 +7424,7 @@ method steps are: ASCII lowercase.

          2. Let verifiedValue be the result of calling - get Trusted Types-compliant attribute value with qualifiedName, null, + get trusted type compliant attribute value with qualifiedName, null, this, and value. [[!TRUSTED-TYPES]]

          3. Let attribute be the first attribute in this's @@ -7450,7 +7450,7 @@ method steps are: qualifiedName given "element".

          4. Let verifiedValue be the result of calling - get Trusted Types-compliant attribute value with localName, namespace, + get trusted type compliant attribute value with localName, namespace, this, and value. [[!TRUSTED-TYPES]]

          5. Set an attribute value for this using localName, @@ -8052,7 +8052,7 @@ string value, run these steps:

          6. Let element be attribute's element.

          7. Let verifiedValue be the result of calling - get Trusted Types-compliant attribute value with attribute's + get trusted type compliant attribute value with attribute's local name, attribute's namespace, element, and value. [[!TRUSTED-TYPES]] From 2075acd382315d1a676eb1189d63c2945019ab9c Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Thu, 30 Oct 2025 13:03:23 +0000 Subject: [PATCH 12/13] Remove early return when setting an existing attribute value and the attribute moves elements during the TT callback --- dom.bs | 3 --- 1 file changed, 3 deletions(-) diff --git a/dom.bs b/dom.bs index ae4fe588..bfd0ce5a 100644 --- a/dom.bs +++ b/dom.bs @@ -8059,9 +8059,6 @@ string value, run these steps:

          8. If attribute's element is null, then set attribute's value to verifiedValue, and return. -

          9. If attribute's element is not element, then - return. -

          10. Change attribute to verifiedValue.

        From 1ff8aaa8e3bfc54b7de25d749000705f12d20853 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Thu, 30 Oct 2025 18:00:57 +0100 Subject: [PATCH 13/13] modernize some of the old prose and lean on early returns --- dom.bs | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/dom.bs b/dom.bs index bfd0ce5a..91f00454 100644 --- a/dom.bs +++ b/dom.bs @@ -7424,20 +7424,21 @@ method steps are: ASCII lowercase.
      10. Let verifiedValue be the result of calling - get trusted type compliant attribute value with qualifiedName, null, - this, and value. [[!TRUSTED-TYPES]] + get trusted type compliant attribute value with qualifiedName, null, this, + and value. [[!TRUSTED-TYPES]]

      11. Let attribute be the first attribute in this's attribute list whose qualified name is qualifiedName, and null otherwise. -

      12. If attribute is null, create an attribute whose - local name is qualifiedName, value is - verifiedValue, and node document is this's - node document, then append this attribute - to this, and then return. +

      13. If attribute is non-null, then change + attribute to verifiedValue and return. -

      14. Change attribute to verifiedValue. +

      15. Set attribute to a new attribute whose local name is + qualifiedName, value is verifiedValue, and + node document is this's node document. + +

      16. Append attribute to this.

      The @@ -7454,7 +7455,7 @@ method steps are: this, and value. [[!TRUSTED-TYPES]]

    10. Set an attribute value for this using localName, - verifiedValue, and also prefix and namespace. + verifiedValue, prefix, and namespace.

    The @@ -8043,24 +8044,19 @@ string value, run these steps:

    1. If attribute's element is null, then set attribute's - value to value. + value to value and return. -

    2. -

      Otherwise: +

    3. Let element be attribute's element. -

        -
      1. Let element be attribute's element. - -

      2. Let verifiedValue be the result of calling - get trusted type compliant attribute value with attribute's - local name, attribute's namespace, - element, and value. [[!TRUSTED-TYPES]] +

      3. Let verifiedValue be the result of calling + get trusted type compliant attribute value with attribute's + local name, attribute's namespace, element, + and value. [[!TRUSTED-TYPES]] -

      4. If attribute's element is null, then set attribute's - value to verifiedValue, and return. +

      5. If attribute's element is null, then set attribute's + value to verifiedValue and return. -

      6. Change attribute to verifiedValue. -

      +
    4. Change attribute to verifiedValue.

    The {{Attr/value}} setter steps are to set an existing attribute value with this