Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /dom/nodes/insertion-removing-steps/Node-appendChild-script-and-custom-from-fragment.tentative.html - WPT Dashboard Interop Dashboard
<!doctype html>
<meta charset=utf-8>
<title>Node.appendChild: inserting script and custom element from a DocumentFragment</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<body>
<script>
let customConstructed = false;
let customConstructedDuringEarlierScript = false;
class CustomElement extends HTMLElement {
constructor() {
super();
customConstructed = true;
}
}
test(() => {
const script = document.createElement("script");
script.textContent = `
customElements.define("custom-element", CustomElement);
customConstructedDuringEarlierScript = customConstructed;
`;
const custom = document.createElement("custom-element");
const df = document.createDocumentFragment();
df.appendChild(script);
df.appendChild(custom);
assert_false(customConstructed);
assert_false(customConstructedDuringEarlierScript);
document.head.appendChild(df);
assert_true(customConstructed);
assert_true(customConstructedDuringEarlierScript);
}, "An earlier-inserted script can upgrade a later-inserted custom element, " +
"whose upgrading is synchronously observable to the script, since DOM " +
"insertion has been completed by the time it runs");
</script>