LibWeb: Verify element namespace in DOM::create_element()

This commit is contained in:
Psychpsyo 2025-01-09 21:36:40 +01:00 committed by Jelle Raaijmakers
parent 00ed797627
commit 19f97472eb
Notes: github-actions[bot] 2025-01-11 22:30:15 +00:00

View file

@ -576,16 +576,18 @@ WebIDL::ExceptionOr<GC::Ref<Element>> create_element(Document& document, FlyStri
// 2. Set result to the result of constructing C, with no arguments.
auto result = TRY(WebIDL::construct(constructor));
// FIXME: 3. Assert: results custom element state and custom element definition are initialized.
// FIXME: 4. Assert: results namespace is the HTML namespace.
// Spec Note: IDL enforces that result is an HTMLElement object, which all use the HTML namespace.
// IDL does not currently convert the object for us, so we will have to do it here.
// NOTE: IDL does not currently convert the object for us, so we will have to do it here.
if (!result.has_value() || !result->is_object() || !is<HTML::HTMLElement>(result->as_object()))
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "HTMLElement"sv);
GC::Ref<HTML::HTMLElement> element = verify_cast<HTML::HTMLElement>(result->as_object());
// FIXME: 3. Assert: results custom element state and custom element definition are initialized.
// 4. Assert: results namespace is the HTML namespace.
// Spec Note: IDL enforces that result is an HTMLElement object, which all use the HTML namespace.
VERIFY(element->namespace_uri() == Namespace::HTML);
// 5. If results attribute list is not empty, then throw a "NotSupportedError" DOMException.
if (element->has_attributes())
return JS::throw_completion(WebIDL::NotSupportedError::create(realm, "Synchronously created custom element cannot have attributes"_string));