Issue #2453 - Don't try to directly access pref on worker thread.

This commit is contained in:
Moonchild 2024-01-15 15:10:31 +01:00 committed by roytam1
commit 4f83e877a8
2 changed files with 20 additions and 5 deletions

View file

@ -26,6 +26,7 @@ WORKER_SIMPLE_PREF("browser.dom.window.dump.enabled", DumpEnabled, DUMP)
WORKER_SIMPLE_PREF("canvas.imagebitmap_extensions.enabled", ImageBitmapExtensionsEnabled, IMAGEBITMAP_EXTENSIONS_ENABLED)
WORKER_SIMPLE_PREF("dom.caches.enabled", DOMCachesEnabled, DOM_CACHES)
WORKER_SIMPLE_PREF("dom.caches.testing.enabled", DOMCachesTestingEnabled, DOM_CACHES_TESTING)
WORKER_SIMPLE_PREF("dom.min_timeout_value", DOMMinTimoutValue, DOM_MIN_TIMEOUT_VALUE)
WORKER_SIMPLE_PREF("dom.performance.enable_user_timing_logging", PerformanceLoggingEnabled, PERFORMANCE_LOGGING_ENABLED)
WORKER_SIMPLE_PREF("dom.webnotifications.enabled", DOMWorkerNotificationEnabled, DOM_WORKERNOTIFICATION)
WORKER_SIMPLE_PREF("dom.webnotifications.serviceworker.enabled", DOMServiceWorkerNotificationEnabled, DOM_SERVICEWORKERNOTIFICATION)

View file

@ -1995,13 +1995,27 @@ struct WorkerPrivate::TimeoutInfo
mNestingLevel = kClampTimeoutNestingLevel;
}
void CalculateTargetTime() {
void CalculateTargetTime(JSContext* aCx) {
auto target = mInterval;
int32_t minTimeoutValue;
if (NS_IsMainThread()) {
// We can get the pref value directly.
minTimeoutValue = Preferences::GetInt("dom.min_timeout_value");
} else {
// We're on a worker thread; go through WorkerPrivate.
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
if (workerPrivate) {
minTimeoutValue = workerPrivate->DOMMinTimoutValue();
} else {
// fall back to default 4 ms
minTimeoutValue = 4;
}
}
// Clamp timeout for workers, except chrome workers
if (mNestingLevel >= kClampTimeoutNestingLevel && !mOnChromeWorker) {
target = TimeDuration::Max(
mInterval,
TimeDuration::FromMilliseconds(Preferences::GetInt("dom.min_timeout_value")));
target = TimeDuration::Max(mInterval,TimeDuration::FromMilliseconds(minTimeoutValue));
}
mTargetTime = TimeStamp::Now() + target;
}
@ -6387,7 +6401,7 @@ WorkerPrivate::RunExpiredTimeouts(JSContext* aCx)
// Reschedule intervals.
// Reschedule a timeout and, if needed, increase the nesting level.
info->AccumulateNestingLevel(info->mNestingLevel);
info->CalculateTargetTime();
info->CalculateTargetTime(aCx);
// Don't re-sort the list here, we'll do that at the end.
++index;
}