mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:07:35 +00:00
LibWeb: Implement "NodeIterator pre-removing steps"
These steps run when a node is about to be removed from its parent, and adjust the position of any live NodeIterators so that they don't point at a now-removed node. Note that while this commit implements what's in the DOM specification, the specification doesn't fully match what other browsers do. Spec bug: https://github.com/whatwg/dom/issues/907
This commit is contained in:
parent
acbdb95b0a
commit
9c6999ecf2
5 changed files with 91 additions and 2 deletions
|
@ -1037,6 +1037,17 @@ void Document::adopt_node(Node& node)
|
|||
inclusive_descendant.adopted_from(old_document);
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
|
||||
// Transfer NodeIterators rooted at `node` from old_document to this document.
|
||||
Vector<NodeIterator&> node_iterators_to_transfer;
|
||||
for (auto* node_iterator : old_document.m_node_iterators) {
|
||||
if (node_iterator->root() == &node)
|
||||
node_iterators_to_transfer.append(*node_iterator);
|
||||
}
|
||||
for (auto& node_iterator : node_iterators_to_transfer) {
|
||||
old_document.m_node_iterators.remove(&node_iterator);
|
||||
m_node_iterators.set(&node_iterator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1474,4 +1485,16 @@ NonnullRefPtr<TreeWalker> Document::create_tree_walker(Node& root, unsigned what
|
|||
return TreeWalker::create(root, what_to_show, move(filter));
|
||||
}
|
||||
|
||||
void Document::register_node_iterator(Badge<NodeIterator>, NodeIterator& node_iterator)
|
||||
{
|
||||
auto result = m_node_iterators.set(&node_iterator);
|
||||
VERIFY(result == AK::HashSetResult::InsertedNewEntry);
|
||||
}
|
||||
|
||||
void Document::unregister_node_iterator(Badge<NodeIterator>, NodeIterator& node_iterator)
|
||||
{
|
||||
bool was_removed = m_node_iterators.remove(&node_iterator);
|
||||
VERIFY(was_removed);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue