customElements.define should retrieve lifecycle callbacks
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 Aug 2016 23:55:49 +0000 (23:55 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 Aug 2016 23:55:49 +0000 (23:55 +0000)
commit5539aecac10d93b7b7fd989ed8cd1c5bf9a07f39
tree99d5350826b73070a305253d0af7a0d3732b1990
parent6e309a0f10c94a834fe05d2de4f58fcf52a7aba9
customElements.define should retrieve lifecycle callbacks
https://bugs.webkit.org/show_bug.cgi?id=160797

Reviewed by Chris Dumez.

Source/WebCore:

Updated JSCustomElementInterface to invoke Get(constructor, "prototype") and Get(prototype, callbackName)
for each lifecycle callback as required by the latest specification:
https://html.spec.whatwg.org/#dom-customelementsregistry-define

Also added the support for "observedAttributes" property on the custom elements constructor which defines
the list of attributes for which attributeChangedCallback is invoked.

Test: fast/custom-elements/CustomElementsRegistry.html

* bindings/js/JSCustomElementInterface.cpp:
(WebCore::JSCustomElementInterface::setAttributeChangedCallback): Added.
(WebCore::JSCustomElementInterface::attributeChanged): Invoke m_attributeChangedCallback instead of on the
result of Get(element, "attributeChangedCallback").
* bindings/js/JSCustomElementInterface.h:
(WebCore::JSCustomElementInterface::observesAttribute): Added.

* bindings/js/JSCustomElementsRegistryCustom.cpp:
(WebCore::getLifecycleCallback): Added.
(WebCore::JSCustomElementsRegistry::define): Invoke Get(prototype, callbackName) for each callback. Also
store attributedChangedCallback and observedAttributes to JSCustomElementInterface. Other callbacks will
be stored in the future when the support for those callbacks are added.

* dom/Element.cpp:
(WebCore::Element::attributeChanged): Moved more code into enqueueAttributeChangedCallbackIfNeeded.

* dom/LifecycleCallbackQueue.cpp:
(WebCore::LifecycleCallbackQueue::enqueueAttributeChangedCallbackIfNeeded): Added an early exit for when
the given attribute is not observed by the custom element. Also moved the logic to retrieve
JSCustomElementInterface from Element::attributeChanged and renamed it from enqueueAttributeChangedCallback.

* bindings/js/JSDOMBinding.h:
(WebCore::toNativeArray): Throw a TypeError when the argument is not an object.
* bindings/js/JSDOMConvert.h:
(WebCore::Converter<Vector<T>>::convert): Removed a FIXME comment.

LayoutTests:

Added test cases for CustomElementsRegistry.define to make sure it invokes Get(constructor, "prototype")
and Get(prototype, callbackName) for each lifecycle callback.

Also updated the tests to reflect the support for observedAttributes which specifies the list of attributes
for which attributeChangedCallback is invoked.

* fast/custom-elements/CustomElementsRegistry-expected.txt: Renamed from Document-defineElement-expected.txt.
* fast/custom-elements/CustomElementsRegistry.html: Renamed from Document-defineElement.html.
* fast/custom-elements/Document-defineElement-expected.txt: Removed.
* fast/custom-elements/Document-defineElement.html: Removed.
* fast/custom-elements/attribute-changed-callback-expected.txt:
* fast/custom-elements/attribute-changed-callback.html: Added test cases for "observedAttributes".
* fast/custom-elements/lifecycle-callback-timing.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@204540 268f45cc-cd09-0410-ab3c-d52691b4dbfc
15 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/custom-elements/CustomElementsRegistry-expected.txt [new file with mode: 0644]
LayoutTests/fast/custom-elements/CustomElementsRegistry.html [new file with mode: 0644]
LayoutTests/fast/custom-elements/Document-defineElement-expected.txt [deleted file]
LayoutTests/fast/custom-elements/Document-defineElement.html [deleted file]
LayoutTests/fast/custom-elements/attribute-changed-callback-expected.txt
LayoutTests/fast/custom-elements/attribute-changed-callback.html
LayoutTests/fast/custom-elements/lifecycle-callback-timing.html
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSCustomElementInterface.cpp
Source/WebCore/bindings/js/JSCustomElementInterface.h
Source/WebCore/bindings/js/JSCustomElementsRegistryCustom.cpp
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/LifecycleCallbackQueue.cpp
Source/WebCore/dom/LifecycleCallbackQueue.h