From 7d1f88b64bad09ab7993cab07eaf91c0130e3579 Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Thu, 22 Feb 2024 17:44:21 +0000 Subject: [PATCH 01/12] Integration with trusted types inside of node conversion --- dom.bs | 73 ++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/dom.bs b/dom.bs index a0aa0c3d2..09f6dcae9 100644 --- a/dom.bs +++ b/dom.bs @@ -3034,15 +3034,54 @@ standards that want to define APIs shared between documents and

Mixin {{ParentNode}}

To convert nodes into a node, given -nodes and document, run these steps: +parent, nodes and document, run these steps:

    +
  1. Let isScriptElement be parent is a {{HTMLScriptElement}}. +

  2. For each value in nodes: +

      +
    1. If value is a node, then: +
        +
      1. If isScriptElement is false, skip to the next value. +
      2. If value's {{nodeType}} is not {{TEXT_NODE}}, skip to the next value. +
      3. Let text be the result of executing the [$Get Trusted Type compliant string$] algorithm, with the following arguments: + * {{TrustedScript}} as expectedType, + * document's [=relevant global object=] as global, + * value's data as input, + * `HTMLScriptElement text` as sink, + * `script` as sinkGroup. + +

        If the algorithm threw an error, rethrow the error. +

      4. Set value's data to text. +
      +
    2. If value is a string, then: +
        +
      1. Let text be value. +
      2. If isScriptElement is true: +
          +
        1. Let text be the result of executing the [$Get Trusted Type compliant string$] algorithm, with the following arguments: + * {{TrustedScript}} as expectedType, + * document's [=relevant global object=] as global, + * value as input, + * `HTMLScriptElement text` as sink, + * `script` as sinkGroup. + + If the algorithm threw an error, rethrow the error. +
        2. Let newValue be a new {{Text}} node whose + data is text and node document is document. +
        3. Replace value with newValue. +
        +
      +
    3. If value is a {{TrustedScript}}, then: +
        +
      1. Let text be value's Data internal slot value. +
      2. Let newValue be a new {{Text}} node whose + data is text and node document is document. +
      3. Replace value with newValue. +
      +
  3. Let node be null. -

  4. Replace each string in nodes with a new {{Text}} node whose - data is the string and node document is - document. -

  5. If nodes contains one node, then set node to nodes[0]. @@ -3060,9 +3099,9 @@ interface mixin ParentNode { readonly attribute Element? lastElementChild; readonly attribute unsigned long childElementCount; - [CEReactions, Unscopable] undefined prepend((Node or DOMString)... nodes); - [CEReactions, Unscopable] undefined append((Node or DOMString)... nodes); - [CEReactions, Unscopable] undefined replaceChildren((Node or DOMString)... nodes); + [CEReactions, Unscopable] undefined prepend((Node or DOMString or TrustedScript)... nodes); + [CEReactions, Unscopable] undefined append((Node or DOMString or TrustedScript)... nodes); + [CEReactions, Unscopable] undefined replaceChildren((Node or DOMString or TrustedScript)... nodes); Element? querySelector(DOMString selectors); [NewObject] NodeList querySelectorAll(DOMString selectors); @@ -3136,7 +3175,7 @@ the number of children of this that are elements

    The prepend(nodes) method steps are:

      -
    1. Let node be the result of converting nodes into a node given +

    2. Let node be the result of converting nodes into a node given this, nodes and this's node document.

    3. Pre-insert node into this before this's @@ -3146,7 +3185,7 @@ the number of children of this that are elements

      The append(nodes) method steps are:

        -
      1. Let node be the result of converting nodes into a node given +

      2. Let node be the result of converting nodes into a node given this, nodes and this's node document.

      3. Append node to this. @@ -3156,7 +3195,7 @@ the number of children of this that are elements are:

          -
        1. Let node be the result of converting nodes into a node given +

        2. Let node be the result of converting nodes into a node given this, nodes and this's node document.

        3. Ensure pre-insertion validity of node into this before @@ -3212,9 +3251,9 @@ steps are to return the first following sibling that is a

           interface mixin ChildNode {
          -  [CEReactions, Unscopable] undefined before((Node or DOMString)... nodes);
          -  [CEReactions, Unscopable] undefined after((Node or DOMString)... nodes);
          -  [CEReactions, Unscopable] undefined replaceWith((Node or DOMString)... nodes);
          +  [CEReactions, Unscopable] undefined before((Node or DOMString or TrustedScript)... nodes);
          +  [CEReactions, Unscopable] undefined after((Node or DOMString or TrustedScript)... nodes);
          +  [CEReactions, Unscopable] undefined replaceWith((Node or DOMString or TrustedScript)... nodes);
             [CEReactions, Unscopable] undefined remove();
           };
           DocumentType includes ChildNode;
          @@ -3262,7 +3301,7 @@ CharacterData includes ChildNode;
            sibling not in nodes; otherwise null.
           
            
        4. Let node be the result of converting nodes into a node, given - nodes and this's node document. + parent, nodes and this's node document.

        5. If viablePreviousSibling is null, then set it to parent's first child; otherwise to viablePreviousSibling's @@ -3283,7 +3322,7 @@ CharacterData includes ChildNode; sibling not in nodes; otherwise null.

        6. Let node be the result of converting nodes into a node, given - nodes and this's node document. + parent, nodes and this's node document.

        7. Pre-insert node into parent before viableNextSibling. @@ -3300,7 +3339,7 @@ CharacterData includes ChildNode; sibling not in nodes; otherwise null.

        8. Let node be the result of converting nodes into a node, given - nodes and this's node document. + parent, nodes and this's node document.

        9. If this's parent is parent, replace this with From 103a2d31dcb411fbb77eb3c2b3f88e7e9ba4747c Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Mon, 4 Mar 2024 17:06:34 +0000 Subject: [PATCH 02/12] Address review comments --- dom.bs | 49 +++++++++++++++++++------------------------------ 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/dom.bs b/dom.bs index 09f6dcae9..a4bb145d7 100644 --- a/dom.bs +++ b/dom.bs @@ -3037,41 +3037,31 @@ standards that want to define APIs shared between documents and parent, nodes and document, run these steps:

            +
          1. Let node be null. + +

          2. Replace each string in nodes with a new {{Text}} node whose + data is the string and node document is + document. +

          3. Let isScriptElement be parent is a {{HTMLScriptElement}}. -

          4. For each value in nodes: + +

          5. For each value in nodes:

            1. If value is a node, then:
              1. If isScriptElement is false, skip to the next value. -
              2. If value's {{nodeType}} is not {{TEXT_NODE}}, skip to the next value. -
              3. Let text be the result of executing the [$Get Trusted Type compliant string$] algorithm, with the following arguments: - * {{TrustedScript}} as expectedType, - * document's [=relevant global object=] as global, - * value's data as input, - * `HTMLScriptElement text` as sink, - * `script` as sinkGroup. - -

                If the algorithm threw an error, rethrow the error. -

              4. Set value's data to text. +
              5. If value is not a {{Text}} node, then continue. +
              6. Let text be the result of executing the [$Get Trusted Type compliant string$] algorithm, with the following arguments: + * {{TrustedScript}} as expectedType, + * document's [=relevant global object=] as global, + * value's data as input, + * `HTMLScriptElement text` as sink, + * `script` as sinkGroup. + +

                If the algorithm threw an error, rethrow the error. +

              7. Set value's data to text.
              -
            2. If value is a string, then: -
                -
              1. Let text be value. -
              2. If isScriptElement is true: -
                  -
                1. Let text be the result of executing the [$Get Trusted Type compliant string$] algorithm, with the following arguments: - * {{TrustedScript}} as expectedType, - * document's [=relevant global object=] as global, - * value as input, - * `HTMLScriptElement text` as sink, - * `script` as sinkGroup. - - If the algorithm threw an error, rethrow the error. -
                2. Let newValue be a new {{Text}} node whose - data is text and node document is document. -
                3. Replace value with newValue. -
                -
              +
            3. If value is a {{TrustedScript}}, then:
              1. Let text be value's Data internal slot value. @@ -3080,7 +3070,6 @@ standards that want to define APIs shared between documents and
              2. Replace value with newValue.
            -
          6. Let node be null.

          7. If nodes contains one node, then set node to nodes[0]. From ed51dc91698c480d7d274e7256ecb5d2f3163a0e Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Wed, 13 Mar 2024 15:31:12 +0000 Subject: [PATCH 03/12] Add missing

            --- dom.bs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/dom.bs b/dom.bs index a4bb145d7..3df7a2cef 100644 --- a/dom.bs +++ b/dom.bs @@ -3047,27 +3047,25 @@ standards that want to define APIs shared between documents and

          8. For each value in nodes:

              -
            1. If value is a node, then: +
            2. If value is a node, then:

                -
              1. If isScriptElement is false, skip to the next value. -
              2. If value is not a {{Text}} node, then continue. -
              3. Let text be the result of executing the [$Get Trusted Type compliant string$] algorithm, with the following arguments: +
              4. If isScriptElement is false, then continue. +

              5. If value is not a {{Text}} node, then continue. +

              6. Let text be the result of executing the [$Get Trusted Type compliant string$] algorithm, with the following arguments: * {{TrustedScript}} as expectedType, * document's [=relevant global object=] as global, * value's data as input, * `HTMLScriptElement text` as sink, * `script` as sinkGroup. - -

                If the algorithm threw an error, rethrow the error. -

              7. Set value's data to text. +
              8. Set value's data to text.

              -
            3. If value is a {{TrustedScript}}, then: +
            4. If value is a {{TrustedScript}}, then:

                -
              1. Let text be value's Data internal slot value. -
              2. Let newValue be a new {{Text}} node whose +
              3. Let text be value's Data internal slot value. +

              4. Let newValue be a new {{Text}} node whose data is text and node document is document. -

              5. Replace value with newValue. +
              6. Replace value with newValue.

            From f56969eef30274eedfccd09e581a6354aa1bc1c9 Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Wed, 13 Mar 2024 16:38:02 +0000 Subject: [PATCH 04/12] Change syntax for calling algorithm and linkify data slot reference --- dom.bs | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/dom.bs b/dom.bs index 3df7a2cef..0d433a734 100644 --- a/dom.bs +++ b/dom.bs @@ -37,6 +37,8 @@ urlPrefix: https://w3c.github.io/hr-time/#; spec: HR-TIME type:typedef; urlPrefix: dom-; text: DOMHighResTimeStamp type:dfn; text: current high resolution time; url: dfn-current-high-resolution-time type:dfn; text: relative high resolution coarse time; url: dfn-relative-high-resolution-coarse-time +urlPrefix: https://w3c.github.io/trusted-types/dist/spec/#; spec: TRUSTED-TYPES + type:dfn; text: [[Data]]; for: TrustedScript; url: trustedscript-data
      4. If nodes contains one node, then set node to From 0c13ee94e582761709bdec7c2fc2236f39486ea7 Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Tue, 16 Apr 2024 11:38:23 +0100 Subject: [PATCH 07/12] address some comments --- dom.bs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/dom.bs b/dom.bs index 51cac16f2..73601603c 100644 --- a/dom.bs +++ b/dom.bs @@ -3053,18 +3053,14 @@ standards that want to define APIs shared between documents and

        1. -

          If value is a node, then: - -

            -
          1. If value is a {{Text}} node, and isScriptElement - is false, then set value's data to text the - result of calling Get Trusted Type compliant string, with {{TrustedScript}}, - document's relevant global object, value's - data, "HTMLScriptElement text", and "script". -

          +

          If value is a {{Text}} node, and isScriptElement + is true, then set value's data to text the + result of calling Get Trusted Type compliant string, with {{TrustedScript}}, + document's relevant global object, value's + data, "HTMLScriptElement text", and "script".

        2. -

          If value is a {{TrustedScript}}, then: +

          Otherwise, if value is a {{TrustedScript}}:

          1. Let text be value's \[[Data]] From d6db0aab6965d00effb0722fac89173056ce2184 Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Tue, 16 Apr 2024 11:56:53 +0100 Subject: [PATCH 08/12] Change to using a new list rather than changing the list being iterated. --- dom.bs | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/dom.bs b/dom.bs index 73601603c..7ecbaca6a 100644 --- a/dom.bs +++ b/dom.bs @@ -3048,38 +3048,46 @@ standards that want to define APIs shared between documents and

          2. Let isScriptElement be true if parent is an {{HTMLScriptElement}} node; otherwise false. +

          3. Let newNodes be the empty list. +

          4. -

            For each value of nodes: +

            For each value of nodes:

            1. If value is a {{Text}} node, and isScriptElement - is true, then set value's data to text the - result of calling Get Trusted Type compliant string, with {{TrustedScript}}, - document's relevant global object, value's - data, "HTMLScriptElement text", and "script". + is true: + +

                +
              1. Let newValue be a new {{Text}} node whose + node document is document and data is the + result of calling Get Trusted Type compliant string, with {{TrustedScript}}, + document's relevant global object, value's data, "HTMLScriptElement text", and "script". + +

              2. Append newValue to newNodes. +

            2. Otherwise, if value is a {{TrustedScript}}:

                -
              1. Let text be value's \[[Data]] - internal slot value. -

              2. Let newValue be a new {{Text}} node whose - data is text and node document is - document. + data is value's \[[Data]] + internal slot value and node document is document. -

              3. Replace value with newValue. +

              4. Append newValue to newNodes.

              + +
            3. Otherwise, append value to newNodes.

            -
          5. If nodes contains one node, then set node to - nodes[0]. +

          6. If newNodes contains one node, then set node to + newNodes[0].

          7. Otherwise, set node to a new {{DocumentFragment}} node whose node document is document, and then append each node - in nodes, if any, to it. + in newNodes, if any, to it.

          8. Return node.

          From 1b8e47f022cee71b6ff12b02395db01a2e93428a Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Wed, 17 Apr 2024 11:14:06 +0100 Subject: [PATCH 09/12] Address comments --- dom.bs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dom.bs b/dom.bs index 7ecbaca6a..ff6e2f20e 100644 --- a/dom.bs +++ b/dom.bs @@ -3048,14 +3048,14 @@ standards that want to define APIs shared between documents and
        3. Let isScriptElement be true if parent is an {{HTMLScriptElement}} node; otherwise false. -

        4. Let newNodes be the empty list. +

        5. Let newNodes be « ».

        6. For each value of nodes:

          1. -

            If value is a {{Text}} node, and isScriptElement +

            If value is a {{Text}} node and isScriptElement is true:

              @@ -3073,14 +3073,14 @@ standards that want to define APIs shared between documents and
              1. Let newValue be a new {{Text}} node whose - data is value's \[[Data]] - internal slot value and node document is document. + data is value's data + and node document is document.

              2. Append newValue to newNodes.

            1. Otherwise, append value to newNodes. -

            +
        7. If newNodes contains one node, then set node to newNodes[0]. From a085e1e27d69b4f1f4518cc32d9db7264c33d104 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Thu, 18 Apr 2024 15:56:33 +0200 Subject: [PATCH 10/12] final nits --- dom.bs | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/dom.bs b/dom.bs index ff6e2f20e..00badcffb 100644 --- a/dom.bs +++ b/dom.bs @@ -3035,8 +3035,9 @@ standards that want to define APIs shared between documents and

          Mixin {{ParentNode}}

          -

          To convert nodes into a node, given -parent, nodes and document, run these steps: +

          To convert nodes into a node, given a +node parent, list of nodes nodes, and +document document:

          1. Let node be null. @@ -3054,32 +3055,20 @@ standards that want to define APIs shared between documents and

            For each value of nodes:

              -
            1. -

              If value is a {{Text}} node and isScriptElement - is true: +

            2. Let newValue be value. -

                -
              1. Let newValue be a new {{Text}} node whose - node document is document and data is the - result of calling Get Trusted Type compliant string, with {{TrustedScript}}, - document's relevant global object, value's data, "HTMLScriptElement text", and "script". +

              2. If value is a {{Text}} node and isScriptElement is + true, then set newValue to a new {{Text}} node whose + node document is document and data is the + result of calling Get Trusted Type compliant string, with {{TrustedScript}}, + document's relevant global object, value's + data, "HTMLScriptElement text", and "script". -

              3. Append newValue to newNodes. -

              - -
            3. -

              Otherwise, if value is a {{TrustedScript}}: - -

                -
              1. Let newValue be a new {{Text}} node whose - data is value's data - and node document is document. - -

              2. Append newValue to newNodes. -

              +
            4. If value is a {{TrustedScript}}, then set newValue to a new {{Text}} + node whose data is value's + data and node document is document. -

            5. Otherwise, append value to newNodes. +

            6. Append newValue to newNodes.

          2. If newNodes contains one node, then set node to From ba733eee54befdc3ba5574f3f2a06afb89212f44 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Thu, 18 Apr 2024 16:04:03 +0200 Subject: [PATCH 11/12] keep DOMString last --- dom.bs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dom.bs b/dom.bs index 00badcffb..5ddfcc24d 100644 --- a/dom.bs +++ b/dom.bs @@ -3088,9 +3088,9 @@ interface mixin ParentNode { readonly attribute Element? lastElementChild; readonly attribute unsigned long childElementCount; - [CEReactions, Unscopable] undefined prepend((Node or DOMString or TrustedScript)... nodes); - [CEReactions, Unscopable] undefined append((Node or DOMString or TrustedScript)... nodes); - [CEReactions, Unscopable] undefined replaceChildren((Node or DOMString or TrustedScript)... nodes); + [CEReactions, Unscopable] undefined prepend((Node or TrustedScript or DOMString)... nodes); + [CEReactions, Unscopable] undefined append((Node or TrustedScript or DOMString)... nodes); + [CEReactions, Unscopable] undefined replaceChildren((Node or TrustedScript or DOMString)... nodes); Element? querySelector(DOMString selectors); [NewObject] NodeList querySelectorAll(DOMString selectors); @@ -3240,9 +3240,9 @@ steps are to return the first following sibling that is a

             interface mixin ChildNode {
            -  [CEReactions, Unscopable] undefined before((Node or DOMString or TrustedScript)... nodes);
            -  [CEReactions, Unscopable] undefined after((Node or DOMString or TrustedScript)... nodes);
            -  [CEReactions, Unscopable] undefined replaceWith((Node or DOMString or TrustedScript)... nodes);
            +  [CEReactions, Unscopable] undefined before((Node or TrustedScript or DOMString)... nodes);
            +  [CEReactions, Unscopable] undefined after((Node or TrustedScript or DOMString)... nodes);
            +  [CEReactions, Unscopable] undefined replaceWith((Node or TrustedScript or DOMString)... nodes);
               [CEReactions, Unscopable] undefined remove();
             };
             DocumentType includes ChildNode;
            
            From 6b615a7ddc7e116e152abb756bc0050db5b7ef62 Mon Sep 17 00:00:00 2001
            From: Anne van Kesteren 
            Date: Thu, 18 Apr 2024 16:14:34 +0200
            Subject: [PATCH 12/12] Oxford
            
            ---
             dom.bs | 12 ++++++------
             1 file changed, 6 insertions(+), 6 deletions(-)
            
            diff --git a/dom.bs b/dom.bs
            index 5ddfcc24d..f472a3b3c 100644
            --- a/dom.bs
            +++ b/dom.bs
            @@ -3165,7 +3165,7 @@ the number of children of this that are elements
             
             
            1. Let node be the result of converting nodes into a node given this, - nodes and this's node document. + nodes, and this's node document.

            2. Pre-insert node into this before this's first child. @@ -3175,7 +3175,7 @@ the number of children of this that are elements

              1. Let node be the result of converting nodes into a node given this, - nodes and this's node document. + nodes, and this's node document.

              2. Append node to this.

              @@ -3185,7 +3185,7 @@ are:
              1. Let node be the result of converting nodes into a node given this, - nodes and this's node document. + nodes, and this's node document.

              2. Ensure pre-insertion validity of node into this before null. @@ -3290,7 +3290,7 @@ CharacterData includes ChildNode; sibling not in nodes; otherwise null.

              3. Let node be the result of converting nodes into a node, given - parent, nodes and this's node document. + parent, nodes, and this's node document.

              4. If viablePreviousSibling is null, then set it to parent's first child; otherwise to viablePreviousSibling's @@ -3311,7 +3311,7 @@ CharacterData includes ChildNode; sibling not in nodes; otherwise null.

              5. Let node be the result of converting nodes into a node, given - parent, nodes and this's node document. + parent, nodes, and this's node document.

              6. Pre-insert node into parent before viableNextSibling. @@ -3328,7 +3328,7 @@ CharacterData includes ChildNode; sibling not in nodes; otherwise null.

              7. Let node be the result of converting nodes into a node, given - parent, nodes and this's node document. + parent, nodes, and this's node document.

              8. If this's parent is parent, replace this with