Skip to content

Commit

Permalink
Make getName should return DOMString? instead of DOMString or undefined
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=257759

Reviewed by Chris Dumez.

Update the implementation of CustomElementsRegistry.prototype.getName to match the latest PR.
Namely, it now returns DOMString? instead of (DOMString or undefined):
whatwg/html#9195
web-platform-tests/wpt#39640

* LayoutTests/imported/w3c/web-platform-tests/custom-elements/CustomElementRegistry-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/custom-elements/CustomElementRegistry.html:
* Source/WebCore/dom/CustomElementRegistry.cpp:
(WebCore::CustomElementRegistry::getName):
* Source/WebCore/dom/CustomElementRegistry.h:
* Source/WebCore/dom/CustomElementRegistry.idl:

Canonical link: https://commits.webkit.org/264916@main
  • Loading branch information
rniwa committed Jun 7, 2023
1 parent 50c2756 commit 1515a23
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
8 changes: 4 additions & 4 deletions Source/WebCore/dom/CustomElementRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/dom/CustomElementRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class CustomElementRegistry : public RefCounted<CustomElementRegistry>, 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<AtomString, Ref<DeferredPromise>>& promiseMap() { return m_promiseMap; }
Expand Down
3 changes: 1 addition & 2 deletions Source/WebCore/dom/CustomElementRegistry.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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<undefined> whenDefined(DOMString name);
[CEReactions=Needed] undefined upgrade(Node root);
Expand Down

0 comments on commit 1515a23

Please sign in to comment.