[whatwg/dom] What should `adoptNode` return for a `DocumentFragment` with a non-null host? (#930)

https://dom.spec.whatwg.org/#concept-node-adopt

Step 3 of the `adoptNode` algorithm states:

> If `node` is a `DocumentFragment` node whose `host` is non-null, then return.

I'm assuming this means return nothing, where the other cases are either throwing a `DOMException` or returning a `Node`.

However, this is contrary to the [Document interface IDL](https://dom.spec.whatwg.org/#interface-document), which is:

`[CEReactions] Node adoptNode(Node node);`

instead of:

`[CEReactions] Node? adoptNode(Node node);`

---

Given this:

```html
<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`.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/930

Received on Wednesday, 25 November 2020 06:01:24 UTC