mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 00:19:53 +01:00
LibWeb: Ensure Noah's Ark clause is called in the Parser
This commit is contained in:
parent
102edf638d
commit
6f31d9a40d
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
namespace Web::HTML {
|
||||
|
||||
static constexpr size_t NoahsArkCapacity = 3;
|
||||
ListOfActiveFormattingElements::~ListOfActiveFormattingElements() = default;
|
||||
|
||||
void ListOfActiveFormattingElements::visit_edges(JS::Cell::Visitor& visitor)
|
||||
|
|
@ -17,9 +18,46 @@ void ListOfActiveFormattingElements::visit_edges(JS::Cell::Visitor& visitor)
|
|||
visitor.visit(entry.element);
|
||||
}
|
||||
|
||||
void ListOfActiveFormattingElements::ensure_noahs_ark_clause(DOM::Element& element)
|
||||
{
|
||||
Vector<Entry> possible_matches;
|
||||
for (size_t i = m_entries.size(); i > 0;) {
|
||||
i--;
|
||||
auto& entry = m_entries[i];
|
||||
if (entry.is_marker())
|
||||
break;
|
||||
if (entry.element->local_name() == element.local_name()
|
||||
&& entry.element->namespace_uri() == element.namespace_uri()
|
||||
&& entry.element->attribute_list_size() == element.attribute_list_size())
|
||||
possible_matches.append(entry);
|
||||
}
|
||||
|
||||
if (possible_matches.size() < NoahsArkCapacity)
|
||||
return;
|
||||
|
||||
// FIXME: the attributes should be compared as they where created by the parser
|
||||
element.for_each_attribute([&](auto& name, auto& value) {
|
||||
possible_matches.remove_all_matching([&](auto& entry) {
|
||||
auto attr = entry.element->get_attribute(name);
|
||||
return !attr.has_value() || attr != value;
|
||||
});
|
||||
});
|
||||
|
||||
if (possible_matches.size() < NoahsArkCapacity)
|
||||
return;
|
||||
|
||||
remove(*possible_matches.last().element);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/parsing.html#push-onto-the-list-of-active-formatting-elements
|
||||
void ListOfActiveFormattingElements::add(DOM::Element& element)
|
||||
{
|
||||
// FIXME: Implement the Noah's Ark clause https://html.spec.whatwg.org/multipage/parsing.html#push-onto-the-list-of-active-formatting-elements
|
||||
// 1. If there are already three elements in the list of active formatting elements after the last marker, if any, or anywhere in the list if there are no markers,
|
||||
// that have the same tag name, namespace, and attributes as element, then remove the earliest such element from the list of active formatting elements.
|
||||
// For these purposes, the attributes must be compared as they were when the elements were created by the parser; two elements have the same attributes if all their parsed attributes
|
||||
// can be paired such that the two attributes in each pair have identical names, namespaces, and values (the order of the attributes does not matter).
|
||||
ensure_noahs_ark_clause(element);
|
||||
// 2. Add element to the list of active formatting elements.
|
||||
m_entries.append({ element });
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ public:
|
|||
|
||||
private:
|
||||
Vector<Entry> m_entries;
|
||||
void ensure_noahs_ark_clause(DOM::Element& element);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@ Harness status: OK
|
|||
|
||||
Found 17 tests
|
||||
|
||||
16 Pass
|
||||
1 Fail
|
||||
17 Pass
|
||||
Pass html5lib_adoption01.html dab5eca760a630bc57719d678d789dd1ca74f492
|
||||
Pass html5lib_adoption01.html a3a46907dc73b7be1e1171f797a9f696b7fb185b
|
||||
Pass html5lib_adoption01.html b720cd1d95283d6288e7ca17142540b10ef8f847
|
||||
|
|
@ -20,4 +19,4 @@ Pass html5lib_adoption01.html 52b62611a847a3f5fc3dc607a6b0174f1697247c
|
|||
Pass html5lib_adoption01.html 88d0d3403d2a7b4058fcfb4e62835acb1c207e0f
|
||||
Pass html5lib_adoption01.html d7338f457789f65d47b240e203b9e40a3925f2ca
|
||||
Pass html5lib_adoption01.html bf8088acd8bd48d8487bae49a613c248c488c041
|
||||
Fail html5lib_adoption01.html 39edaa2e298c60ad4a1b0b9fdb4481d4aea98f36
|
||||
Pass html5lib_adoption01.html 39edaa2e298c60ad4a1b0b9fdb4481d4aea98f36
|
||||
|
|
@ -2,10 +2,9 @@ Harness status: OK
|
|||
|
||||
Found 5 tests
|
||||
|
||||
2 Pass
|
||||
3 Fail
|
||||
Fail html5lib_tests23.html 79c0dc8da653d983d07795852b5f38d1533ff404
|
||||
Fail html5lib_tests23.html 403404388390abddf3fb44db8dd7d643652f5df9
|
||||
Fail html5lib_tests23.html b9a81ae44ab81719fc6a4e3b6460fc6efc684e65
|
||||
5 Pass
|
||||
Pass html5lib_tests23.html 79c0dc8da653d983d07795852b5f38d1533ff404
|
||||
Pass html5lib_tests23.html 403404388390abddf3fb44db8dd7d643652f5df9
|
||||
Pass html5lib_tests23.html b9a81ae44ab81719fc6a4e3b6460fc6efc684e65
|
||||
Pass html5lib_tests23.html d271d3662baafff4893d32b250cadcf4c2ff3352
|
||||
Pass html5lib_tests23.html f8e296b2f362a64c1c464bedd6248e314f41c701
|
||||
Loading…
Reference in New Issue
Block a user