Merge remote-tracking branch 'origin/tracking' into custom

This commit is contained in:
roytam1 2024-02-23 10:53:26 +08:00
commit 1804fcb5d1
10 changed files with 36 additions and 166 deletions

View file

@ -26,7 +26,6 @@ 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", DOMMinTimeoutValue, 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

@ -171,6 +171,8 @@ const nsIID kDEBUGWorkerEventTargetIID = {
// The number of nested timeouts before we start clamping. HTML says 5.
const uint32_t kClampTimeoutNestingLevel = 5u;
// The minimum interval we clamp timers in workers to. HTML says 4ms.
const uint32_t kClampTimeoutInterval = 4u;
template <class T>
class AutoPtrComparator
@ -1997,20 +1999,10 @@ struct WorkerPrivate::TimeoutInfo
void CalculateTargetTime(JSContext* aCx) {
auto target = mInterval;
int32_t minTimeoutValue;
// We're on a worker thread; go through WorkerPrivate for the pref.
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
if (workerPrivate) {
minTimeoutValue = workerPrivate->DOMMinTimeoutValue();
} 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(minTimeoutValue));
target = TimeDuration::Max(mInterval, TimeDuration::FromMilliseconds(kClampTimeoutInterval));
}
mTargetTime = TimeStamp::Now() + target;
}
@ -5169,7 +5161,9 @@ WorkerPrivate::ScheduleDeletion(WorkerRanOrNot aRanOrNot)
if (WorkerRan == aRanOrNot) {
nsIThread* currentThread = NS_GetCurrentThread();
MOZ_ASSERT(currentThread);
MOZ_ASSERT(!NS_HasPendingEvents(currentThread));
// On the worker thread WorkerRunnable will refuse to run if not nested
// on top of a WorkerThreadPrimaryRunnable.
Unused << NS_WARN_IF(NS_HasPendingEvents(currentThread));
}
#endif

View file

@ -11,6 +11,7 @@
#include "nsIRunnable.h"
#include "nsThreadUtils.h"
#include "mozilla/CycleCollectedJSContext.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/Unused.h"
@ -231,6 +232,19 @@ WorkerRunnable::Run()
bool targetIsWorkerThread = mBehavior == WorkerThreadModifyBusyCount ||
mBehavior == WorkerThreadUnchangedBusyCount;
if (targetIsWorkerThread) {
// On a worker thread, a WorkerRunnable should only run when there is an
// underlying WorkerThreadPrimaryRunnable active, which means we should
// find a CycleCollectedJSContext.
if (!CycleCollectedJSContext::Get()) {
MOZ_DIAGNOSTIC_ASSERT(false,
"A WorkerRunnable was executed after "
"WorkerThreadPrimaryRunnable ended.");
return NS_OK;
}
}
#ifdef DEBUG
MOZ_ASSERT_IF(mCallingCancelWithinRun, targetIsWorkerThread);
if (targetIsWorkerThread) {