LibWeb: Add and remove MutationObservers at specified times

In the current spec, MutationObservers are explicitly added to the
pending mutation observers list, and they are removed when that list is
cleared in the "notify mutation observers" microtask.

This solves some issues with slotchange events.

As noted, we delay actually emptying the list of pending mutation
observers until after we're finished with the "clone", because we can't
actually copy or move the intrusive list. As far as I am aware, this
should not affect behaviour because only one microtask can run at once.
This commit is contained in:
Sam Atkins 2025-11-21 12:35:36 +00:00 committed by Andreas Kling
parent 37f49d5f6d
commit 6e17503423
Notes: github-actions[bot] 2025-11-21 15:21:13 +00:00
6 changed files with 39 additions and 34 deletions

View file

@ -29,7 +29,7 @@ struct SimilarOriginWindowAgent : public Agent {
// https://dom.spec.whatwg.org/#mutation-observer-list
// Each similar-origin window agent also has pending mutation observers (a set of zero or more MutationObserver objects), which is initially empty.
DOM::MutationObserver::List mutation_observers;
DOM::MutationObserver::List pending_mutation_observers;
// https://html.spec.whatwg.org/multipage/custom-elements.html#custom-element-reactions-stack
// Each similar-origin window agent has a custom element reactions stack, which is initially empty.