Title: [205220] trunk
Revision
205220
Author
[email protected]
Date
2016-08-30 22:18:54 -0700 (Tue, 30 Aug 2016)

Log Message

Add "get" to CustomElementsRegistry
https://bugs.webkit.org/show_bug.cgi?id=161421

Reviewed by Yusuke Suzuki.

Source/WebCore:

Add the support for "get" method on CustomElementsRegistry, which returns the constructor
of the custom element with the given name:
https://html.spec.whatwg.org/multipage/scripting.html#dom-customelementregistry-get

Tests: fast/custom-elements/CustomElementRegistry.html

* dom/CustomElementRegistry.cpp:
(WebCore::CustomElementRegistry::get): Added.
* dom/CustomElementRegistry.h:
* dom/CustomElementRegistry.idl:

LayoutTests:

Added test cases for "get" method on CustomElementsRegistry.

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

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (205219 => 205220)


--- trunk/LayoutTests/ChangeLog	2016-08-31 05:03:10 UTC (rev 205219)
+++ trunk/LayoutTests/ChangeLog	2016-08-31 05:18:54 UTC (rev 205220)
@@ -1,3 +1,15 @@
+2016-08-30  Ryosuke Niwa  <[email protected]>
+
+        Add "get" to CustomElementsRegistry
+        https://bugs.webkit.org/show_bug.cgi?id=161421
+
+        Reviewed by Yusuke Suzuki.
+
+        Added test cases for "get" method on CustomElementsRegistry.
+
+        * fast/custom-elements/CustomElementRegistry-expected.txt:
+        * fast/custom-elements/CustomElementRegistry.html:
+
 2016-08-30  Jiewen Tan  <[email protected]>
 
         Unreviewed, update iOS simulator WK1 flaky tests.

Modified: trunk/LayoutTests/fast/custom-elements/CustomElementRegistry-expected.txt (205219 => 205220)


--- trunk/LayoutTests/fast/custom-elements/CustomElementRegistry-expected.txt	2016-08-31 05:03:10 UTC (rev 205219)
+++ trunk/LayoutTests/fast/custom-elements/CustomElementRegistry-expected.txt	2016-08-31 05:18:54 UTC (rev 205220)
@@ -17,4 +17,8 @@
 PASS customElements.define must rethrow an exception thrown while retrieving Symbol.iterator on observedAttributes 
 PASS customElements.define must not throw even if "observedAttributes" fails to convert if "attributeChangedCallback" is not defined 
 PASS customElements.define must define an instantiatable custom element 
+PASS CustomElementRegistry interface must have get as a method 
+PASS "get" must return undefined when the registry does not contain an entry with the given name 
+PASS "get" must return undefined when the registry does not contain an entry with the given name even if the name was not a valid custom element name 
+PASS "get" return the constructor of the entry with the given name when there is a matching entry. 
 

Modified: trunk/LayoutTests/fast/custom-elements/CustomElementRegistry.html (205219 => 205220)


--- trunk/LayoutTests/fast/custom-elements/CustomElementRegistry.html	2016-08-31 05:03:10 UTC (rev 205219)
+++ trunk/LayoutTests/fast/custom-elements/CustomElementRegistry.html	2016-08-31 05:18:54 UTC (rev 205220)
@@ -267,6 +267,30 @@
 
 }, 'customElements.define must define an instantiatable custom element');
 
+test(function () {
+    assert_true('get' in CustomElementRegistry.prototype, '"get" exists on CustomElementRegistry.prototype');
+    assert_true('get' in customElements, '"get" exists on window.customElements');
+}, 'CustomElementRegistry interface must have get as a method');
+
+test(function () {
+    assert_equals(customElements.get('a-b'), undefined);
+}, '"get" must return undefined when the registry does not contain an entry with the given name');
+
+test(function () {
+    assert_equals(customElements.get('html'), undefined);
+    assert_equals(customElements.get('span'), undefined);
+    assert_equals(customElements.get('div'), undefined);
+    assert_equals(customElements.get('g'), undefined);
+    assert_equals(customElements.get('ab'), undefined);
+}, '"get" must return undefined when the registry does not contain an entry with the given name even if the name was not a valid custom element name');
+
+test(function () {
+    assert_equals(customElements.get('existing-custom-element'), undefined);
+    class ExistingCustomElement extends HTMLElement {};
+    customElements.define('existing-custom-element', ExistingCustomElement);
+    assert_equals(customElements.get('existing-custom-element'), ExistingCustomElement);
+}, '"get" return the constructor of the entry with the given name when there is a matching entry.');
+
 </script>
 </body>
 </html>

Modified: trunk/Source/WebCore/ChangeLog (205219 => 205220)


--- trunk/Source/WebCore/ChangeLog	2016-08-31 05:03:10 UTC (rev 205219)
+++ trunk/Source/WebCore/ChangeLog	2016-08-31 05:18:54 UTC (rev 205220)
@@ -1,3 +1,21 @@
+2016-08-30  Ryosuke Niwa  <[email protected]>
+
+        Add "get" to CustomElementsRegistry
+        https://bugs.webkit.org/show_bug.cgi?id=161421
+
+        Reviewed by Yusuke Suzuki.
+
+        Add the support for "get" method on CustomElementsRegistry, which returns the constructor
+        of the custom element with the given name:
+        https://html.spec.whatwg.org/multipage/scripting.html#dom-customelementregistry-get
+
+        Tests: fast/custom-elements/CustomElementRegistry.html
+
+        * dom/CustomElementRegistry.cpp:
+        (WebCore::CustomElementRegistry::get): Added.
+        * dom/CustomElementRegistry.h:
+        * dom/CustomElementRegistry.idl:
+
 2016-08-30  Yusuke Suzuki  <[email protected]>
 
         Make PendingScript as ref-counted

Modified: trunk/Source/WebCore/dom/CustomElementRegistry.cpp (205219 => 205220)


--- trunk/Source/WebCore/dom/CustomElementRegistry.cpp	2016-08-31 05:03:10 UTC (rev 205219)
+++ trunk/Source/WebCore/dom/CustomElementRegistry.cpp	2016-08-31 05:18:54 UTC (rev 205220)
@@ -105,6 +105,13 @@
     return m_constructorMap.contains(constructor);
 }
 
+JSC::JSValue CustomElementRegistry::get(const AtomicString& name)
+{
+    if (auto* elementInterface = m_nameMap.get(name))
+        return elementInterface->constructor();
+    return JSC::jsUndefined();
 }
 
+}
+
 #endif

Modified: trunk/Source/WebCore/dom/CustomElementRegistry.h (205219 => 205220)


--- trunk/Source/WebCore/dom/CustomElementRegistry.h	2016-08-31 05:03:10 UTC (rev 205219)
+++ trunk/Source/WebCore/dom/CustomElementRegistry.h	2016-08-31 05:18:54 UTC (rev 205220)
@@ -35,6 +35,7 @@
 namespace JSC {
 
 class JSObject;
+class JSValue;
     
 }
 
@@ -57,6 +58,8 @@
     JSCustomElementInterface* findInterface(const JSC::JSObject*) const;
     bool containsConstructor(const JSC::JSObject*) const;
 
+    JSC::JSValue get(const AtomicString&);
+
 private:
     CustomElementRegistry();
 
@@ -64,7 +67,7 @@
     HashMap<AtomicString, Ref<JSCustomElementInterface>> m_nameMap;
     HashMap<const JSC::JSObject*, JSCustomElementInterface*> m_constructorMap;
 };
-    
+
 }
 
 #endif

Modified: trunk/Source/WebCore/dom/CustomElementRegistry.idl (205219 => 205220)


--- trunk/Source/WebCore/dom/CustomElementRegistry.idl	2016-08-31 05:03:10 UTC (rev 205219)
+++ trunk/Source/WebCore/dom/CustomElementRegistry.idl	2016-08-31 05:18:54 UTC (rev 205220)
@@ -31,5 +31,6 @@
 ] interface CustomElementRegistry {
 
     [CEReactions, Custom] void define(DOMString name, Function constructor);
+    any get(DOMString name);
 
 };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to