diff --git a/Userland/Libraries/LibWeb/DOM/Slottable.cpp b/Userland/Libraries/LibWeb/DOM/Slottable.cpp index 50b4edcb88..db20e8b285 100644 --- a/Userland/Libraries/LibWeb/DOM/Slottable.cpp +++ b/Userland/Libraries/LibWeb/DOM/Slottable.cpp @@ -25,8 +25,11 @@ void SlottableMixin::visit_edges(JS::Cell::Visitor& visitor) // https://dom.spec.whatwg.org/#dom-slotable-assignedslot JS::GCPtr SlottableMixin::assigned_slot() { - // FIXME: The assignedSlot getter steps are to return the result of find a slot given this and with the open flag set. - return nullptr; + auto* node = dynamic_cast(this); + VERIFY(node); + + // The assignedSlot getter steps are to return the result of find a slot given this and with the open flag set. + return find_a_slot(node->as_slottable(), OpenFlag::Set); } JS::GCPtr assigned_slot_for_node(JS::NonnullGCPtr node) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSlotElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLSlotElement.cpp index e357744bc0..a33fabe86b 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSlotElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLSlotElement.cpp @@ -62,17 +62,41 @@ void HTMLSlotElement::visit_edges(JS::Cell::Visitor& visitor) } // https://html.spec.whatwg.org/multipage/scripting.html#dom-slot-assignednodes -Vector> HTMLSlotElement::assigned_nodes(AssignedNodesOptions) +Vector> HTMLSlotElement::assigned_nodes(AssignedNodesOptions options) { - // FIXME: 1. If options["flatten"] is false, then return this's assigned nodes. + // 1. If options["flatten"] is false, then return this's assigned nodes. + if (!options.flatten) { + Vector> assigned_nodes; + assigned_nodes.ensure_capacity(assigned_nodes_internal().size()); + + for (auto const& node : assigned_nodes_internal()) { + node.visit([&](auto const& node) { + assigned_nodes.unchecked_append(*node); + }); + } + + return assigned_nodes; + } + // FIXME: 2. Return the result of finding flattened slottables with this. return {}; } // https://html.spec.whatwg.org/multipage/scripting.html#dom-slot-assignedelements -Vector> HTMLSlotElement::assigned_elements(AssignedNodesOptions) +Vector> HTMLSlotElement::assigned_elements(AssignedNodesOptions options) { - // FIXME: 1. If options["flatten"] is false, then return this's assigned nodes, filtered to contain only Element nodes. + // 1. If options["flatten"] is false, then return this's assigned nodes, filtered to contain only Element nodes. + if (!options.flatten) { + Vector> assigned_nodes; + + for (auto const& node : assigned_nodes_internal()) { + if (auto const* element = node.get_pointer>()) + assigned_nodes.append(*element); + } + + return assigned_nodes; + } + // FIXME: 2. Return the result of finding flattened slottables with this, filtered to contain only Element nodes. return {}; }