From 14b7123a72f6fd97cc315b4aeb1cdb8756335691 Mon Sep 17 00:00:00 2001 From: Cameron Kaiser Date: Tue, 6 Feb 2018 14:32:06 -0800 Subject: [PATCH] #463: add IdleRequestCallback to nsTimeout --- dom/base/nsGlobalWindow.cpp | 22 +++++++++++++++++++++- dom/base/nsGlobalWindow.h | 9 +++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index f8bf14a4f..1032c4b33 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -11537,10 +11537,20 @@ nsGlobalWindow::SetInterval(JSContext* aCx, const nsAString& aHandler, return SetTimeoutOrInterval(aCx, aHandler, timeout, isInterval, aError); } +// TenFourFox issue 463 nsresult nsGlobalWindow::SetTimeoutOrInterval(nsIScriptTimeoutHandler *aHandler, int32_t interval, bool aIsInterval, int32_t *aReturn) +{ + return SetTimeoutOrIntervalOrIdleCallback(aHandler, interval, aIsInterval, aReturn, nullptr); +} + +nsresult +nsGlobalWindow::SetTimeoutOrIntervalOrIdleCallback(nsIScriptTimeoutHandler *aHandler, + int32_t interval, + bool aIsInterval, int32_t *aReturn, + mozilla::dom::IdleRequestCallback *aCallback) { MOZ_ASSERT(IsInnerWindow()); @@ -11565,7 +11575,10 @@ nsGlobalWindow::SetTimeoutOrInterval(nsIScriptTimeoutHandler *aHandler, RefPtr timeout = new nsTimeout(); timeout->mIsInterval = aIsInterval; timeout->mInterval = interval; - timeout->mScriptHandler = aHandler; + if (aCallback) + timeout->mCallback = aCallback; + else + timeout->mScriptHandler = aHandler; // Now clamp the actual interval we will use for the timer based on uint32_t nestingLevel = sNestingLevel + 1; @@ -11754,6 +11767,13 @@ nsGlobalWindow::RunTimeoutHandler(nsTimeout* aTimeout, reason = "setTimeout handler"; } + if (!timeout->mScriptHandler) { + // Time to assess the conditions for requestIdleCallback (issue 463). + MOZ_ASSERT(timeout->mCallback); + MOZ_CRASH("RunTimeoutHandler triggered on requestIdleCallback"); + return false; + } + nsCOMPtr handler(timeout->mScriptHandler); RefPtr callback = handler->GetCallback(); if (!callback) { diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index 41d1b65e4..025b261fa 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -211,7 +211,10 @@ public: PopupControlState mPopupState; // The language-specific information about the callback. + // If there is an nsIScriptTimeoutHandler, this is a regular setTimeout. + // If there is an IdleRequestCallback, this is requestIdleCallback (issue 463). nsCOMPtr mScriptHandler; + RefPtr mCallback; }; struct IdleObserverHolder @@ -1411,6 +1414,12 @@ public: nsresult SetTimeoutOrInterval(nsIScriptTimeoutHandler *aHandler, int32_t interval, bool aIsInterval, int32_t* aReturn) override; + // TenFourFox issue 463 + nsresult SetTimeoutOrIntervalOrIdleCallback(nsIScriptTimeoutHandler *aHandler, + int32_t interval, + bool aIsInterval, int32_t *aReturn, + mozilla::dom::IdleRequestCallback *aCallback); + int32_t SetTimeoutOrInterval(JSContext* aCx, mozilla::dom::Function& aFunction, int32_t aTimeout,