tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 51cc426eea79efa05a86e08a216119e387ac3f45
parent 213b6265c1bbd3cbe0f5bf6a1a774345de620713
Author: Timothy Nikkel <tnikkel@gmail.com>
Date:   Thu,  8 Jan 2026 04:34:48 +0000

Bug 2008698. Don't hold an entry in the AsyncScrollsWithAnchorHashmap hash table while we can modify the hashtable elsewhere. r=hiro,layout-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D278067

Diffstat:
Mlayout/base/DisplayPortUtils.cpp | 45+++++++++++++++++++++++----------------------
1 file changed, 23 insertions(+), 22 deletions(-)

diff --git a/layout/base/DisplayPortUtils.cpp b/layout/base/DisplayPortUtils.cpp @@ -1394,28 +1394,29 @@ bool DisplayPortUtils::ShouldAsyncScrollWithAnchor( MOZ_ASSERT(!aAxes.isEmpty()); // ShouldAsyncScrollWithAnchorNotCached can call recursively and modify - // AsyncScrollsWithAnchorHashmap, so we use this to only do one hashtable - // lookup and only call ShouldAsyncScrollWithAnchorNotCached if not already - // present in the hashtable. - bool wasPresent = true; - auto& entry = aBuilder->AsyncScrollsWithAnchorHashmap().LookupOrInsertWith( - aFrame, [&]() { - wasPresent = false; - return true; - }); - if (!wasPresent) { - bool reportToDoc = false; - entry = ShouldAsyncScrollWithAnchorNotCached(aFrame, aAnchor, aBuilder, - aAxes, &reportToDoc); - if (!entry && reportToDoc) { - auto* pc = aFrame->PresContext(); - pc->Document()->ReportHasScrollLinkedEffect( - pc->RefreshDriver()->MostRecentRefresh(), - dom::Document::ReportToConsole::No); - } - } - - return entry; + // AsyncScrollsWithAnchorHashmap, so we have to be careful to not hold an + // entry in the hashtable during a call to + // ShouldAsyncScrollWithAnchorNotCached. Unfortunately this means that we have + // to do two hashtable lookups if the frame is not present in the hashtable. + if (auto entry = aBuilder->AsyncScrollsWithAnchorHashmap().Lookup(aFrame)) { + return *entry; + } + bool reportToDoc = false; + bool shouldAsyncScrollWithAnchor = ShouldAsyncScrollWithAnchorNotCached( + aFrame, aAnchor, aBuilder, aAxes, &reportToDoc); + { + bool& entry = + aBuilder->AsyncScrollsWithAnchorHashmap().LookupOrInsert(aFrame); + entry = shouldAsyncScrollWithAnchor; + } + if (reportToDoc) { + auto* pc = aFrame->PresContext(); + pc->Document()->ReportHasScrollLinkedEffect( + pc->RefreshDriver()->MostRecentRefresh(), + dom::Document::ReportToConsole::No); + } + + return shouldAsyncScrollWithAnchor; } } // namespace mozilla