summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-12-15 20:04:44 +0100
committerAndreas Kling <kling@serenityos.org>2022-12-16 09:58:03 +0100
commit346737701d8f00afcc601e2e3e1d735e30a487f1 (patch)
tree1f7e30b696beacc6f29cf54a57a65b559217ec3f /Userland/Libraries
parent2d791cf90f5533517381f140ac6e2af05cead7f4 (diff)
downloadserenity-346737701d8f00afcc601e2e3e1d735e30a487f1.zip
LibWeb: Allow setting HTMLTableElement.tHead to null value
This deals with 2 FIXMEs :^)
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp21
1 files changed, 15 insertions, 6 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp
index 77e655f372..a8c7342fc3 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp
@@ -93,8 +93,11 @@ void HTMLTableElement::delete_caption()
}
}
+// https://html.spec.whatwg.org/multipage/tables.html#dom-table-thead
JS::GCPtr<HTMLTableSectionElement> HTMLTableElement::t_head()
{
+ // The tHead IDL attribute must return, on getting, the first thead element child of the table element,
+ // if any, or null otherwise.
for (auto* child = first_child(); child; child = child->next_sibling()) {
if (is<HTMLTableSectionElement>(*child)) {
auto table_section_element = &verify_cast<HTMLTableSectionElement>(*child);
@@ -106,18 +109,24 @@ JS::GCPtr<HTMLTableSectionElement> HTMLTableElement::t_head()
return nullptr;
}
+// https://html.spec.whatwg.org/multipage/tables.html#dom-table-thead
WebIDL::ExceptionOr<void> HTMLTableElement::set_t_head(HTMLTableSectionElement* thead)
{
- // FIXME: This is not always the case, but this function is currently written in a way that assumes non-null.
- VERIFY(thead);
-
- if (thead->local_name() != TagNames::thead)
+ // If the new value is neither null nor a thead element, then a "HierarchyRequestError" DOMException must be thrown instead.
+ if (thead && thead->local_name() != TagNames::thead)
return WebIDL::HierarchyRequestError::create(realm(), "Element is not thead");
- // FIXME: The spec requires deleting the current thead if thead is null
- // Currently the wrapper generator doesn't send us a nullable value
+ // On setting, if the new value is null or a thead element, the first thead element child of the table element,
+ // if any, must be removed,
delete_t_head();
+ if (!thead)
+ return {};
+
+ // and the new value, if not null, must be inserted immediately before the first element in the table element
+ // that is neither a caption element nor a colgroup element, if any,
+ // or at the end of the table if there are no such elements.
+
// We insert the new thead after any <caption> or <colgroup> elements
DOM::Node* child_to_append_after = nullptr;
for (auto* child = first_child(); child; child = child->next_sibling()) {