diff --git a/LayoutTests/imported/w3c/web-platform-tests/custom-elements/CustomElementRegistry-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/custom-elements/CustomElementRegistry-expected.txt index b5d3c3ae99dfb..fe2d11795b8bd 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/custom-elements/CustomElementRegistry-expected.txt +++ b/LayoutTests/imported/w3c/web-platform-tests/custom-elements/CustomElementRegistry-expected.txt @@ -36,10 +36,10 @@ PASS CustomElementRegistry interface must have get as a method PASS customElements.get must return undefined when the registry does not contain an entry with the given name PASS customElements.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 customElements.get return the constructor of the entry with the given name when there is a matching entry. -PASS customElements.getName must return undefined when called with undefined -PASS customElements.getName must return undefined when called with null -PASS customElements.getName must return undefined when called with a string -PASS customElements.getName must return undefined when the registry does not contain an entry with the given constructor +PASS customElements.getName must return null when the registry does not contain an entry with the given constructor +PASS customElements.getName must return null when called with undefined +PASS customElements.getName must return null when called with null +PASS customElements.getName must return null when called with a string PASS customElements.getName returns the name of the entry with the given constructor when there is a matching entry. PASS customElements.whenDefined must return a promise for a valid custom element name PASS customElements.whenDefined must return the same promise each time invoked for a valid custom element name which has not been defined diff --git a/LayoutTests/imported/w3c/web-platform-tests/custom-elements/CustomElementRegistry.html b/LayoutTests/imported/w3c/web-platform-tests/custom-elements/CustomElementRegistry.html index fddb3be999fe8..c740279b94c88 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/custom-elements/CustomElementRegistry.html +++ b/LayoutTests/imported/w3c/web-platform-tests/custom-elements/CustomElementRegistry.html @@ -624,26 +624,26 @@ }, 'customElements.get return the constructor of the entry with the given name when there is a matching entry.'); test(function () { - assert_equals(customElements.getName(undefined), undefined); -}, 'customElements.getName must return undefined when called with undefined'); + assert_equals(customElements.getName(class extends HTMLElement {}), null); +}, 'customElements.getName must return null when the registry does not contain an entry with the given constructor'); test(function () { - assert_equals(customElements.getName(null), undefined); -}, 'customElements.getName must return undefined when called with null'); + assert_equals(customElements.getName(undefined), null); +}, 'customElements.getName must return null when called with undefined'); test(function () { - assert_equals(customElements.getName(''), undefined); -}, 'customElements.getName must return undefined when called with a string'); + assert_equals(customElements.getName(null), null); +}, 'customElements.getName must return null when called with null'); test(function () { - assert_equals(customElements.getName(class extends HTMLElement {}), undefined); -}, 'customElements.getName must return undefined when the registry does not contain an entry with the given constructor'); + assert_equals(customElements.getName(''), null); +}, 'customElements.getName must return null when called with a string'); test(function () { - class ExistingCustomElement extends HTMLElement {}; - assert_equals(customElements.getName(ExistingCustomElement), undefined); - customElements.define('other-custom-element', ExistingCustomElement); - assert_equals(customElements.getName(ExistingCustomElement), 'other-custom-element'); + class OtherExistingCustomElement extends HTMLElement {}; + assert_equals(customElements.getName(OtherExistingCustomElement), null); + customElements.define('other-existing-custom-element', OtherExistingCustomElement); + assert_equals(customElements.getName(OtherExistingCustomElement), 'other-existing-custom-element'); }, 'customElements.getName returns the name of the entry with the given constructor when there is a matching entry.'); test(function () { diff --git a/Source/WebCore/dom/CustomElementRegistry.cpp b/Source/WebCore/dom/CustomElementRegistry.cpp index d0527835a1600..138119355f04e 100644 --- a/Source/WebCore/dom/CustomElementRegistry.cpp +++ b/Source/WebCore/dom/CustomElementRegistry.cpp @@ -128,15 +128,15 @@ JSC::JSValue CustomElementRegistry::get(const AtomString& name) return JSC::jsUndefined(); } -JSC::JSValue CustomElementRegistry::getName(JSC::JSGlobalObject& globalObject, JSC::JSValue constructorValue) +String CustomElementRegistry::getName(JSC::JSValue constructorValue) { auto* constructor = constructorValue.getObject(); if (!constructor) - return JSC::jsUndefined(); + return String { }; auto* elementInterface = findInterface(constructor); if (!elementInterface) - return JSC::jsUndefined(); - return JSC::jsString(globalObject.vm(), elementInterface->name().localName()); + return String { }; + return elementInterface->name().localName(); } static void upgradeElementsInShadowIncludingDescendants(ContainerNode& root) diff --git a/Source/WebCore/dom/CustomElementRegistry.h b/Source/WebCore/dom/CustomElementRegistry.h index 917ddb0fce754..abcd0762890dc 100644 --- a/Source/WebCore/dom/CustomElementRegistry.h +++ b/Source/WebCore/dom/CustomElementRegistry.h @@ -70,7 +70,7 @@ class CustomElementRegistry : public RefCounted, public C bool containsConstructor(const JSC::JSObject*) const; JSC::JSValue get(const AtomString&); - JSC::JSValue getName(JSC::JSGlobalObject&, JSC::JSValue); + String getName(JSC::JSValue); void upgrade(Node& root); MemoryCompactRobinHoodHashMap>& promiseMap() { return m_promiseMap; } diff --git a/Source/WebCore/dom/CustomElementRegistry.idl b/Source/WebCore/dom/CustomElementRegistry.idl index e03c6fbd9f118..f3c27b1ad68db 100644 --- a/Source/WebCore/dom/CustomElementRegistry.idl +++ b/Source/WebCore/dom/CustomElementRegistry.idl @@ -32,8 +32,7 @@ [CEReactions=Needed, Custom] undefined define(DOMString name, Function constructor); any get([AtomString] DOMString name); - // FIXME: This should return (DOMString or undefined). See webkit.org/b/232734. - [CallWith=CurrentGlobalObject] any getName(any constructor); + DOMString? getName(any constructor); [Custom, ReturnsOwnPromise] Promise whenDefined(DOMString name); [CEReactions=Needed] undefined upgrade(Node root);