diff options
author | Moonchild <moonchild@palemoon.org> | 2022-02-06 13:54:40 +0000 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2022-05-07 14:39:41 +0000 |
commit | 6f8d063b186022997303d33e33c008741c86ca78 (patch) | |
tree | a9765fb5754a8d7fdd9e4384671fd28138c209bb /dom/base | |
parent | a5b4a440d6ccecf03fd694e0c225caf4482e3aca (diff) | |
download | uxp-6f8d063b186022997303d33e33c008741c86ca78.tar.gz |
Issue #1895 - Implement queueMicroTask(callback())
Diffstat (limited to 'dom/base')
-rw-r--r-- | dom/base/nsDOMMutationObserver.h | 7 | ||||
-rw-r--r-- | dom/base/nsGlobalWindow.h | 6 | ||||
-rw-r--r-- | dom/base/nsIGlobalObject.cpp | 38 | ||||
-rw-r--r-- | dom/base/nsIGlobalObject.h | 11 |
4 files changed, 57 insertions, 5 deletions
diff --git a/dom/base/nsDOMMutationObserver.h b/dom/base/nsDOMMutationObserver.h index 6e17e4f2cc..1e2225d020 100644 --- a/dom/base/nsDOMMutationObserver.h +++ b/dom/base/nsDOMMutationObserver.h @@ -25,6 +25,7 @@ #include "nsIDocument.h" #include "mozilla/dom/Animation.h" #include "nsIAnimationObserver.h" +#include "nsGlobalWindow.h" class nsDOMMutationObserver; using mozilla::dom::MutationObservingInfo; @@ -599,11 +600,7 @@ protected: bool Suppressed() { - if (mOwner) { - nsCOMPtr<nsIDocument> d = mOwner->GetExtantDoc(); - return d && d->IsInSyncOperation(); - } - return false; + return mOwner && nsGlobalWindow::Cast(mOwner)->IsInSyncOperation(); } static void HandleMutationsInternal(mozilla::AutoSlowOperation& aAso); diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index 00ac023fce..e42835a0b2 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -1224,6 +1224,12 @@ public: already_AddRefed<nsWindowRoot> GetWindowRoot(mozilla::ErrorResult& aError); mozilla::dom::Performance* GetPerformance(); + + virtual bool IsInSyncOperation() override + { + return GetExtantDoc() && GetExtantDoc()->IsInSyncOperation(); + } + protected: // Web IDL helpers diff --git a/dom/base/nsIGlobalObject.cpp b/dom/base/nsIGlobalObject.cpp index 8923865082..7a6bab8b4b 100644 --- a/dom/base/nsIGlobalObject.cpp +++ b/dom/base/nsIGlobalObject.cpp @@ -4,10 +4,20 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "nsIGlobalObject.h" + +#include "mozilla/CycleCollectedJSContext.h" +#include "mozilla/dom/FunctionBinding.h" #include "nsContentUtils.h" #include "nsThreadUtils.h" #include "nsHostObjectProtocolHandler.h" +using mozilla::AutoSlowOperation; +using mozilla::CycleCollectedJSContext; +using mozilla::ErrorResult; +using mozilla::IgnoredErrorResult; +using mozilla::MicroTaskRunnable; +using mozilla::dom::VoidFunction; + nsIGlobalObject::~nsIGlobalObject() { UnlinkHostObjectURIs(); @@ -110,3 +120,31 @@ nsIGlobalObject::TraverseHostObjectURIs(nsCycleCollectionTraversalCallback &aCb) nsHostObjectProtocolHandler::Traverse(mHostObjectURIs[index], aCb); } } + +class QueuedMicrotask : public MicroTaskRunnable { + public: + QueuedMicrotask(nsIGlobalObject* aGlobal, VoidFunction& aCallback) + : mGlobal(aGlobal) + , mCallback(&aCallback) + {} + + /* unsafe */ + void Run(AutoSlowOperation& aAso) final { + IgnoredErrorResult rv; + mCallback->Call(static_cast<ErrorResult&>(rv)); + } + + bool Suppressed() final { return mGlobal->IsInSyncOperation(); } + + private: + nsCOMPtr<nsIGlobalObject> mGlobal; + RefPtr<VoidFunction> mCallback; +}; + +void nsIGlobalObject::QueueMicrotask(VoidFunction& aCallback) { + CycleCollectedJSContext* context = CycleCollectedJSContext::Get(); + if (context) { + RefPtr<MicroTaskRunnable> mt = new QueuedMicrotask(this, aCallback); + context->DispatchMicroTaskRunnable(mt.forget()); + } +}
\ No newline at end of file diff --git a/dom/base/nsIGlobalObject.h b/dom/base/nsIGlobalObject.h index 6dfae4fbe4..1438803317 100644 --- a/dom/base/nsIGlobalObject.h +++ b/dom/base/nsIGlobalObject.h @@ -19,6 +19,13 @@ class nsCString; class nsCycleCollectionTraversalCallback; class nsIPrincipal; +namespace mozilla{ +namespace dom{ +class VoidFunction; +} +} + + class nsIGlobalObject : public nsISupports { nsTArray<nsCString> mHostObjectURIs; @@ -72,6 +79,10 @@ public: void UnlinkHostObjectURIs(); void TraverseHostObjectURIs(nsCycleCollectionTraversalCallback &aCb); + virtual bool IsInSyncOperation() { return false; } + + void QueueMicrotask(mozilla::dom::VoidFunction& aCallback); + protected: virtual ~nsIGlobalObject(); |