Skip to content

Commit

Permalink
LibWeb: Verify element namespace in DOM::create_element()
Browse files Browse the repository at this point in the history
  • Loading branch information
Psychpsyo authored and gmta committed Jan 11, 2025
1 parent 00ed797 commit 19f9747
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Libraries/LibWeb/DOM/ElementFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: result’s custom element state and custom element definition are initialized.
// FIXME: 4. Assert: result’s 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: result’s custom element state and custom element definition are initialized.

// 4. Assert: result’s 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 result’s 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));
Expand Down

0 comments on commit 19f9747

Please sign in to comment.