Move document.defineElement to customElements.define
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Aug 2016 02:08:17 +0000 (02:08 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Aug 2016 02:08:17 +0000 (02:08 +0000)
commit1f0eec3ce6784e561f8fddff57e987e6ddec2551
treee274d972467c4332d48367b897ce2a55f351813c
parentd25bba7418f6fa60a3472550c307fd27b3ef1fc4
Move document.defineElement to customElements.define
https://bugs.webkit.org/show_bug.cgi?id=160731

Reviewed by Chris Dumez.

Source/WebCore:

Replaced Document.prototype.defineElement by CustomElementsRegistry.prototype.define to match
the latest HTML specification: https://html.spec.whatwg.org/#custom-elements-api

This patch renames the existing CustomElementDefinitions to CustomElementsRegistry and exposes
it on window.customElements. CustomElementDefinitions is now owned by DOMWindow instead of
Document to match the spec's new semantics.

No new tests. The existing tests have been updated to reflect the change.

* DerivedSources.cpp:
* DerivedSources.make:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSCustomElementsRegistryCustom.cpp: Added.
(WebCore::JSCustomElementsRegistry::define): Moved from JSDocumentCustom. Removed the check for
the existence of DOMWindow since CustomElementsRegistry is an attribute on DOMWindow itself.
* bindings/js/JSDocumentCustom.cpp:
(WebCore::JSDocument::defineElement): Deleted.
* bindings/js/JSHTMLElementCustom.cpp: Added the code to check the existence of DOMWindow since
the registry is associated with DOMWindow, not Document.
(WebCore::constructJSHTMLElement):
* dom/CustomElementsRegistry.cpp: Renamed from Source/WebCore/dom/CustomElementDefinitions.cpp.
(WebCore::CustomElementsRegistry::create): Added.
(WebCore::CustomElementsRegistry::CustomElementsRegistry): Added.
(WebCore::CustomElementsRegistry::~CustomElementsRegistry): Added.
(WebCore::CustomElementsRegistry::addElementDefinition): Moved from CustomElementDefinitions.
(WebCore::CustomElementsRegistry::addUpgradeCandidate): Ditto.
(WebCore::CustomElementsRegistry::findInterface): Ditto.
(WebCore::CustomElementsRegistry::containsConstructor): Ditto.
* dom/CustomElementsRegistry.h: Renamed from Source/WebCore/dom/CustomElementDefinitions.h.
* dom/CustomElementsRegistry.idl: Added.
* dom/Document.cpp:
(WebCore::createUpgradeCandidateElement): Extracted out of createHTMLElementWithNameValidation
and createFallbackHTMLElement to share code.
(WebCore::createHTMLElementWithNameValidation):
(WebCore::createFallbackHTMLElement): This function was missing a check for the runtime flag.
Sharing code with createHTMLElementWithNameValidation via createUpgradeCandidateElement fixes it.
(WebCore::Document::ensureCustomElementDefinitions): Deleted.
* dom/Document.h:
(WebCore::Document::customElementDefinitions): Deleted.
* dom/Document.idl:
* dom/Element.cpp:
(WebCore::Element::attributeChanged):
* html/parser/HTMLConstructionSite.cpp:
(WebCore::HTMLConstructionSite::createHTMLElementOrFindCustomElementInterface):
* page/DOMWindow.cpp:
(WebCore::DOMWindow::ensureCustomElementsRegistry): Added. Moved from Document.
* page/DOMWindow.h:
* page/DOMWindow.idl: Added customElements on DOMWindow.

LayoutTests:

Updated the tests and their expected results to reflect the move of Document.prototype.defineElement to
CustomElementsRegistry.prototype.define. I'm going to rename tests in a follow up.

* fast/custom-elements/Document-createElement.html:
* fast/custom-elements/Document-defineElement-expected.txt:
* fast/custom-elements/Document-defineElement.html: Removed test cases for testing defining elements
in a viewless/windowless document since those documents don't have a corresponding window object.
* fast/custom-elements/HTMLElement-constructor.html:
* fast/custom-elements/attribute-changed-callback.html:
* fast/custom-elements/defined-pseudo-class.html:
* fast/custom-elements/defined-rule.html:
* fast/custom-elements/lifecycle-callback-timing.html:
* fast/custom-elements/parser/parser-constructs-custom-element-in-document-write.html:
* fast/custom-elements/parser/parser-constructs-custom-element-synchronously.html:
* fast/custom-elements/parser/parser-constructs-custom-elements-expected.txt:
* fast/custom-elements/parser/parser-constructs-custom-elements.html:
* fast/custom-elements/parser/parser-fallsback-to-unknown-element.html:
* fast/custom-elements/parser/parser-sets-attributes-and-children.html:
* fast/custom-elements/parser/parser-uses-constructed-element.html:
* fast/custom-elements/parser/parser-uses-registry-of-owner-document.html:
* fast/custom-elements/upgrading/Node-cloneNode.html:
* fast/custom-elements/upgrading/upgrading-parser-created-element.html:
* platform/mac/js/dom/global-constructors-attributes-expected.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@204367 268f45cc-cd09-0410-ab3c-d52691b4dbfc
43 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/custom-elements/Document-createElement.html
LayoutTests/fast/custom-elements/Document-defineElement-expected.txt
LayoutTests/fast/custom-elements/Document-defineElement.html
LayoutTests/fast/custom-elements/HTMLElement-constructor.html
LayoutTests/fast/custom-elements/attribute-changed-callback.html
LayoutTests/fast/custom-elements/defined-pseudo-class.html
LayoutTests/fast/custom-elements/defined-rule.html
LayoutTests/fast/custom-elements/lifecycle-callback-timing.html
LayoutTests/fast/custom-elements/parser/parser-constructs-custom-element-in-document-write.html
LayoutTests/fast/custom-elements/parser/parser-constructs-custom-element-synchronously.html
LayoutTests/fast/custom-elements/parser/parser-constructs-custom-elements-expected.txt
LayoutTests/fast/custom-elements/parser/parser-constructs-custom-elements.html
LayoutTests/fast/custom-elements/parser/parser-fallsback-to-unknown-element.html
LayoutTests/fast/custom-elements/parser/parser-sets-attributes-and-children.html
LayoutTests/fast/custom-elements/parser/parser-uses-constructed-element.html
LayoutTests/fast/custom-elements/parser/parser-uses-registry-of-owner-document.html
LayoutTests/fast/custom-elements/upgrading/Node-cloneNode.html
LayoutTests/fast/custom-elements/upgrading/upgrading-parser-created-element.html
LayoutTests/platform/efl/js/dom/global-constructors-attributes-expected.txt
LayoutTests/platform/gtk/js/dom/global-constructors-attributes-expected.txt
LayoutTests/platform/mac-yosemite/js/dom/global-constructors-attributes-expected.txt
LayoutTests/platform/mac/js/dom/global-constructors-attributes-expected.txt
LayoutTests/platform/win/js/dom/global-constructors-attributes-expected.txt
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources.cpp
Source/WebCore/DerivedSources.make
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSCustomElementsRegistryCustom.cpp [new file with mode: 0644]
Source/WebCore/bindings/js/JSDocumentCustom.cpp
Source/WebCore/bindings/js/JSHTMLElementCustom.cpp
Source/WebCore/dom/CustomElementsRegistry.cpp [moved from Source/WebCore/dom/CustomElementDefinitions.cpp with 75% similarity]
Source/WebCore/dom/CustomElementsRegistry.h [moved from Source/WebCore/dom/CustomElementDefinitions.h with 87% similarity]
Source/WebCore/dom/CustomElementsRegistry.idl [new file with mode: 0644]
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/Document.idl
Source/WebCore/dom/Element.cpp
Source/WebCore/html/parser/HTMLConstructionSite.cpp
Source/WebCore/page/DOMWindow.cpp
Source/WebCore/page/DOMWindow.h
Source/WebCore/page/DOMWindow.idl