From 2b410144bf197ea609a67e4c0cc7c883316ad3c1 Mon Sep 17 00:00:00 2001 From: "Carsten \"Tomcat\" Book" Date: Tue, 25 Oct 2016 12:33:00 +0200 Subject: [PATCH] Backed out changeset 24839edcf0ef (bug 1198381) --- dom/base/Timeout.cpp | 2 +- dom/base/Timeout.h | 6 +-- dom/base/moz.build | 1 - dom/base/nsGlobalWindow.cpp | 72 ++++++++++++++---------------- dom/base/nsGlobalWindow.h | 3 +- dom/base/nsIScriptTimeoutHandler.h | 5 ++- dom/base/nsITimeoutHandler.h | 31 ------------- dom/base/nsJSTimeoutHandler.cpp | 17 +------ 8 files changed, 44 insertions(+), 93 deletions(-) delete mode 100644 dom/base/nsITimeoutHandler.h diff --git a/dom/base/Timeout.cpp b/dom/base/Timeout.cpp index ad0114fbe9be..8f66be1fd8a8 100644 --- a/dom/base/Timeout.cpp +++ b/dom/base/Timeout.cpp @@ -7,7 +7,7 @@ #include "Timeout.h" #include "nsGlobalWindow.h" -#include "nsITimeoutHandler.h" +#include "nsIScriptTimeoutHandler.h" #include "nsITimer.h" #include "nsPIDOMWindow.h" diff --git a/dom/base/Timeout.h b/dom/base/Timeout.h index ea3ac3b48a39..0d4be0f080e7 100644 --- a/dom/base/Timeout.h +++ b/dom/base/Timeout.h @@ -14,7 +14,7 @@ class nsGlobalWindow; class nsIPrincipal; -class nsITimeoutHandler; +class nsIScriptTimeoutHandler; class nsITimer; namespace mozilla { @@ -22,7 +22,7 @@ namespace dom { /* * Timeout struct that holds information about each script - * timeout. Holds a strong reference to an nsITimeoutHandler, which + * timeout. Holds a strong reference to an nsIScriptTimeoutHandler, which * abstracts the language specific cruft. */ class Timeout final @@ -85,7 +85,7 @@ public: PopupControlState mPopupState; // The language-specific information about the callback. - nsCOMPtr mScriptHandler; + nsCOMPtr mScriptHandler; private: ~Timeout(); diff --git a/dom/base/moz.build b/dom/base/moz.build index bd55fc5455fa..60c55f97d9e1 100644 --- a/dom/base/moz.build +++ b/dom/base/moz.build @@ -102,7 +102,6 @@ EXPORTS += [ 'nsIScriptObjectPrincipal.h', 'nsIScriptTimeoutHandler.h', 'nsIStyleSheetLinkingElement.h', - 'nsITimeoutHandler.h', 'nsJSEnvironment.h', 'nsJSUtils.h', 'nsLineBreaker.h', diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 38de81af8a33..b7644943bc60 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -41,7 +41,6 @@ #include "nsIPermissionManager.h" #include "nsIScriptContext.h" #include "nsIScriptTimeoutHandler.h" -#include "nsITimeoutHandler.h" #include "nsIController.h" #include "nsScriptNameSpaceManager.h" #include "nsISlowScriptDebug.h" @@ -1999,7 +1998,10 @@ nsGlobalWindow::UnmarkGrayTimers() timeout; timeout = timeout->getNext()) { if (timeout->mScriptHandler) { - timeout->mScriptHandler->MarkForCC(); + Function* f = timeout->mScriptHandler->GetCallback(); + if (f) { + f->MarkForCC(); + } } } } @@ -12057,7 +12059,7 @@ nsGlobalWindow::SetInterval(JSContext* aCx, const nsAString& aHandler, } nsresult -nsGlobalWindow::SetTimeoutOrInterval(nsITimeoutHandler* aHandler, +nsGlobalWindow::SetTimeoutOrInterval(nsIScriptTimeoutHandler* aHandler, int32_t interval, bool aIsInterval, int32_t* aReturn) { @@ -12255,46 +12257,40 @@ nsGlobalWindow::RunTimeoutHandler(Timeout* aTimeout, } bool abortIntervalHandler = false; - nsCOMPtr basicHandler(timeout->mScriptHandler); - nsCOMPtr handler(do_QueryInterface(basicHandler)); - if (handler) { - RefPtr callback = handler->GetCallback(); + nsCOMPtr handler(timeout->mScriptHandler); + RefPtr callback = handler->GetCallback(); - if (!callback) { - // Evaluate the timeout expression. - const nsAString& script = handler->GetHandlerText(); + if (!callback) { + // Evaluate the timeout expression. + const nsAString& script = handler->GetHandlerText(); - const char* filename = nullptr; - uint32_t lineNo = 0, dummyColumn = 0; - handler->GetLocation(&filename, &lineNo, &dummyColumn); + const char* filename = nullptr; + uint32_t lineNo = 0, dummyColumn = 0; + handler->GetLocation(&filename, &lineNo, &dummyColumn); - // New script entry point required, due to the "Create a script" sub-step of - // http://www.whatwg.org/specs/web-apps/current-work/#timer-initialisation-steps - nsAutoMicroTask mt; - AutoEntryScript aes(this, reason, true); - JS::CompileOptions options(aes.cx()); - options.setFileAndLine(filename, lineNo).setVersion(JSVERSION_DEFAULT); - JS::Rooted global(aes.cx(), FastGetGlobalJSObject()); - nsresult rv = - nsJSUtils::EvaluateString(aes.cx(), script, global, options); - if (rv == NS_SUCCESS_DOM_SCRIPT_EVALUATION_THREW_UNCATCHABLE) { - abortIntervalHandler = true; - } - } else { - // Hold strong ref to ourselves while we call the callback. - nsCOMPtr me(static_cast(this)); - ErrorResult rv; - JS::Rooted ignoredVal(RootingCx()); - callback->Call(me, handler->GetArgs(), &ignoredVal, rv, reason); - if (rv.IsUncatchableException()) { - abortIntervalHandler = true; - } - - rv.SuppressException(); + // New script entry point required, due to the "Create a script" sub-step of + // http://www.whatwg.org/specs/web-apps/current-work/#timer-initialisation-steps + nsAutoMicroTask mt; + AutoEntryScript aes(this, reason, true); + JS::CompileOptions options(aes.cx()); + options.setFileAndLine(filename, lineNo) + .setVersion(JSVERSION_DEFAULT); + JS::Rooted global(aes.cx(), FastGetGlobalJSObject()); + nsresult rv = nsJSUtils::EvaluateString(aes.cx(), script, global, options); + if (rv == NS_SUCCESS_DOM_SCRIPT_EVALUATION_THREW_UNCATCHABLE) { + abortIntervalHandler = true; } } else { - nsCOMPtr kungFuDeathGrip(static_cast(this)); - basicHandler->Call(); + // Hold strong ref to ourselves while we call the callback. + nsCOMPtr me(static_cast(this)); + ErrorResult rv; + JS::Rooted ignoredVal(RootingCx()); + callback->Call(me, handler->GetArgs(), &ignoredVal, rv, reason); + if (rv.IsUncatchableException()) { + abortIntervalHandler = true; + } + + rv.SuppressException(); } // If we received an uncatchable exception, do not schedule the timeout again. diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index 48c38b159509..b84c4bfe3970 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -86,7 +86,6 @@ class nsIControllers; class nsIJSID; class nsIScriptContext; class nsIScriptTimeoutHandler; -class nsITimeoutHandler; class nsIWebBrowserChrome; class nsDOMWindowList; @@ -1441,7 +1440,7 @@ public: // Timeout Functions // Language agnostic timeout function (all args passed). // |interval| is in milliseconds. - nsresult SetTimeoutOrInterval(nsITimeoutHandler* aHandler, + nsresult SetTimeoutOrInterval(nsIScriptTimeoutHandler* aHandler, int32_t interval, bool aIsInterval, int32_t* aReturn); int32_t SetTimeoutOrInterval(JSContext* aCx, diff --git a/dom/base/nsIScriptTimeoutHandler.h b/dom/base/nsIScriptTimeoutHandler.h index 722f68e78555..e39af9a12bc2 100644 --- a/dom/base/nsIScriptTimeoutHandler.h +++ b/dom/base/nsIScriptTimeoutHandler.h @@ -6,7 +6,6 @@ #ifndef nsIScriptTimeoutHandler_h___ #define nsIScriptTimeoutHandler_h___ -#include "nsITimeoutHandler.h" #include "nsTArray.h" #include "js/TypeDecls.h" #include "mozilla/Function.h" @@ -27,7 +26,7 @@ class Function; * language agnostic way. */ -class nsIScriptTimeoutHandler : public nsITimeoutHandler +class nsIScriptTimeoutHandler : public nsISupports { public: NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISCRIPTTIMEOUTHANDLER_IID) @@ -42,6 +41,8 @@ public: // Get the location of the script. // Note: The memory pointed to by aFileName is owned by the // nsIScriptTimeoutHandler and should not be freed by the caller. + virtual void GetLocation(const char **aFileName, uint32_t *aLineNo, + uint32_t *aColumn) = 0; // If we have a Function, get the arguments for passing to it. virtual const nsTArray& GetArgs() = 0; diff --git a/dom/base/nsITimeoutHandler.h b/dom/base/nsITimeoutHandler.h deleted file mode 100644 index 9f921dfb2951..000000000000 --- a/dom/base/nsITimeoutHandler.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef nsITimeoutHandler_h___ -#define nsITimeoutHandler_h___ - -#include "nsISupports.h" - -#define NS_ITIMEOUTHANDLER_IID \ -{ 0xb071a1d3, 0xfd54, 0x40a8, \ - { 0x91, 0x9f, 0xc8, 0xf3, 0x3e, 0xb8, 0x3c, 0xfe } } - -class nsITimeoutHandler : public nsISupports -{ -public: - NS_DECLARE_STATIC_IID_ACCESSOR(NS_ITIMEOUTHANDLER_IID) - - virtual nsresult Call() = 0; - - virtual void GetLocation(const char** aFileName, uint32_t* aLineNo, - uint32_t* aColumn) = 0; - - virtual void MarkForCC() = 0; -}; - -NS_DEFINE_STATIC_IID_ACCESSOR(nsITimeoutHandler, - NS_ITIMEOUTHANDLER_IID) - -#endif // nsITimeoutHandler_h___ diff --git a/dom/base/nsJSTimeoutHandler.cpp b/dom/base/nsJSTimeoutHandler.cpp index 8736cd1ddd9c..98bf83c97fb0 100644 --- a/dom/base/nsJSTimeoutHandler.cpp +++ b/dom/base/nsJSTimeoutHandler.cpp @@ -60,16 +60,6 @@ public: return mFunction; } - virtual const nsTArray& GetArgs() override - { - return mArgs; - } - - virtual nsresult Call() override - { - return NS_OK; - } - virtual void GetLocation(const char** aFileName, uint32_t* aLineNo, uint32_t* aColumn) override { @@ -78,11 +68,9 @@ public: *aColumn = mColumn; } - virtual void MarkForCC() override + virtual const nsTArray& GetArgs() override { - if (mFunction) { - mFunction->MarkForCC(); - } + return mArgs; } void ReleaseJSObjects(); @@ -163,7 +151,6 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_END NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsJSScriptTimeoutHandler) NS_INTERFACE_MAP_ENTRY(nsIScriptTimeoutHandler) - NS_INTERFACE_MAP_ENTRY(nsITimeoutHandler) NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END