Changeset 205220 in webkit


Ignore:
Timestamp:
Aug 30, 2016 10:18:54 PM (8 years ago)
Author:
rniwa@webkit.org
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:
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r205219 r205220  
     12016-08-30  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Add "get" to CustomElementsRegistry
     4        https://bugs.webkit.org/show_bug.cgi?id=161421
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        Added test cases for "get" method on CustomElementsRegistry.
     9
     10        * fast/custom-elements/CustomElementRegistry-expected.txt:
     11        * fast/custom-elements/CustomElementRegistry.html:
     12
    1132016-08-30  Jiewen Tan  <jiewen_tan@apple.com>
    214
  • trunk/LayoutTests/fast/custom-elements/CustomElementRegistry-expected.txt

    r204732 r205220  
    1818PASS customElements.define must not throw even if "observedAttributes" fails to convert if "attributeChangedCallback" is not defined
    1919PASS customElements.define must define an instantiatable custom element
     20PASS CustomElementRegistry interface must have get as a method
     21PASS "get" must return undefined when the registry does not contain an entry with the given name
     22PASS "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
     23PASS "get" return the constructor of the entry with the given name when there is a matching entry.
    2024
  • trunk/LayoutTests/fast/custom-elements/CustomElementRegistry.html

    r204732 r205220  
    268268}, 'customElements.define must define an instantiatable custom element');
    269269
     270test(function () {
     271    assert_true('get' in CustomElementRegistry.prototype, '"get" exists on CustomElementRegistry.prototype');
     272    assert_true('get' in customElements, '"get" exists on window.customElements');
     273}, 'CustomElementRegistry interface must have get as a method');
     274
     275test(function () {
     276    assert_equals(customElements.get('a-b'), undefined);
     277}, '"get" must return undefined when the registry does not contain an entry with the given name');
     278
     279test(function () {
     280    assert_equals(customElements.get('html'), undefined);
     281    assert_equals(customElements.get('span'), undefined);
     282    assert_equals(customElements.get('div'), undefined);
     283    assert_equals(customElements.get('g'), undefined);
     284    assert_equals(customElements.get('ab'), undefined);
     285}, '"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');
     286
     287test(function () {
     288    assert_equals(customElements.get('existing-custom-element'), undefined);
     289    class ExistingCustomElement extends HTMLElement {};
     290    customElements.define('existing-custom-element', ExistingCustomElement);
     291    assert_equals(customElements.get('existing-custom-element'), ExistingCustomElement);
     292}, '"get" return the constructor of the entry with the given name when there is a matching entry.');
     293
    270294</script>
    271295</body>
  • trunk/Source/WebCore/ChangeLog

    r205218 r205220  
     12016-08-30  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Add "get" to CustomElementsRegistry
     4        https://bugs.webkit.org/show_bug.cgi?id=161421
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        Add the support for "get" method on CustomElementsRegistry, which returns the constructor
     9        of the custom element with the given name:
     10        https://html.spec.whatwg.org/multipage/scripting.html#dom-customelementregistry-get
     11
     12        Tests: fast/custom-elements/CustomElementRegistry.html
     13
     14        * dom/CustomElementRegistry.cpp:
     15        (WebCore::CustomElementRegistry::get): Added.
     16        * dom/CustomElementRegistry.h:
     17        * dom/CustomElementRegistry.idl:
     18
    1192016-08-30  Yusuke Suzuki  <utatane.tea@gmail.com>
    220
  • trunk/Source/WebCore/dom/CustomElementRegistry.cpp

    r204732 r205220  
    106106}
    107107
     108JSC::JSValue CustomElementRegistry::get(const AtomicString& name)
     109{
     110    if (auto* elementInterface = m_nameMap.get(name))
     111        return elementInterface->constructor();
     112    return JSC::jsUndefined();
     113}
     114
    108115}
    109116
  • trunk/Source/WebCore/dom/CustomElementRegistry.h

    r204732 r205220  
    3636
    3737class JSObject;
     38class JSValue;
    3839   
    3940}
     
    5859    bool containsConstructor(const JSC::JSObject*) const;
    5960
     61    JSC::JSValue get(const AtomicString&);
     62
    6063private:
    6164    CustomElementRegistry();
     
    6568    HashMap<const JSC::JSObject*, JSCustomElementInterface*> m_constructorMap;
    6669};
    67    
     70
    6871}
    6972
  • trunk/Source/WebCore/dom/CustomElementRegistry.idl

    r204732 r205220  
    3232
    3333    [CEReactions, Custom] void define(DOMString name, Function constructor);
     34    any get(DOMString name);
    3435
    3536};
Note: See TracChangeset for help on using the changeset viewer.