Add "whenDefined" to CustomElementRegistry
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Sep 2016 21:16:40 +0000 (21:16 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Sep 2016 21:16:40 +0000 (21:16 +0000)
commit06d25dbf4ec5e57da09b2d0aed4ea8aa0e583d5f
treec92f14ac847783ce1615b85911154d1f0ae5bcdc
parent9cf9eec87817d0ac62ea75f6fa92f1440d3db022
Add "whenDefined" to CustomElementRegistry
https://bugs.webkit.org/show_bug.cgi?id=161425

Reviewed by Yusuke Suzuki.

Source/WebCore:

Add the support for "whenDefined" method on CustomElementRegistry:
https://html.spec.whatwg.org/#dom-customelementregistry-whendefined

Because it needs to store the newly created promise when the queried custom element has not been defined yet,
we need to write custom binding code instead of relying on the binding generator.

Tests: fast/custom-elements/CustomElementRegistry.html

* bindings/js/JSCustomElementRegistryCustom.cpp:
(WebCore::validateCustomElementNameAndThrowIfNeeded): Extracted out of JSCustomElementRegistry::define.
(WebCore::JSCustomElementRegistry::define): Fulfill the "whenDefined" promise when the definition succeeds.
(WebCore::whenDefinedPromise): Added. Return an existing promise if there is one, or create a new promise.
We cache the created promise only if the custom element had not been defined yet since we'll indefinitely
retain the resolved promise otherwise.
(WebCore::JSCustomElementRegistry::whenDefined): Added. Calls whenDefinedPromise and returns a rejected
promise when there was an exception.
* dom/CustomElementRegistry.cpp:
* dom/CustomElementRegistry.h:
(WebCore::CustomElementRegistry::promiseMap): Added.
* dom/CustomElementRegistry.idl:

LayoutTests:

Added test cases for "whenDefined" method.

* fast/custom-elements/CustomElementRegistry-expected.txt:
* fast/custom-elements/CustomElementRegistry.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@205315 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/fast/custom-elements/CustomElementRegistry-expected.txt
LayoutTests/fast/custom-elements/CustomElementRegistry.html
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSCustomElementRegistryCustom.cpp
Source/WebCore/dom/CustomElementRegistry.cpp
Source/WebCore/dom/CustomElementRegistry.h
Source/WebCore/dom/CustomElementRegistry.idl