From 3cd3acc695477450a1e73067f5cb7675afee72c9 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Tue, 19 Mar 2019 20:52:03 +0000 Subject: [PATCH] Bug 1535384 part 8. Remove MOZ_CAN_RUN_SCRIPT_BOUNDARY for Web IDL Function. r=mccr8 Differential Revision: https://phabricator.services.mozilla.com/D23779 --HG-- extra : moz-landing-system : lando --- dom/base/TimeoutExecutor.cpp | 9 ++++++--- dom/base/TimeoutExecutor.h | 2 +- dom/base/TimeoutManager.cpp | 14 +++++++------- dom/base/TimeoutManager.h | 1 + dom/base/nsGlobalWindowInner.cpp | 2 ++ dom/base/nsGlobalWindowInner.h | 1 + dom/webidl/Function.webidl | 1 - dom/workers/WorkerPrivate.cpp | 7 +++++-- dom/workers/WorkerPrivate.h | 2 +- 9 files changed, 24 insertions(+), 15 deletions(-) diff --git a/dom/base/TimeoutExecutor.cpp b/dom/base/TimeoutExecutor.cpp index 3f6070f849d8..921ead0ccbae 100644 --- a/dom/base/TimeoutExecutor.cpp +++ b/dom/base/TimeoutExecutor.cpp @@ -221,8 +221,9 @@ void TimeoutExecutor::Cancel() { mDeadline = TimeStamp(); } -NS_IMETHODIMP -TimeoutExecutor::Run() { +// MOZ_CAN_RUN_SCRIPT_BOUNDARY until Runnable::Run is MOZ_CAN_RUN_SCRIPT. See +// bug 1535398. +MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHODIMP TimeoutExecutor::Run() { // If the executor is canceled and then rescheduled its possible to get // spurious executions here. Ignore these unless our current mode matches. MOZ_LOG(gTimeoutLog, LogLevel::Debug, @@ -233,7 +234,9 @@ TimeoutExecutor::Run() { return NS_OK; } -NS_IMETHODIMP +// MOZ_CAN_RUN_SCRIPT_BOUNDARY until nsITimerCallback::Notify is +// MOZ_CAN_RUN_SCRIPT. +MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHODIMP TimeoutExecutor::Notify(nsITimer* aTimer) { // If the executor is canceled and then rescheduled its possible to get // spurious executions here. Ignore these unless our current mode matches. diff --git a/dom/base/TimeoutExecutor.h b/dom/base/TimeoutExecutor.h index 28b231e9e9f2..bbee3718dc81 100644 --- a/dom/base/TimeoutExecutor.h +++ b/dom/base/TimeoutExecutor.h @@ -66,7 +66,7 @@ class TimeoutExecutor final : public nsIRunnable, nsresult MaybeReschedule(const TimeStamp& aDeadline, const TimeDuration& aMinDelay); - void MaybeExecute(); + MOZ_CAN_RUN_SCRIPT void MaybeExecute(); public: TimeoutExecutor(TimeoutManager* aOwner, bool aIsIdleQueue, diff --git a/dom/base/TimeoutManager.cpp b/dom/base/TimeoutManager.cpp index 53799666140c..3f9798c7c087 100644 --- a/dom/base/TimeoutManager.cpp +++ b/dom/base/TimeoutManager.cpp @@ -741,11 +741,10 @@ void TimeoutManager::RunTimeout(const TimeStamp& aNow, // Make sure that the window and the script context don't go away as // a result of running timeouts - nsCOMPtr windowKungFuDeathGrip(&mWindow); - // Silence the static analysis error about windowKungFuDeathGrip. Accessing - // members of mWindow here is safe, because the lifetime of TimeoutManager is - // the same as the lifetime of the containing nsGlobalWindow. - Unused << windowKungFuDeathGrip; + RefPtr window(&mWindow); + // Accessing members of mWindow here is safe, because the lifetime of + // TimeoutManager is the same as the lifetime of the containing + // nsGlobalWindow. // A native timer has gone off. See which of our timeouts need // servicing @@ -976,8 +975,9 @@ void TimeoutManager::RunTimeout(const TimeStamp& aNow, MOZ_ASSERT(timeout->mFiringIndex > mLastFiringIndex); mLastFiringIndex = timeout->mFiringIndex; #endif - // This timeout is good to run - bool timeout_was_cleared = mWindow.RunTimeoutHandler(timeout, scx); + // This timeout is good to run. + bool timeout_was_cleared = + window->RunTimeoutHandler(timeout, scx); #if MOZ_GECKO_PROFILER if (profiler_is_active()) { TimeDuration elapsed = now - timeout->SubmitTime(); diff --git a/dom/base/TimeoutManager.h b/dom/base/TimeoutManager.h index cd03a7ecb1e2..682bb3aaec43 100644 --- a/dom/base/TimeoutManager.h +++ b/dom/base/TimeoutManager.h @@ -52,6 +52,7 @@ class TimeoutManager final { bool aIsIdle); // The timeout implementation functions. + MOZ_CAN_RUN_SCRIPT void RunTimeout(const TimeStamp& aNow, const TimeStamp& aTargetDeadline, bool aProcessIdle); diff --git a/dom/base/nsGlobalWindowInner.cpp b/dom/base/nsGlobalWindowInner.cpp index 36c1d5d810c0..161f5bea26a5 100644 --- a/dom/base/nsGlobalWindowInner.cpp +++ b/dom/base/nsGlobalWindowInner.cpp @@ -5559,6 +5559,8 @@ bool nsGlobalWindowInner::RunTimeoutHandler(Timeout* aTimeout, nsIScriptContext* aScx) { // Hold on to the timeout in case mExpr or mFunObj releases its // doc. + // XXXbz Our caller guarantees it'll hold on to the timeout (because + // we're MOZ_CAN_RUN_SCRIPT), so we can probably stop doing that... RefPtr timeout = aTimeout; Timeout* last_running_timeout = mTimeoutManager->BeginRunningTimeout(timeout); timeout->mRunning = true; diff --git a/dom/base/nsGlobalWindowInner.h b/dom/base/nsGlobalWindowInner.h index 96a244d70fbc..3c384005729b 100644 --- a/dom/base/nsGlobalWindowInner.h +++ b/dom/base/nsGlobalWindowInner.h @@ -1053,6 +1053,7 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget, mozilla::ErrorResult& aError); // Return true if |aTimeout| was cleared while its handler ran. + MOZ_CAN_RUN_SCRIPT bool RunTimeoutHandler(mozilla::dom::Timeout* aTimeout, nsIScriptContext* aScx); diff --git a/dom/webidl/Function.webidl b/dom/webidl/Function.webidl index 533804a10241..4312c24d39be 100644 --- a/dom/webidl/Function.webidl +++ b/dom/webidl/Function.webidl @@ -10,7 +10,6 @@ * Opera Software ASA. You are granted a license to use, reproduce * and create derivative works of this document. */ -[MOZ_CAN_RUN_SCRIPT_BOUNDARY] callback Function = any(any... arguments); callback VoidFunction = void (); diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index da3def115cb8..7cbf482de866 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -551,6 +551,9 @@ class TimerRunnable final : public WorkerRunnable, // Silence bad assertions. } + // MOZ_CAN_RUN_SCRIPT_BOUNDARY until worker runnables are generally + // MOZ_CAN_RUN_SCRIPT. + MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual bool WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override { return aWorkerPrivate->RunExpiredTimeouts(aCx); @@ -4267,8 +4270,8 @@ bool WorkerPrivate::RunExpiredTimeouts(JSContext* aCx) { } else { ErrorResult rv; JS::Rooted ignoredVal(aCx); - callback->Call(GlobalScope(), info->mHandler->GetArgs(), &ignoredVal, rv, - reason); + RefPtr scope = GlobalScope(); + callback->Call(scope, info->mHandler->GetArgs(), &ignoredVal, rv, reason); if (rv.IsUncatchableException()) { rv.SuppressException(); retval = false; diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h index 1fdd130474dd..044e97736220 100644 --- a/dom/workers/WorkerPrivate.h +++ b/dom/workers/WorkerPrivate.h @@ -254,7 +254,7 @@ class WorkerPrivate : public RelativeTimeline { void ClearTimeout(int32_t aId); - bool RunExpiredTimeouts(JSContext* aCx); + MOZ_CAN_RUN_SCRIPT bool RunExpiredTimeouts(JSContext* aCx); bool RescheduleTimeoutTimer(JSContext* aCx);