@@ -124392,57 +124392,42 @@ dictionary <dfn dictionary>StreamHTMLUnsafeOptions</dfn> {
124392124392 <li><p>Let <var>writable</var> be a new WritableStream.</p></li>
124393124393
124394124394 <li>
124395- <p>👋 Sketch of the streams setup:</p>
124395+ <p>Let <var>parser</var> be an <span>HTML parser</span> using the <span>HTML fragment parsing
124396+ algorithm</span> given <var>this</var> as <span data-x="concept-frag-parse-context">context</span>
124397+ where the input is delivered in chunks instead of a fixed string.</p>
124396124398
124397- <ol>
124398- <li><p>Incoming chunks must all be of the same type, either strings or a trusted types
124399- wrapper. Check this on every chunk and treat mixing as an error.</p></li>
124399+ <p class="XXX">Refactor the fragment parser algorithm to really support being used in this way,
124400+ either as an object with an algorithm to feed the parser string chunks, or by making the
124401+ argument a readable which the parser reads from.</p>
124402+ </li>
124400124403
124401- <li><p>If the first chunk is not a trusted types wrapper and there is a default TT policy,
124402- create a transform stream using <code data-x="">createTransformStream</code> from the default
124403- policy. Then pipe chunks through that transform stream.</p></li>
124404+ <li><p>If <var>options</var>["<code data-x="dom-StreamHTMLUnsafeOptions-runScripts">runScripts</code>"],
124405+ configure <var>parser</var> to not mark scripts as already executed.</p></li>
124404124406
124405- <li><p>For trusted types handled "outside" (not by the internal transform stream) check that
124406- the chunks are in the same order and not duplicated/filtered/reordered.</p></li>
124407- </ol>
124408- </li>
124407+ <li><p>Return <var>writable</var> and continue running the remaining steps <span>in parallel</span>.</p></li>
124409124408
124410124409 <li>
124411- <p>👋 Sketch of the parser setup :</p>
124410+ <p>For every <var>chunk</var> that is written to <var>writable</var> :</p>
124412124411
124413124412 <ol>
124414- <li><p>Let <var>parser</var> be a new fragment parser.</p></li>
124415-
124416- <li><p>Add <span>this</span> to the <span>stack of open elements</span>.</p></li>
124413+ <li><p>Set <var>input</var> to the stringification of <var>chunk</var>. If this throws, abort
124414+ <var>writable</var> and abort these steps.</p></li>
124417124415
124418- <li><p>If <var>options</var>["<code data-x="dom-StreamHTMLUnsafeOptions-runScripts">runScripts</code>"],
124419- don't mark scripts as already executed.</p></li>
124416+ <li>Place the <var>input</var> into the <span>input stream</span> of <var>parser</var>.</li>
124420124417
124421- <li><p>Write chunks into the parser as they are written to <var>writable</var>.</p></li>
124418+ <li><p>Let <var>parser</var> run until it has consumed all the characters just inserted into
124419+ the input stream.</p></li>
124422124420 </ol>
124423124421 </li>
124424-
124425- <li><p>Return <var>writable</var>.</p></li>
124426124422 </ol>
124427124423 </div>
124428124424
124429124425 <div class="example">
124430124426 <p>Do a thing like this:</p>
124431- <pre><code class="js">const policy = trustedTypes.createPolicy("my-policy", {
124432- createTransformStream() {
124433- return new TransformStream({
124434- transform(chunk, controller) {
124435- // TODO: some buffering
124436- controller.enqueue(sanitize(chunk));
124437- }
124438- });
124439- }
124440- });
124441-
124442- const response = await fetch('/fragments/something');
124443- const transform = policy.createTransformStream();
124427+ <pre><code class="js">const response = await fetch('/fragments/something');
124428+ const decoder = new TextDecoderStream();
124444124429const writable = element.streamHTMLUnsafe();
124445- await response.body.pipeThrough(transform ).pipeTo(writable);</code></pre>
124430+ await response.body.pipeThrough(decoder ).pipeTo(writable);</code></pre>
124446124431 </div>
124447124432
124448124433 <div algorithm>
0 commit comments