LibWeb: Don't crash if ElementByIdMap already has an element

Let's simply reinsert the element respecting it's new position in the
DOM tree, instead of crashing.

Fixes regression in WPT tests caused by introducion of cache for
getElementById().
This commit is contained in:
Aliaksandr Kalenik 2025-03-27 13:00:32 +00:00 committed by Jelle Raaijmakers
commit 634f0c2469
Notes: github-actions[bot] 2025-03-27 14:45:52 +00:00
3 changed files with 1278 additions and 1 deletions

View file

@ -17,7 +17,9 @@ void ElementByIdMap::add(FlyString const& element_id, Element& element)
return !element.has_value();
});
VERIFY(!elements_with_id.contains_slow(element));
elements_with_id.remove_first_matching([&](auto const& another_element) {
return &element == another_element.ptr();
});
elements_with_id.insert_before_matching(element, [&](auto& another_element) {
return element.is_before(*another_element);
});