Skip to content

Commit

Permalink
Trusted Types integration for "converting nodes into a node"
Browse files Browse the repository at this point in the history
Covered by existing tests.

Co-authored-by: Anne van Kesteren <annevk@annevk.nl>
  • Loading branch information
lukewarlow and annevk committed Apr 18, 2024
1 parent 77cd75e commit 720a4fc
Showing 1 changed file with 49 additions and 21 deletions.
70 changes: 49 additions & 21 deletions dom.bs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ spec:html; type:element
<p>This specification depends on the Infra Standard. [[!INFRA]]

<p>Some of the terms used in this specification are defined in <cite>Encoding</cite>,
<cite>Selectors</cite>, <cite>Web IDL</cite>, <cite>XML</cite>, and <cite>Namespaces in XML</cite>.
<cite>Selectors</cite>, <cite>Trusted Types</cite>, <cite>Web IDL</cite>, <cite>XML</cite>, and
<cite>Namespaces in XML</cite>.
[[!ENCODING]]
[[!SELECTORS4]]
[[!TRUSTED-TYPES]]
[[!WEBIDL]]
[[!XML]]
[[!XML-NAMES]]
Expand Down Expand Up @@ -3033,8 +3035,9 @@ standards that want to define APIs shared between <a for=/>documents</a> and

<h4 id=interface-parentnode>Mixin {{ParentNode}}</h4>

<p>To <dfn export lt="converting nodes into a node">convert nodes into a node</dfn>, given
<var>nodes</var> and <var>document</var>, run these steps:
<p>To <dfn export lt="converting nodes into a node">convert nodes into a node</dfn>, given a
<a for=/>node</a> <var>parent</var>, <a for=/>list</a> of <a for=/>nodes</a> <var>nodes</var>, and
<a for=/>document</a> <var>document</var>:

<ol>
<li><p>Let <var>node</var> be null.
Expand All @@ -3043,12 +3046,37 @@ standards that want to define APIs shared between <a for=/>documents</a> and
<a for=CharacterData>data</a> is the string and <a for=Node>node document</a> is
<var>document</var>.

<li><p>If <var>nodes</var> contains one <a for=/>node</a>, then set <var>node</var> to
<var>nodes</var>[0].
<li><p>Let <var>isScriptElement</var> be true if <var>parent</var> is an {{HTMLScriptElement}}
<a for=/>node</a>; otherwise false.

<li><p>Let <var>newNodes</var> be « ».

<li>
<p><a for=list>For each</a> <var>value</var> of <var>nodes</var>:

<ol>
<li><p>Let <var>newValue</var> be <var>value</var>.

<li><p>If <var>value</var> is a {{Text}} <a for=/>node</a> and <var>isScriptElement</var> is
true, then set <var>newValue</var> to a new {{Text}} <a for=/>node</a> whose
<a for=Node>node document</a> is <var>document</var> and <a for=CharacterData>data</a> is the
result of calling <a abstract-op>Get Trusted Type compliant string</a>, with {{TrustedScript}},
<var>document</var>'s <a>relevant global object</a>, <var>value</var>'s
<a for=CharacterData>data</a>, "<code>HTMLScriptElement text</code>", and "<code>script</code>".

<li><p>If <var>value</var> is a {{TrustedScript}}, then set <var>newValue</var> to a new {{Text}}
<a for=/>node</a> whose <a for=CharacterData>data</a> is <var>value</var>'s
<a for=TrustedScript>data</a> and <a for=Node>node document</a> is <var>document</var>.

<li><p><a for=list>Append</a> <var>newValue</var> to <var>newNodes</var>.
</ol>

<li><p>If <var>newNodes</var> contains one <a for=/>node</a>, then set <var>node</var> to
<var>newNodes</var>[0].

<li><p>Otherwise, set <var>node</var> to a new {{DocumentFragment}} <a for=/>node</a> whose
<a for=Node>node document</a> is <var>document</var>, and then <a>append</a> each <a for=/>node</a>
in <var>nodes</var>, if any, to it.
in <var>newNodes</var>, if any, to it.

<li><p>Return <var>node</var>.
</ol>
Expand All @@ -3060,9 +3088,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 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);
Expand Down Expand Up @@ -3136,8 +3164,8 @@ the number of <a for=tree>children</a> of <a>this</a> that are <a for=/>elements
<p>The <dfn method for=ParentNode><code>prepend(<var>nodes</var>)</code></dfn> method steps are:

<ol>
<li><p>Let <var>node</var> be the result of <a>converting nodes into a node</a> given
<var>nodes</var> and <a>this</a>'s <a for=Node>node document</a>.
<li><p>Let <var>node</var> be the result of <a>converting nodes into a node</a> given <a>this</a>,
<var>nodes</var>, and <a>this</a>'s <a for=Node>node document</a>.

<li><p><a>Pre-insert</a> <var>node</var> into <a>this</a> before <a>this</a>'s
<a for=tree>first child</a>.
Expand All @@ -3146,8 +3174,8 @@ the number of <a for=tree>children</a> of <a>this</a> that are <a for=/>elements
<p>The <dfn method for=ParentNode><code>append(<var>nodes</var>)</code></dfn> method steps are:

<ol>
<li><p>Let <var>node</var> be the result of <a>converting nodes into a node</a> given
<var>nodes</var> and <a>this</a>'s <a for=Node>node document</a>.
<li><p>Let <var>node</var> be the result of <a>converting nodes into a node</a> given <a>this</a>,
<var>nodes</var>, and <a>this</a>'s <a for=Node>node document</a>.

<li><p><a>Append</a> <var>node</var> to <a>this</a>.
</ol>
Expand All @@ -3156,8 +3184,8 @@ the number of <a for=tree>children</a> of <a>this</a> that are <a for=/>elements
are:

<ol>
<li><p>Let <var>node</var> be the result of <a>converting nodes into a node</a> given
<var>nodes</var> and <a>this</a>'s <a for=Node>node document</a>.
<li><p>Let <var>node</var> be the result of <a>converting nodes into a node</a> given <a>this</a>,
<var>nodes</var>, and <a>this</a>'s <a for=Node>node document</a>.

<li><p><a>Ensure pre-insertion validity</a> of <var>node</var> into <a>this</a> before
null.
Expand Down Expand Up @@ -3212,9 +3240,9 @@ steps are to return the first <a>following</a> <a for=tree>sibling</a> that is a

<pre class=idl>
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 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;
Expand Down Expand Up @@ -3262,7 +3290,7 @@ CharacterData includes ChildNode;
<a for=tree>sibling</a> not in <var>nodes</var>; otherwise null.

<li><p>Let <var>node</var> be the result of <a>converting nodes into a node</a>, given
<var>nodes</var> and <a>this</a>'s <a for=Node>node document</a>.
<var>parent</var>, <var>nodes</var>, and <a>this</a>'s <a for=Node>node document</a>.

<li><p>If <var>viablePreviousSibling</var> is null, then set it to <var>parent</var>'s
<a for=tree>first child</a>; otherwise to <var>viablePreviousSibling</var>'s
Expand All @@ -3283,7 +3311,7 @@ CharacterData includes ChildNode;
<a for=tree>sibling</a> not in <var>nodes</var>; otherwise null.

<li><p>Let <var>node</var> be the result of <a>converting nodes into a node</a>, given
<var>nodes</var> and <a>this</a>'s <a for=Node>node document</a>.
<var>parent</var>, <var>nodes</var>, and <a>this</a>'s <a for=Node>node document</a>.

<li><p><a>Pre-insert</a> <var>node</var> into <var>parent</var> before
<var>viableNextSibling</var>.
Expand All @@ -3300,7 +3328,7 @@ CharacterData includes ChildNode;
<a for=tree>sibling</a> not in <var>nodes</var>; otherwise null.

<li><p>Let <var>node</var> be the result of <a>converting nodes into a node</a>, given
<var>nodes</var> and <a>this</a>'s <a for=Node>node document</a>.
<var>parent</var>, <var>nodes</var>, and <a>this</a>'s <a for=Node>node document</a>.

<li>
<p>If <a>this</a>'s <a for=tree>parent</a> is <var>parent</var>, <a>replace</a> <a>this</a> with
Expand Down

0 comments on commit 720a4fc

Please sign in to comment.