Skip to content

Commit

Permalink
DOM: latest DocumentFragment adoption changes
Browse files Browse the repository at this point in the history
See whatwg/dom#819.

Verified with jsdom/jsdom#2925.
  • Loading branch information
annevk committed Mar 27, 2020
1 parent 0734d74 commit ebc83f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion custom-elements/adopted-callback.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@

calls = [];
doc.documentElement.appendChild(shadowRoot);
assert_array_equals(calls, ['disconnected', 'adopted', document, doc, 'connected']);
assert_array_equals(calls, ['adopted', document, doc, 'disconnected', 'connected']);
});
}, 'Moving the shadow host\'s shadow of a custom element from the owner document into ' + documentName + ' must enqueue and invoke adoptedCallback');

Expand Down
18 changes: 11 additions & 7 deletions dom/nodes/adoption.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,34 @@ test(() => {
"name": "ShadowRoot",
"creator": doc => doc.createElementNS("http://www.w3.org/1999/xhtml", "div").attachShadow({mode: "closed"})
}
].forEach(dfTest => {
].forEach(({ name, creator }) => {
test(() => {
const doc = new Document();
const df = dfTest.creator(doc);
const df = creator(doc);
const child = df.appendChild(new Text('hi'));
assert_equals(df.ownerDocument, doc);

document.body.appendChild(df);
assert_equals(df.childNodes.length, 0);
assert_equals(child.ownerDocument, document);
assert_equals(df.ownerDocument, doc);
}, `appendChild() and ${dfTest.name}`);
if (name === "ShadowRoot") {
assert_equals(df.ownerDocument, doc);
} else {
assert_equals(df.ownerDocument, document);
}
}, `appendChild() and ${name}`);

test(() => {
const doc = new Document();
const df = dfTest.creator(doc);
const df = creator(doc);
const child = df.appendChild(new Text('hi'));
if (dfTest.name === "ShadowRoot") {
if (name === "ShadowRoot") {
assert_throws_dom("HierarchyRequestError", () => document.adoptNode(df));
} else {
document.adoptNode(df);
assert_equals(df.childNodes.length, 1);
assert_equals(child.ownerDocument, document);
assert_equals(df.ownerDocument, document);
}
}, `adoptNode() and ${dfTest.name}`);
}, `adoptNode() and ${name}`);
});

0 comments on commit ebc83f7

Please sign in to comment.