From 89cd00b540cfe36d86a402501efc4f48c4b436af Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 7 Feb 2022 02:10:03 +0100 Subject: [PATCH] LibWeb: Fix broken step 4.3 implementation in run_focus_update_steps() Some over-eager copy-pasting led to incorrect code for the new chain. --- .../Libraries/LibWeb/HTML/HTMLElement.cpp | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp index a652d6acf5..296e2b07e0 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp @@ -217,9 +217,11 @@ static void run_focus_update_steps(NonnullRefPtrVector old_chain, Non // then let related blur target be the last entry in new chain. // Otherwise, let related blur target be null. RefPtr related_blur_target; - if (&entry == &old_chain.last() + if (!old_chain.is_empty() + && &entry == &old_chain.last() && is(entry) - && (!new_chain.is_empty() && is(new_chain.last()))) { + && !new_chain.is_empty() + && is(new_chain.last())) { related_blur_target = new_chain.last(); } @@ -255,15 +257,17 @@ static void run_focus_update_steps(NonnullRefPtrVector old_chain, Non focus_event_target = static_cast(entry).window(); } - // 3. If entry is the last entry in old chain, and entry is an Element, - // and the last entry in new chain is also an Element, - // then let related focus target be the last entry in new chain. + // 3. If entry is the last entry in new chain, and entry is an Element, + // and the last entry in old chain is also an Element, + // then let related focus target be the last entry in old chain. // Otherwise, let related focus target be null. RefPtr related_focus_target; - if (&entry == &old_chain.last() + if (!new_chain.is_empty() + && &entry == &new_chain.last() && is(entry) - && (!new_chain.is_empty() && is(new_chain.last()))) { - related_focus_target = new_chain.last(); + && !old_chain.is_empty() + && is(old_chain.last())) { + related_focus_target = old_chain.last(); } // 4. If focus event target is not null, fire a focus event named focus at focus event target,