mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-08 08:48:39 +09:00
Issue #3063 - Implement queueMicroTask(callback())
This commit is contained in:
parent
602bb0a877
commit
bf17b1fec3
7 changed files with 66 additions and 9 deletions
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue