|
231 | 231 | assert_false(readystatechange_fired); |
232 | 232 | }, `element.${method} should not modify Document readyState`); |
233 | 233 | } |
| 234 | + |
| 235 | + promise_test(async (t) => { |
| 236 | + window.events = []; |
| 237 | + const placeholder = document.getElementById("placeholder"); |
| 238 | + const container = document.createElement("div"); |
| 239 | + const ref = document.createElement("span"); |
| 240 | + container.append(ref); |
| 241 | + placeholder.append(container); |
| 242 | + t.add_cleanup(() => container.remove()); |
| 243 | + |
| 244 | + const writer = container.streamPrependHTMLUnsafe({ runScripts: true }).getWriter(); |
| 245 | + // The trailing "<" is only emitted, together with EOF, when the stream is closed. |
| 246 | + await writer.write( |
| 247 | + `<script defer src="data:text/javascript,window.events.push('defer');{let cache_buster=${Math.random()}}"></` + `script><` |
| 248 | + ); |
| 249 | + ref.remove(); |
| 250 | + // Inserting the "<" before the removed reference child errors the stream and aborts the |
| 251 | + // parser, but EOF is still processed. |
| 252 | + await promise_rejects_dom(t, "HierarchyRequestError", writer.close()); |
| 253 | + assert_equals(container.textContent, "", "the trailing '<' is not inserted"); |
| 254 | + |
| 255 | + // Control: a defer script streamed and closed now runs within a few tasks, so the defer script |
| 256 | + // of the aborted parser would have run by then too. |
| 257 | + window.control_ran = Promise.withResolvers(); |
| 258 | + t.add_cleanup(() => { delete window.control_ran; }); |
| 259 | + const control = document.createElement("div"); |
| 260 | + container.append(control); |
| 261 | + const controlWriter = control.streamAppendHTMLUnsafe({ runScripts: true }).getWriter(); |
| 262 | + await controlWriter.write( |
| 263 | + `<script defer src="data:text/javascript,window.events.push('control-defer');window.control_ran.resolve();{let cache_buster=${Math.random()}}"></` + `script>` |
| 264 | + ); |
| 265 | + await controlWriter.close(); |
| 266 | + await failOnTimeout(window.control_ran.promise); |
| 267 | + assert_array_equals(window.events, ["control-defer"]); |
| 268 | + }, "element.streamPrependHTMLUnsafe: defer scripts do not run if the reference child is removed before a trailing '<' is flushed by close()"); |
234 | 269 | </script> |
0 commit comments