Node-appendChild-script-and-custom-from-fragment.tentative.html (1257B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title>Node.appendChild: inserting script and custom element from a DocumentFragment</title> 4 <script src=/resources/testharness.js></script> 5 <script src=/resources/testharnessreport.js></script> 6 <body> 7 <script> 8 let customConstructed = false; 9 let customConstructedDuringEarlierScript = false; 10 class CustomElement extends HTMLElement { 11 constructor() { 12 super(); 13 customConstructed = true; 14 } 15 } 16 test(() => { 17 const script = document.createElement("script"); 18 script.textContent = ` 19 customElements.define("custom-element", CustomElement); 20 customConstructedDuringEarlierScript = customConstructed; 21 `; 22 const custom = document.createElement("custom-element"); 23 const df = document.createDocumentFragment(); 24 df.appendChild(script); 25 df.appendChild(custom); 26 assert_false(customConstructed); 27 assert_false(customConstructedDuringEarlierScript); 28 document.head.appendChild(df); 29 assert_true(customConstructed); 30 assert_true(customConstructedDuringEarlierScript); 31 }, "An earlier-inserted script can upgrade a later-inserted custom element, " + 32 "whose upgrading is synchronously observable to the script, since DOM " + 33 "insertion has been completed by the time it runs"); 34 </script>