Only update connected custom elements
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 2 Sep 2016 06:17:17 +0000 (06:17 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 2 Sep 2016 06:17:17 +0000 (06:17 +0000)
commit5ca8b82cb914d54d1197526ea0f2ff059f69dd52
tree7a2c1ca10d9ba2229fe7f909ec827e7471b1cb1f
parent409eab09a26b1e7f1eb8c9c878d7b8806cfb4e84
Only update connected custom elements
https://bugs.webkit.org/show_bug.cgi?id=161480

Reviewed by Yusuke Suzuki.

Source/WebCore:

In the latest specs, creating an element only upgrades an element if the custom element had already been defined:
https://dom.spec.whatwg.org/#concept-create-element

Otherwise, an element remains unresolved until it gets connected to the document associated with the global object:
https://dom.spec.whatwg.org/#concept-node-insert

This patch removes the upgrade candidate map in CustomElementRegistry, and traverses the entire document associated
with global object (DOMWindow) in addElementDefinition: https://html.spec.whatwg.org/#dom-customelementregistry-define

The traversal is done in the shadow-including tree order (different from depth-first preorder traversal of flat tree)
since it doesn't enter slots and children of shadow hosts are always visited even if they are not assigned to a slot:
https://dom.spec.whatwg.org/#concept-shadow-including-tree-order

Test: fast/custom-elements/enqueue-custom-element-upgrade-reaction.html

* bindings/js/JSCustomElementInterface.cpp:
(WebCore::JSCustomElementInterface::upgradeElement): Assert that the element being upgraded as the same qualified name
as the custom element interface.
* bindings/js/JSCustomElementRegistryCustom.cpp:
(WebCore::JSCustomElementRegistry::define): Moved the code to resolve the promise from here to addElementDefinition.
Also cleaned up the code to extract callbacks a little.
* dom/CustomElementReactionQueue.cpp:
(WebCore::CustomElementReactionQueue::enqueueElementUpgrade): Added an assertion.
(WebCore::CustomElementReactionQueue::enqueueElementUpgradeIfDefined): Added. Upgrade an element if the custom element
had already been defined.
* dom/CustomElementReactionQueue.h:
* dom/CustomElementRegistry.cpp:
(WebCore::CustomElementRegistry::create): Stores the reference to DOMWindow to find its document in addElementDefinition.
(WebCore::CustomElementRegistry::CustomElementRegistry): Ditto.
(WebCore::enqueueUpgradeInShadowIncludingTreeOrder): Added. Enqueue upgrade reactions in shadow-including tree order.
(WebCore::CustomElementRegistry::addElementDefinition): Upgrade all unresolved elements that matches this definition and
resolve the the promise returned by "whenDefined" if there is any.
(WebCore::CustomElementRegistry::addUpgradeCandidate): Deleted.
(WebCore::CustomElementRegistry::findInterface): Added a new variant that takes an element.
* dom/CustomElementRegistry.h:
* dom/Document.cpp:
(WebCore::createUpgradeCandidateElement): No longer takes DOMWindow since we don't upgrade synchronously here. It's also
wrong not to mark the element as unresolved custom element in a document without a browsing context per new semantics.
(WebCore::createHTMLElementWithNameValidation): Ditto.
(WebCore::createFallbackHTMLElement): Ditto.
* dom/Element.cpp:
(WebCore::Element::insertedInto): Enqueue an upgrade reaction if this is an unsolved custom element and there is now
a definition for it (the latter condition is checked in enqueueElementUpgradeIfDefined).
* html/parser/HTMLConstructionSite.cpp:
(WebCore::HTMLConstructionSite::createHTMLElementOrFindCustomElementInterface): Don't upgrade this element until it gets
connected to a document in Element::insertedInto.
* page/DOMWindow.cpp:
(WebCore::DOMWindow::ensureCustomElementRegistry):

LayoutTests:

Added a W3c-style testharness.js test for https://html.spec.whatwg.org/#enqueue-a-custom-element-upgrade-reaction
and added more test cases for :defined and customElements.define.

* fast/custom-elements/CustomElementRegistry.html: Revised descriptions for "get" and "whenDefined" test cases consistent
with ones for "define".
* fast/custom-elements/defined-pseudo-class-expected.txt:
* fast/custom-elements/defined-pseudo-class.html:
* fast/custom-elements/enqueue-custom-element-upgrade-reaction-expected.txt: Added.
* fast/custom-elements/enqueue-custom-element-upgrade-reaction.html: Added.
* fast/custom-elements/resources/document-types.js:
(create):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@205340 268f45cc-cd09-0410-ab3c-d52691b4dbfc
19 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/custom-elements/CustomElementRegistry-expected.txt
LayoutTests/fast/custom-elements/CustomElementRegistry.html
LayoutTests/fast/custom-elements/defined-pseudo-class-expected.txt
LayoutTests/fast/custom-elements/defined-pseudo-class.html
LayoutTests/fast/custom-elements/enqueue-custom-element-upgrade-reaction-expected.txt [new file with mode: 0644]
LayoutTests/fast/custom-elements/enqueue-custom-element-upgrade-reaction.html [new file with mode: 0644]
LayoutTests/fast/custom-elements/resources/document-types.js
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSCustomElementInterface.cpp
Source/WebCore/bindings/js/JSCustomElementRegistryCustom.cpp
Source/WebCore/dom/CustomElementReactionQueue.cpp
Source/WebCore/dom/CustomElementReactionQueue.h
Source/WebCore/dom/CustomElementRegistry.cpp
Source/WebCore/dom/CustomElementRegistry.h
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Element.cpp
Source/WebCore/html/parser/HTMLConstructionSite.cpp
Source/WebCore/page/DOMWindow.cpp