diff options
Diffstat (limited to 'dom')
-rw-r--r-- | dom/base/CustomElementRegistry.cpp | 1 | ||||
-rw-r--r-- | dom/base/nsContentUtils.cpp | 46 | ||||
-rw-r--r-- | dom/base/nsContentUtils.h | 25 | ||||
-rw-r--r-- | dom/base/nsDocument.cpp | 13 | ||||
-rw-r--r-- | dom/base/nsJSUtils.cpp | 11 | ||||
-rw-r--r-- | dom/bindings/CallbackObject.cpp | 11 | ||||
-rw-r--r-- | dom/events/EventListenerManager.cpp | 10 | ||||
-rw-r--r-- | dom/jsurl/nsJSProtocolHandler.cpp | 3 |
8 files changed, 37 insertions, 83 deletions
diff --git a/dom/base/CustomElementRegistry.cpp b/dom/base/CustomElementRegistry.cpp index 2d7907bd7..ab1e60366 100644 --- a/dom/base/CustomElementRegistry.cpp +++ b/dom/base/CustomElementRegistry.cpp @@ -6,6 +6,7 @@ #include "mozilla/dom/CustomElementRegistry.h" +#include "mozilla/CycleCollectedJSContext.h" #include "mozilla/dom/CustomElementRegistryBinding.h" #include "mozilla/dom/HTMLElementBinding.h" #include "mozilla/dom/WebComponentsBinding.h" diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 87c879746..402dfd1c5 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -259,7 +259,6 @@ nsIWordBreaker *nsContentUtils::sWordBreaker; nsIBidiKeyboard *nsContentUtils::sBidiKeyboard = nullptr; uint32_t nsContentUtils::sScriptBlockerCount = 0; uint32_t nsContentUtils::sDOMNodeRemovedSuppressCount = 0; -uint32_t nsContentUtils::sMicroTaskLevel = 0; AutoTArray<nsCOMPtr<nsIRunnable>, 8>* nsContentUtils::sBlockedScriptRunners = nullptr; uint32_t nsContentUtils::sRunnersCountAtFirstBlocker = 0; nsIInterfaceRequestor* nsContentUtils::sSameOriginChecker = nullptr; @@ -5302,51 +5301,6 @@ nsContentUtils::RunInMetastableState(already_AddRefed<nsIRunnable> aRunnable) CycleCollectedJSContext::Get()->RunInMetastableState(Move(aRunnable)); } -void -nsContentUtils::EnterMicroTask() -{ - MOZ_ASSERT(NS_IsMainThread()); - ++sMicroTaskLevel; -} - -void -nsContentUtils::LeaveMicroTask() -{ - MOZ_ASSERT(NS_IsMainThread()); - if (--sMicroTaskLevel == 0) { - PerformMainThreadMicroTaskCheckpoint(); - } -} - -bool -nsContentUtils::IsInMicroTask() -{ - MOZ_ASSERT(NS_IsMainThread()); - return sMicroTaskLevel != 0; -} - -uint32_t -nsContentUtils::MicroTaskLevel() -{ - MOZ_ASSERT(NS_IsMainThread()); - return sMicroTaskLevel; -} - -void -nsContentUtils::SetMicroTaskLevel(uint32_t aLevel) -{ - MOZ_ASSERT(NS_IsMainThread()); - sMicroTaskLevel = aLevel; -} - -void -nsContentUtils::PerformMainThreadMicroTaskCheckpoint() -{ - MOZ_ASSERT(NS_IsMainThread()); - - nsDOMMutationObserver::HandleMutations(); -} - /* * Helper function for nsContentUtils::ProcessViewportInfo. * diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index 19b007591..4200a0621 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -1740,17 +1740,6 @@ public: */ static void RunInMetastableState(already_AddRefed<nsIRunnable> aRunnable); - // Call EnterMicroTask when you're entering JS execution. - // Usually the best way to do this is to use nsAutoMicroTask. - static void EnterMicroTask(); - static void LeaveMicroTask(); - - static bool IsInMicroTask(); - static uint32_t MicroTaskLevel(); - static void SetMicroTaskLevel(uint32_t aLevel); - - static void PerformMainThreadMicroTaskCheckpoint(); - /* Process viewport META data. This gives us information for the scale * and zoom of a page on mobile devices. We stick the information in * the document header and use it later on after rendering. @@ -2850,7 +2839,6 @@ private: static bool sInitialized; static uint32_t sScriptBlockerCount; static uint32_t sDOMNodeRemovedSuppressCount; - static uint32_t sMicroTaskLevel; // Not an nsCOMArray because removing elements from those is slower static AutoTArray<nsCOMPtr<nsIRunnable>, 8>* sBlockedScriptRunners; static uint32_t sRunnersCountAtFirstBlocker; @@ -2928,19 +2916,6 @@ public: } }; -class MOZ_STACK_CLASS nsAutoMicroTask -{ -public: - nsAutoMicroTask() - { - nsContentUtils::EnterMicroTask(); - } - ~nsAutoMicroTask() - { - nsContentUtils::LeaveMicroTask(); - } -}; - namespace mozilla { namespace dom { diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index f3e492589..293e48eb0 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -12610,8 +12610,12 @@ MarkDocumentTreeToBeInSyncOperation(nsIDocument* aDoc, void* aData) nsAutoSyncOperation::nsAutoSyncOperation(nsIDocument* aDoc) { - mMicroTaskLevel = nsContentUtils::MicroTaskLevel(); - nsContentUtils::SetMicroTaskLevel(0); + mMicroTaskLevel = 0; + CycleCollectedJSContext* ccjs = CycleCollectedJSContext::Get(); + if (ccjs) { + mMicroTaskLevel = ccjs->MicroTaskLevel(); + ccjs->SetMicroTaskLevel(0); + } if (aDoc) { if (nsPIDOMWindowOuter* win = aDoc->GetWindow()) { if (nsCOMPtr<nsPIDOMWindowOuter> top = win->GetTop()) { @@ -12627,7 +12631,10 @@ nsAutoSyncOperation::~nsAutoSyncOperation() for (int32_t i = 0; i < mDocuments.Count(); ++i) { mDocuments[i]->SetIsInSyncOperation(false); } - nsContentUtils::SetMicroTaskLevel(mMicroTaskLevel); + CycleCollectedJSContext* ccjs = CycleCollectedJSContext::Get(); + if (ccjs) { + ccjs->SetMicroTaskLevel(mMicroTaskLevel); + } } gfxUserFontSet* diff --git a/dom/base/nsJSUtils.cpp b/dom/base/nsJSUtils.cpp index 98b367b66..b6c843065 100644 --- a/dom/base/nsJSUtils.cpp +++ b/dom/base/nsJSUtils.cpp @@ -25,7 +25,7 @@ #include "xpcpublic.h" #include "nsContentUtils.h" #include "nsGlobalWindow.h" - +#include "mozilla/CycleCollectedJSContext.h" #include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/Date.h" #include "mozilla/dom/Element.h" @@ -159,7 +159,8 @@ nsJSUtils::EvaluateString(JSContext* aCx, aEvaluationGlobal); MOZ_ASSERT_IF(aOffThreadToken, aCompileOptions.noScriptRval); MOZ_ASSERT(NS_IsMainThread()); - MOZ_ASSERT(nsContentUtils::IsInMicroTask()); + MOZ_ASSERT(CycleCollectedJSContext::Get() && + CycleCollectedJSContext::Get()->MicroTaskLevel()); // Unfortunately, the JS engine actually compiles scripts with a return value // in a different, less efficient way. Furthermore, it can't JIT them in many @@ -293,7 +294,8 @@ nsJSUtils::CompileModule(JSContext* aCx, aEvaluationGlobal); MOZ_ASSERT(JS::CurrentGlobalOrNull(aCx) == aEvaluationGlobal); MOZ_ASSERT(NS_IsMainThread()); - MOZ_ASSERT(nsContentUtils::IsInMicroTask()); + MOZ_ASSERT(CycleCollectedJSContext::Get() && + CycleCollectedJSContext::Get()->MicroTaskLevel()); NS_ENSURE_TRUE(xpc::Scriptability::Get(aEvaluationGlobal).Allowed(), NS_OK); @@ -330,7 +332,8 @@ nsJSUtils::ModuleEvaluation(JSContext* aCx, JS::Handle<JSObject*> aModule) MOZ_ASSERT(aCx == nsContentUtils::GetCurrentJSContext()); MOZ_ASSERT(NS_IsMainThread()); - MOZ_ASSERT(nsContentUtils::IsInMicroTask()); + MOZ_ASSERT(CycleCollectedJSContext::Get() && + CycleCollectedJSContext::Get()->MicroTaskLevel()); NS_ENSURE_TRUE(xpc::Scriptability::Get(aModule).Allowed(), NS_OK); diff --git a/dom/bindings/CallbackObject.cpp b/dom/bindings/CallbackObject.cpp index bb01c804c..398acf9da 100644 --- a/dom/bindings/CallbackObject.cpp +++ b/dom/bindings/CallbackObject.cpp @@ -5,6 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/dom/CallbackObject.h" +#include "mozilla/CycleCollectedJSContext.h" #include "mozilla/dom/BindingUtils.h" #include "jsfriendapi.h" #include "nsIScriptGlobalObject.h" @@ -79,7 +80,10 @@ CallbackObject::CallSetup::CallSetup(CallbackObject* aCallback, , mIsMainThread(NS_IsMainThread()) { if (mIsMainThread) { - nsContentUtils::EnterMicroTask(); + CycleCollectedJSContext* ccjs = CycleCollectedJSContext::Get(); + if (ccjs) { + ccjs->EnterMicroTask(); + } } // Compute the caller's subject principal (if necessary) early, before we @@ -288,7 +292,10 @@ CallbackObject::CallSetup::~CallSetup() // It is important that this is the last thing we do, after leaving the // compartment and undoing all our entry/incumbent script changes if (mIsMainThread) { - nsContentUtils::LeaveMicroTask(); + CycleCollectedJSContext* ccjs = CycleCollectedJSContext::Get(); + if (ccjs) { + ccjs->LeaveMicroTask(); + } } } diff --git a/dom/events/EventListenerManager.cpp b/dom/events/EventListenerManager.cpp index 0774c3296..2add7d009 100644 --- a/dom/events/EventListenerManager.cpp +++ b/dom/events/EventListenerManager.cpp @@ -1087,7 +1087,10 @@ EventListenerManager::HandleEventSubType(Listener* aListener, if (NS_SUCCEEDED(result)) { if (mIsMainThreadELM) { - nsContentUtils::EnterMicroTask(); + CycleCollectedJSContext* ccjs = CycleCollectedJSContext::Get(); + if (ccjs) { + ccjs->EnterMicroTask(); + } } // nsIDOMEvent::currentTarget is set in EventDispatcher. if (listenerHolder.HasWebIDLCallback()) { @@ -1099,7 +1102,10 @@ EventListenerManager::HandleEventSubType(Listener* aListener, result = listenerHolder.GetXPCOMCallback()->HandleEvent(aDOMEvent); } if (mIsMainThreadELM) { - nsContentUtils::LeaveMicroTask(); + CycleCollectedJSContext* ccjs = CycleCollectedJSContext::Get(); + if (ccjs) { + ccjs->LeaveMicroTask(); + } } } diff --git a/dom/jsurl/nsJSProtocolHandler.cpp b/dom/jsurl/nsJSProtocolHandler.cpp index 90171db10..df1e6cbf5 100644 --- a/dom/jsurl/nsJSProtocolHandler.cpp +++ b/dom/jsurl/nsJSProtocolHandler.cpp @@ -46,6 +46,7 @@ #include "nsIWritablePropertyBag2.h" #include "nsIContentSecurityPolicy.h" #include "nsSandboxFlags.h" +#include "mozilla/CycleCollectedJSContext.h" #include "mozilla/dom/ScriptSettings.h" #include "nsILoadInfo.h" #include "nsContentSecurityManager.h" @@ -241,7 +242,7 @@ nsresult nsJSThunk::EvaluateScript(nsIChannel *aChannel, // New script entry point required, due to the "Create a script" step of // http://www.whatwg.org/specs/web-apps/current-work/#javascript-protocol - nsAutoMicroTask mt; + mozilla::nsAutoMicroTask mt; AutoEntryScript aes(innerGlobal, "javascript: URI", true); JSContext* cx = aes.cx(); JS::Rooted<JSObject*> globalJSObject(cx, innerGlobal->GetGlobalJSObject()); |