From 0afe028ab60c8866c5a2237f8442e17a1ce19214 Mon Sep 17 00:00:00 2001 From: "aiunusov@mozilla.com" Date: Wed, 21 May 2025 11:20:46 +0000 Subject: [PATCH] Bug 1967608 - Make all prefs accessed by worker thread atomic, r=smaug Differential Revision: https://phabricator.services.mozilla.com/D250349 --- dom/base/TimeoutManager.cpp | 6 +++--- dom/workers/WorkerPrivate.cpp | 7 +++---- modules/libpref/init/StaticPrefList.yaml | 8 ++++---- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/dom/base/TimeoutManager.cpp b/dom/base/TimeoutManager.cpp index dd8ec0537ad2..e37fc282d518 100644 --- a/dom/base/TimeoutManager.cpp +++ b/dom/base/TimeoutManager.cpp @@ -322,7 +322,7 @@ TimeDuration TimeoutManager::CalculateDelay(Timeout* aTimeout) const { TimeDuration result = aTimeout->mInterval; if (aTimeout->mNestingLevel >= - StaticPrefs::dom_clamp_timeout_nesting_level_AtStartup()) { + StaticPrefs::dom_clamp_timeout_nesting_level()) { uint32_t minTimeoutValue = StaticPrefs::dom_min_timeout_value(); result = TimeDuration::Max(result, TimeDuration::FromMilliseconds(minTimeoutValue)); @@ -529,7 +529,7 @@ nsresult TimeoutManager::SetTimeout(TimeoutHandler* aHandler, int32_t interval, const uint32_t nestingLevel{mIsWindow ? GetNestingLevelForWindow() : GetNestingLevelForWorker()}; timeout->mNestingLevel = - nestingLevel < StaticPrefs::dom_clamp_timeout_nesting_level_AtStartup() + nestingLevel < StaticPrefs::dom_clamp_timeout_nesting_level() ? nestingLevel + 1 : nestingLevel; } @@ -1039,7 +1039,7 @@ bool TimeoutManager::RescheduleTimeout(Timeout* aTimeout, // Automatically increase the nesting level when a setInterval() // is rescheduled just as if it was using a chained setTimeout(). if (aTimeout->mNestingLevel < - StaticPrefs::dom_clamp_timeout_nesting_level_AtStartup()) { + StaticPrefs::dom_clamp_timeout_nesting_level()) { aTimeout->mNestingLevel += 1; } diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index 6b1649723ee0..e19f398e2672 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -1094,18 +1094,17 @@ struct WorkerPrivate::TimeoutInfo { } void AccumulateNestingLevel(const uint32_t& aBaseLevel) { - if (aBaseLevel < StaticPrefs::dom_clamp_timeout_nesting_level_AtStartup()) { + if (aBaseLevel < StaticPrefs::dom_clamp_timeout_nesting_level()) { mNestingLevel = aBaseLevel + 1; return; } - mNestingLevel = StaticPrefs::dom_clamp_timeout_nesting_level_AtStartup(); + mNestingLevel = StaticPrefs::dom_clamp_timeout_nesting_level(); } void CalculateTargetTime() { auto target = mInterval; // Don't clamp timeout for chrome workers - if (mNestingLevel >= - StaticPrefs::dom_clamp_timeout_nesting_level_AtStartup() && + if (mNestingLevel >= StaticPrefs::dom_clamp_timeout_nesting_level() && !mOnChromeWorker) { target = TimeDuration::Max( mInterval, diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index fc437b0c2e49..bf84aaf4576e 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -2528,9 +2528,9 @@ # HTML specification says the level should be 5 # https://html.spec.whatwg.org/#timer-initialisation-steps - name: dom.clamp.timeout.nesting.level - type: uint32_t + type: RelaxedAtomicUint32 value: 5 - mirror: once + mirror: always # Skip the security checks for document.cookie. - name: dom.cookie.testing.enabled @@ -3537,13 +3537,13 @@ # Timeout clamp in ms for background windows. - name: dom.min_background_timeout_value - type: int32_t + type: RelaxedAtomicInt32 value: 1000 mirror: always # Timeout clamp in ms for background windows when throttling isn't enabled. - name: dom.min_background_timeout_value_without_budget_throttling - type: int32_t + type: RelaxedAtomicInt32 value: 1000 mirror: always