Skip to content

Commit ae698cf

Browse files
committed
Adopted custom element's callbacks should continue to work
https://bugs.webkit.org/show_bug.cgi?id=161065 Reviewed by Andreas Kling. Source/WebCore: When a custom element is adopted into another document, its reaction callbacks need to continue to work. Because a different document may have its own global object, each custom element needs to remember its original global object or JSCustomElementInterface. This patch adds the latter to the element rare data. Tests: fast/custom-elements/connected-callbacks.html fast/custom-elements/disconnected-callbacks.html * bindings/js/JSCustomElementInterface.cpp: (WebCore::JSCustomElementInterface::constructElement): (WebCore::JSCustomElementInterface::upgradeElement): * dom/CustomElementReactionQueue.cpp: (WebCore::findInterfaceForCustomElement): Deleted. (WebCore::CustomElementReactionQueue::enqueueConnectedCallbackIfNeeded): (WebCore::CustomElementReactionQueue::enqueueDisconnectedCallbackIfNeeded): (WebCore::CustomElementReactionQueue::enqueueAttributeChangedCallbackIfNeeded): * dom/Element.cpp: (WebCore::Element::insertedInto): Invoke callbacks even when the current document is not a HTML document. (WebCore::Element::removedFrom): Ditto. (WebCore::Element::setCustomElementIsResolved): Moved from Node. Add the element interface to the rare data. (WebCore::Element::customElementInterface): Added. * dom/Element.h: * dom/ElementRareData.cpp: * dom/ElementRareData.h: (WebCore::ElementRareData::customElementInterface): Added. (WebCore::ElementRareData::setCustomElementInterface): Added. * dom/Node.h: ((WebCore::Node::setCustomElementIsResolved): Deleted. LayoutTests: Added test cases for adopting custom elements into various kinds of documents. * fast/custom-elements/connected-callbacks-expected.txt: * fast/custom-elements/connected-callbacks.html: * fast/custom-elements/defined-pseudo-class-expected.txt: * fast/custom-elements/defined-pseudo-class.html: * fast/custom-elements/disconnected-callbacks-expected.txt: * fast/custom-elements/disconnected-callbacks.html: * fast/custom-elements/resources/document-types.js: Added. * fast/custom-elements/resources/empty-html-document.html: Added. Canonical link: https://commits.webkit.org/179436@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@205060 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 33f8228 commit ae698cf

17 files changed

Lines changed: 396 additions & 216 deletions

LayoutTests/ChangeLog

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
2016-08-23 Ryosuke Niwa <rniwa@webkit.org>
2+
3+
Adopted custom element's callbacks should continue to work
4+
https://bugs.webkit.org/show_bug.cgi?id=161065
5+
6+
Reviewed by Andreas Kling.
7+
8+
Added test cases for adopting custom elements into various kinds of documents.
9+
10+
* fast/custom-elements/connected-callbacks-expected.txt:
11+
* fast/custom-elements/connected-callbacks.html:
12+
* fast/custom-elements/defined-pseudo-class-expected.txt:
13+
* fast/custom-elements/defined-pseudo-class.html:
14+
* fast/custom-elements/disconnected-callbacks-expected.txt:
15+
* fast/custom-elements/disconnected-callbacks.html:
16+
* fast/custom-elements/resources/document-types.js: Added.
17+
* fast/custom-elements/resources/empty-html-document.html: Added.
18+
119
2016-08-26 Ryan Haddad <ryanhaddad@apple.com>
220

321
Marking webgl/max-active-contexts-webglcontextlost-prevent-default.html as flaky on mac-wk1.
Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,43 @@
11

22
PASS Inserting a custom element into a document must enqueue and invoke connectedCallback
3-
PASS Inserting a custom element into a detached node must not enqueue and invoke connectedCallback
4-
FAIL Inserting a custom element into a window-less document must enqueue and invoke connectedCallback assert_array_equals: lengths differ, expected 2 got 0
5-
PASS Inserting an ancestor of a custom element into a document must enqueue and invoke connectedCallback
6-
FAIL Inserting an ancestor of custom element into a window-less document must enqueue and invoke connectedCallback assert_array_equals: lengths differ, expected 2 got 0
7-
PASS Inserting a custom element into a connected shadow tree must enqueue and invoke connectedCallback
8-
PASS Inserting the shadow host of a shadow tree with a custom element into a document must enqueue and invoke connectedCallback
9-
PASS Inserting a custom element into a detached shadow tree must not enqueue and invoke connectedCallback
3+
PASS Inserting an ancestor of custom element into a document must enqueue and invoke connectedCallback
4+
PASS Inserting a custom element into a shadow tree in a document must enqueue and invoke connectedCallback
5+
PASS Inserting the shadow host of a custom element into a document must enqueue and invoke connectedCallback
6+
PASS Inserting a custom element into a detached shadow tree that belongs to a document must not enqueue and invoke connectedCallback
7+
PASS Inserting a custom element into a document of a template element must enqueue and invoke connectedCallback
8+
PASS Inserting an ancestor of custom element into a document of a template element must enqueue and invoke connectedCallback
9+
PASS Inserting a custom element into a shadow tree in a document of a template element must enqueue and invoke connectedCallback
10+
PASS Inserting the shadow host of a custom element into a document of a template element must enqueue and invoke connectedCallback
11+
PASS Inserting a custom element into a detached shadow tree that belongs to a document of a template element must not enqueue and invoke connectedCallback
12+
PASS Inserting a custom element into a new document must enqueue and invoke connectedCallback
13+
PASS Inserting an ancestor of custom element into a new document must enqueue and invoke connectedCallback
14+
PASS Inserting a custom element into a shadow tree in a new document must enqueue and invoke connectedCallback
15+
PASS Inserting the shadow host of a custom element into a new document must enqueue and invoke connectedCallback
16+
PASS Inserting a custom element into a detached shadow tree that belongs to a new document must not enqueue and invoke connectedCallback
17+
PASS Inserting a custom element into a cloned document must enqueue and invoke connectedCallback
18+
PASS Inserting an ancestor of custom element into a cloned document must enqueue and invoke connectedCallback
19+
PASS Inserting a custom element into a shadow tree in a cloned document must enqueue and invoke connectedCallback
20+
PASS Inserting the shadow host of a custom element into a cloned document must enqueue and invoke connectedCallback
21+
PASS Inserting a custom element into a detached shadow tree that belongs to a cloned document must not enqueue and invoke connectedCallback
22+
PASS Inserting a custom element into a document created by createHTMLDocument must enqueue and invoke connectedCallback
23+
PASS Inserting an ancestor of custom element into a document created by createHTMLDocument must enqueue and invoke connectedCallback
24+
PASS Inserting a custom element into a shadow tree in a document created by createHTMLDocument must enqueue and invoke connectedCallback
25+
PASS Inserting the shadow host of a custom element into a document created by createHTMLDocument must enqueue and invoke connectedCallback
26+
PASS Inserting a custom element into a detached shadow tree that belongs to a document created by createHTMLDocument must not enqueue and invoke connectedCallback
27+
PASS Inserting a custom element into a HTML document created by createDocument must enqueue and invoke connectedCallback
28+
PASS Inserting an ancestor of custom element into a HTML document created by createDocument must enqueue and invoke connectedCallback
29+
PASS Inserting a custom element into a shadow tree in a HTML document created by createDocument must enqueue and invoke connectedCallback
30+
PASS Inserting the shadow host of a custom element into a HTML document created by createDocument must enqueue and invoke connectedCallback
31+
PASS Inserting a custom element into a detached shadow tree that belongs to a HTML document created by createDocument must not enqueue and invoke connectedCallback
32+
PASS Inserting a custom element into a document in an iframe must enqueue and invoke connectedCallback
33+
PASS Inserting an ancestor of custom element into a document in an iframe must enqueue and invoke connectedCallback
34+
PASS Inserting a custom element into a shadow tree in a document in an iframe must enqueue and invoke connectedCallback
35+
PASS Inserting the shadow host of a custom element into a document in an iframe must enqueue and invoke connectedCallback
36+
PASS Inserting a custom element into a detached shadow tree that belongs to a document in an iframe must not enqueue and invoke connectedCallback
37+
PASS Inserting a custom element into a HTML document fetched by XHR must enqueue and invoke connectedCallback
38+
PASS Inserting an ancestor of custom element into a HTML document fetched by XHR must enqueue and invoke connectedCallback
39+
PASS Inserting a custom element into a shadow tree in a HTML document fetched by XHR must enqueue and invoke connectedCallback
40+
PASS Inserting the shadow host of a custom element into a HTML document fetched by XHR must enqueue and invoke connectedCallback
41+
PASS Inserting a custom element into a detached shadow tree that belongs to a HTML document fetched by XHR must not enqueue and invoke connectedCallback
42+
1043

LayoutTests/fast/custom-elements/connected-callbacks.html

Lines changed: 63 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<link rel="help" href="https://w3c.github.io/webcomponents/spec/custom/#dfn-connected-callback">
88
<script src="../../resources/testharness.js"></script>
99
<script src="../../resources/testharnessreport.js"></script>
10+
<script src="./resources/document-types.js"></script>
1011
<link rel='stylesheet' href='../../resources/testharness.css'>
1112
</head>
1213
<body>
@@ -20,84 +21,68 @@
2021
}
2122
customElements.define('my-custom-element', MyCustomElement);
2223

23-
test(function () {
24-
var instance = document.createElement('my-custom-element');
25-
26-
calls = [];
27-
document.body.appendChild(instance);
28-
assert_array_equals(calls, ['connected', instance]);
29-
}, 'Inserting a custom element into a document must enqueue and invoke connectedCallback');
30-
31-
test(function () {
32-
var instance = document.createElement('my-custom-element');
33-
34-
calls = [];
35-
var parent = document.createElement('div');
36-
parent.appendChild(instance);
37-
assert_array_equals(calls, []);
38-
}, 'Inserting a custom element into a detached node must not enqueue and invoke connectedCallback');
39-
40-
test(function () {
41-
var instance = document.createElement('my-custom-element');
42-
var documentWithoutWindow = document.implementation.createHTMLDocument();
43-
44-
calls = [];
45-
documentWithoutWindow.body.appendChild(instance);
46-
assert_array_equals(calls, ['connected', instance]);
47-
}, 'Inserting a custom element into a window-less document must enqueue and invoke connectedCallback');
48-
49-
test(function () {
50-
var instance = document.createElement('my-custom-element');
51-
var parent = document.createElement('div');
52-
parent.appendChild(instance);
53-
54-
calls = [];
55-
document.body.appendChild(parent);
56-
assert_array_equals(calls, ['connected', instance]);
57-
}, 'Inserting an ancestor of a custom element into a document must enqueue and invoke connectedCallback');
58-
59-
test(function () {
60-
var instance = document.createElement('my-custom-element');
61-
var parent = document.createElement('div');
62-
parent.appendChild(instance);
63-
var documentWithoutWindow = document.implementation.createHTMLDocument();
64-
65-
calls = [];
66-
documentWithoutWindow.body.appendChild(parent);
67-
assert_array_equals(calls, ['connected', instance]);
68-
}, 'Inserting an ancestor of custom element into a window-less document must enqueue and invoke connectedCallback');
69-
70-
test(function () {
71-
var instance = document.createElement('my-custom-element');
72-
var host = document.createElement('div');
73-
var shadowRoot = host.attachShadow({mode: 'closed'});
74-
document.body.appendChild(host);
75-
76-
calls = [];
77-
shadowRoot.appendChild(instance);
78-
assert_array_equals(calls, ['connected', instance]);
79-
}, 'Inserting a custom element into a connected shadow tree must enqueue and invoke connectedCallback');
80-
81-
test(function () {
82-
var instance = document.createElement('my-custom-element');
83-
var host = document.createElement('div');
84-
var shadowRoot = host.attachShadow({mode: 'closed'});
85-
shadowRoot.appendChild(instance);
86-
87-
calls = [];
88-
document.body.appendChild(host);
89-
assert_array_equals(calls, ['connected', instance]);
90-
}, 'Inserting the shadow host of a shadow tree with a custom element into a document must enqueue and invoke connectedCallback');
91-
92-
test(function () {
93-
var instance = document.createElement('my-custom-element');
94-
var host = document.createElement('div');
95-
var shadowRoot = host.attachShadow({mode: 'closed'});
96-
97-
calls = [];
98-
shadowRoot.appendChild(instance);
99-
assert_array_equals(calls, []);
100-
}, 'Inserting a custom element into a detached shadow tree must not enqueue and invoke connectedCallback');
24+
DocumentTypes.forEach(function (entry) {
25+
var documentName = entry.name;
26+
var getDocument = entry.create;
27+
28+
promise_test(function () {
29+
return getDocument().then(function (doc) {
30+
var instance = document.createElement('my-custom-element');
31+
calls = [];
32+
doc.documentElement.appendChild(instance);
33+
assert_array_equals(calls, ['connected', instance]);
34+
});
35+
}, 'Inserting a custom element into a ' + documentName + ' must enqueue and invoke connectedCallback');
36+
37+
promise_test(function () {
38+
return getDocument().then(function (doc) {
39+
var instance = document.createElement('my-custom-element');
40+
var parent = document.createElement('div');
41+
parent.appendChild(instance);
42+
calls = [];
43+
doc.documentElement.appendChild(parent);
44+
assert_array_equals(calls, ['connected', instance]);
45+
});
46+
}, 'Inserting an ancestor of custom element into a ' + documentName + ' must enqueue and invoke connectedCallback');
47+
48+
promise_test(function () {
49+
return getDocument().then(function (doc) {
50+
var instance = document.createElement('my-custom-element');
51+
var host = doc.createElementNS('http://www.w3.org/1999/xhtml', 'div');
52+
var shadowRoot = host.attachShadow({mode: 'closed'});
53+
doc.documentElement.appendChild(host);
54+
55+
calls = [];
56+
shadowRoot.appendChild(instance);
57+
assert_array_equals(calls, ['connected', instance]);
58+
});
59+
}, 'Inserting a custom element into a shadow tree in a ' + documentName + ' must enqueue and invoke connectedCallback');
60+
61+
promise_test(function () {
62+
return getDocument().then(function (doc) {
63+
var instance = document.createElement('my-custom-element');
64+
var host = doc.createElementNS('http://www.w3.org/1999/xhtml', 'div');
65+
var shadowRoot = host.attachShadow({mode: 'closed'});
66+
shadowRoot.appendChild(instance);
67+
68+
calls = [];
69+
doc.documentElement.appendChild(host);
70+
assert_array_equals(calls, ['connected', instance]);
71+
});
72+
}, 'Inserting the shadow host of a custom element into a ' + documentName + ' must enqueue and invoke connectedCallback');
73+
74+
promise_test(function () {
75+
return getDocument().then(function (doc) {
76+
var instance = document.createElement('my-custom-element');
77+
var host = doc.createElementNS('http://www.w3.org/1999/xhtml', 'div');
78+
var shadowRoot = host.attachShadow({mode: 'closed'});
79+
80+
calls = [];
81+
shadowRoot.appendChild(instance);
82+
assert_array_equals(calls, []);
83+
});
84+
}, 'Inserting a custom element into a detached shadow tree that belongs to a ' + documentName + ' must not enqueue and invoke connectedCallback');
85+
});
10186

10287
</script>
10388
</body>

LayoutTests/fast/custom-elements/defined-pseudo-class-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
PASS The defined flag of a custom element must be set if a custom element has not been upgraded yet
2+
PASS The defined flag of a custom element must not be set if a custom element has not been upgraded yet
33
PASS The defined flag of a custom element must be set when a custom element is successfully upgraded
44
PASS The defined flag of a custom element must be set if there is a matching definition
55
PASS The defined flag of a custom element created by HTML parser must be unset if there is no matching definition

LayoutTests/fast/custom-elements/defined-pseudo-class.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
test(function () {
1818
assert_false(upgradeCandidate.matches(':defined'));
19-
}, 'The defined flag of a custom element must be set if a custom element has not been upgraded yet');
19+
}, 'The defined flag of a custom element must not be set if a custom element has not been upgraded yet');
2020

2121
var matchInsideConstructor;
2222
class MyElement extends HTMLElement {

0 commit comments

Comments
 (0)