Add basic support for connected and disconnected callbacks
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 18 Aug 2016 22:19:59 +0000 (22:19 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 18 Aug 2016 22:19:59 +0000 (22:19 +0000)
commitf4710d99c35d53292ca6ffcf5d501a6f01f45665
tree7b0a10c180f1b08508ee67cb4aafdd99a3aca527
parent29701ebbdd3b8a8ea9745651350c58128a0faca5
Add basic support for connected and disconnected callbacks
https://bugs.webkit.org/show_bug.cgi?id=160950

Reviewed by Chris Dumez.

Source/WebCore:

Added the basic support for custom elements' connectedCallback and disconnectedCallback. These callbacks
are enqueued by inserting and removing a node as spec'ed by https://dom.spec.whatwg.org/#concept-node-insert
and https://dom.spec.whatwg.org/#concept-node-remove

For now, we only support callbacks on appendChild and removeChild to limit the amount of code changes and
tests that need to be included in this patch.

This patch also renames InvokesCustomElementLifecycleCallbacks IDL attribute to CEReactions to match
the latest specification: https://html.spec.whatwg.org/multipage/scripting.html#cereactions

Tests: fast/custom-elements/connected-callbacks.html
       fast/custom-elements/disconnected-callbacks.html

* bindings/js/JSCustomElementInterface.cpp:
(WebCore::JSCustomElementInterface::invokeCallback): Extracted from invokeAttributeChangedCallback.
(WebCore::JSCustomElementInterface::setConnectedCallback): Added.
(WebCore::JSCustomElementInterface::invokeConnectedCallback): Added.
(WebCore::JSCustomElementInterface::setDisconnectedCallback): Added.
(WebCore::JSCustomElementInterface::invokeDisconnectedCallback): Added.
(WebCore::JSCustomElementInterface::setAttributeChangedCallback):
(WebCore::JSCustomElementInterface::invokeAttributeChangedCallback): Renamed from attributeChanged.
* bindings/js/JSCustomElementInterface.h: Added m_connectedCallback and m_disconnectedCallback as instance
variables. Also removed the superfluous mutable qualifier from m_constructor m_attributeChangedCallback.
* bindings/js/JSCustomElementsRegistryCustom.cpp:
(WebCore::JSCustomElementsRegistry::define): Store connectedCallback and disconnectedCallback.
* bindings/scripts/CodeGeneratorJS.pm:
(GenerateImplementation):
* bindings/scripts/IDLAttributes.txt:
* dom/CustomElementsRegistry.idl:
* dom/Element.cpp:
(WebCore::Element::insertedInto): Call enqueueConnectedCallbackIfNeeded.
(WebCore::Element::removedFrom): Call enqueueDisconnectedCallbackIfNeeded.
* dom/Element.idl:
* dom/LifecycleCallbackQueue.cpp:
(WebCore::LifecycleQueueItem::invoke): Added calls to invokeConnectedCallback and invokeDisconnectedCallback.
(WebCore::findInterfaceForCustomElement): Extracted from enqueueAttributeChangedCallbackIfNeeded.
(WebCore::LifecycleCallbackQueue::enqueueConnectedCallbackIfNeeded): Added.
(WebCore::LifecycleCallbackQueue::enqueueDisconnectedCallbackIfNeeded): Added.
(WebCore::LifecycleCallbackQueue::enqueueAttributeChangedCallbackIfNeeded):
(WebCore::CustomElementLifecycleProcessingStack::ensureCurrentQueue):
* dom/LifecycleCallbackQueue.h:
* dom/Node.idl:

LayoutTests:

Added W3C style testharness.js tests for connectedCallback and disconnectedCallback.

Four test cases are failing due to a bug in window-less document's custom element registry,
which will be addressed in a future patch.

* fast/custom-elements/connected-callbacks-expected.txt: Added.
* fast/custom-elements/connected-callbacks.html: Added.
* fast/custom-elements/disconnected-callbacks-expected.txt: Added.
* fast/custom-elements/disconnected-callbacks.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@204611 268f45cc-cd09-0410-ab3c-d52691b4dbfc
17 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/custom-elements/connected-callbacks-expected.txt [new file with mode: 0644]
LayoutTests/fast/custom-elements/connected-callbacks.html [new file with mode: 0644]
LayoutTests/fast/custom-elements/disconnected-callbacks-expected.txt [new file with mode: 0644]
LayoutTests/fast/custom-elements/disconnected-callbacks.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSCustomElementInterface.cpp
Source/WebCore/bindings/js/JSCustomElementInterface.h
Source/WebCore/bindings/js/JSCustomElementsRegistryCustom.cpp
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Source/WebCore/bindings/scripts/IDLAttributes.txt
Source/WebCore/dom/CustomElementsRegistry.idl
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/Element.idl
Source/WebCore/dom/LifecycleCallbackQueue.cpp
Source/WebCore/dom/LifecycleCallbackQueue.h
Source/WebCore/dom/Node.idl