Closed
Description
https://dom.spec.whatwg.org/#dom-document-adoptnode
Step 3 of the adoptNode
algorithm states:
If
node
is aDocumentFragment
node whosehost
is non-null, then return.
I'm assuming this means return nothing (null), where the other cases are either throwing a DOMException
or returning a Node
.
However, this is contrary to the Document interface IDL, which is:
[CEReactions] Node adoptNode(Node node);
instead of:
[CEReactions] Node? adoptNode(Node node);
Given this:
<html>
<body>
<script>
const createTemplateElement = (doc) => {
let template = doc.createElement('template')
let p = doc.createElement('p')
p.appendChild(doc.createTextNode('hello'))
template.appendChild(p)
return template
}
let newDoc = document.implementation.createHTMLDocument()
newDoc.body.appendChild(createTemplateElement(newDoc))
let template = newDoc.getElementsByTagName('template')[0]
// `template.content` is a `DocumentFragment` with a non-null host (the host is the <template>)
// <template> creation steps from https://html.spec.whatwg.org/multipage/scripting.html#the-template-element:
// 1. Let doc be the template element's node document's appropriate template contents owner document.
// 2. Create a DocumentFragment object whose node document is doc and host is the template element.
// 3. Set the template element's template contents to the newly created DocumentFragment object.
console.log(document.adoptNode(template.content))
</script>
</body>
</html>
Firefox, Chromium, and Safari all returned the DocumentFragment
from adoptNode
.
Metadata
Metadata
Assignees
Labels
No labels