From efe9ce4bb9f596dd4872f3984a90fa1219beed64 Mon Sep 17 00:00:00 2001 From: roytam1 Date: Tue, 3 Oct 2023 22:33:36 +0800 Subject: [PATCH] import from UXP: Issue #2323 - Part 3: Exclude chrome workers from worker timer clamping. (2ca57151) --- dom/workers/WorkerPrivate.cpp | 6 +++++- dom/workers/WorkerPrivate.h | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index c693ad44a..284592e10 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -1921,6 +1921,7 @@ struct WorkerPrivate::TimeoutInfo , mNestingLevel(0) , mIsInterval(false) , mCanceled(false) + , mOnChromeWorker(false) { MOZ_COUNT_CTOR(mozilla::dom::workers::WorkerPrivate::TimeoutInfo); } @@ -1950,7 +1951,8 @@ struct WorkerPrivate::TimeoutInfo void CalculateTargetTime() { auto target = mInterval; - if (mNestingLevel >= kClampTimeoutNestingLevel) { + // Clamp timeout for workers, except chrome workers + if (mNestingLevel >= kClampTimeoutNestingLevel && !mOnChromeWorker) { target = TimeDuration::Max( mInterval, TimeDuration::FromMilliseconds(Preferences::GetInt("dom.min_timeout_value"))); @@ -1965,6 +1967,7 @@ struct WorkerPrivate::TimeoutInfo uint32_t mNestingLevel; bool mIsInterval; bool mCanceled; + bool mOnChromeWorker; }; class WorkerJSContextStats final : public JS::RuntimeStats @@ -6040,6 +6043,7 @@ WorkerPrivate::SetTimeout(JSContext* aCx, } nsAutoPtr newInfo(new TimeoutInfo()); + newInfo->mOnChromeWorker = mIsChromeWorker; newInfo->mIsInterval = aIsInterval; newInfo->mId = timerId; newInfo->AccumulateNestingLevel(this->mCurrentTimerNestingLevel); diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h index 094168887..9bbeffa11 100644 --- a/dom/workers/WorkerPrivate.h +++ b/dom/workers/WorkerPrivate.h @@ -214,6 +214,9 @@ protected: RefPtr mEventTarget; nsTArray> mPreStartRunnables; + // True if the worker is used in the UI + bool mIsChromeWorker; + private: WorkerPrivate* mParent; nsString mScriptURL; @@ -243,7 +246,6 @@ private: uint32_t mParentWindowPausedDepth; Status mParentStatus; bool mParentFrozen; - bool mIsChromeWorker; bool mMainThreadObjectsForgotten; // mIsSecureContext is set once in our constructor; after that it can be read // from various threads. We could make this const if we were OK with setting