Skip to content

Commit e47a15c

Browse files
committed
Add patchUnsafe() methods
Depends on w3c/trusted-types#597 for Trusted Types integration.
1 parent ad28192 commit e47a15c

File tree

1 file changed

+77
-2
lines changed

1 file changed

+77
-2
lines changed

source

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123478,7 +123478,7 @@ document.body.appendChild(frame)</code></pre>
123478123478

123479123479
<h3 id="dom-parsing-and-serialization">DOM parsing and serialization APIs</h3>
123480123480

123481-
<pre><code class="idl">partial interface <span id="Element-partial">Element</span> {
123481+
<pre><code class="idl">partial interface <span>Element</span> {
123482123482
[<span>CEReactions</span>] undefined <span data-x="dom-Element-setHTMLUnsafe">setHTMLUnsafe</span>((<code data-x="tt-trustedhtml">TrustedHTML</code> or DOMString) html);
123483123483
DOMString <span data-x="dom-Element-getHTML">getHTML</span>(optional <span>GetHTMLOptions</span> options = {});
123484123484

@@ -123487,7 +123487,7 @@ document.body.appendChild(frame)</code></pre>
123487123487
[<span>CEReactions</span>] undefined <span data-x="dom-Element-insertAdjacentHTML">insertAdjacentHTML</span>(DOMString position, (<code data-x="tt-trustedhtml">TrustedHTML</code> or DOMString) string);
123488123488
};
123489123489

123490-
partial interface <span id="ShadowRoot-partial">ShadowRoot</span> {
123490+
partial interface <span>ShadowRoot</span> {
123491123491
[<span>CEReactions</span>] undefined <span data-x="dom-ShadowRoot-setHTMLUnsafe">setHTMLUnsafe</span>((<code data-x="tt-trustedhtml">TrustedHTML</code> or DOMString) html);
123492123492
DOMString <span data-x="dom-ShadowRoot-getHTML">getHTML</span>(optional <span>GetHTMLOptions</span> options = {});
123493123493

@@ -124357,6 +124357,81 @@ interface <dfn interface>XMLSerializer</dfn> {
124357124357

124358124358
</div>
124359124359

124360+
<h3 split-filename="patching" id="patching">Patching</h3>
124361+
124362+
<p>TODO: introduction, what's all this?</p>
124363+
124364+
<pre><code class="idl">partial interface <span>Element</span> {
124365+
WritableStream <span data-x="dom-Element-patchUnsafe">patchUnsafe</span>(optional PatchUnsafeOptions options = {});
124366+
};
124367+
124368+
partial interface <span>ShadowRoot</span> {
124369+
WritableStream <span data-x="dom-ShadowRoot-patchUnsafe">patchUnsafe</span>(optional PatchUnsafeOptions options = {});
124370+
};
124371+
124372+
dictionary <dfn dictionary>PatchUnsafeOptions</dfn> {
124373+
TrustedTransformStream <dfn dict-member for="PatchUnsafeOptions" data-x="dom-PatchUnsafeOptions-trustedTransformStream">trustedTransformStream</dfn>;
124374+
};</code></pre>
124375+
124376+
<div w-nodev>
124377+
124378+
<p><code>Element</code>'s <dfn method for="Element"><code
124379+
data-x="dom-Element-patchUnsafe">patchUnsafe(<var>options</var>)</code></dfn> method steps
124380+
are:</p>
124381+
124382+
<ol>
124383+
<li><p>Let <var>writable</var> be a new WritableStream.</p></li>
124384+
124385+
<li>
124386+
<p>If <var>options</var>["<code data-x="dom-PatchUnsafeOptions-trustedTransformStream">trustedTransformStream</code>"] <span data-x="map exists">exists</span>:</p>
124387+
124388+
<ol>
124389+
<li><p>Set <var>writable</var> to the result of piping <var>writable</var> through <var>options</var>["trustedTransformStream"].</p></li>
124390+
</ol>
124391+
</li>
124392+
124393+
<li>
124394+
<p>Otherwise:</p>
124395+
124396+
<ol>
124397+
<li><p>If there's a default TT policy, use that and wrap <var>writable</var> 👋</p></li>
124398+
</ol>
124399+
</li>
124400+
124401+
<li><p>Create a new parser and do all the actual work 👋</p></li>
124402+
124403+
<li><p>Return <var>writable</var>.</p></li>
124404+
</ol>
124405+
124406+
<div class="example">
124407+
<p>Do a thing like this:</p>
124408+
<pre><code class="js">const policy = trustedTypes.createPolicy("my-policy", {
124409+
createTransformStream() {
124410+
return new TransformStream({
124411+
transform(chunk, controller) {
124412+
// TODO: some buffering
124413+
controller.enqueue(sanitize(chunk));
124414+
}
124415+
});
124416+
}
124417+
});
124418+
124419+
const trustedTransformStream = policy.createTransformStream(input);
124420+
const writable = element.patchUnsafe({ trustedTransformStream });
124421+
const response = await fetch('/fragments/something');
124422+
response.body.pipeTo(writable);</code></pre>
124423+
</div>
124424+
124425+
<p><code>ShadowRoot</code>'s <dfn method for="ShadowRoot"><code
124426+
data-x="dom-ShadowRoot-patchUnsafe">patchUnsafe(<var>options</var>)</code></dfn> method steps
124427+
are:</p>
124428+
124429+
<ol>
124430+
<li>TODO</li>
124431+
</ol>
124432+
124433+
</div>
124434+
124360124435
<h3 split-filename="timers-and-user-prompts" id="timers">Timers</h3>
124361124436

124362124437
<p>The <code data-x="dom-setTimeout">setTimeout()</code> and <code

0 commit comments

Comments
 (0)