Bug 1406922 - Make CycleCollectedJSContext to handle microtasks and make MutationObserver to use them

Tag UXP Issue #1344
This commit is contained in:
Gaming4JC 2020-01-22 21:07:19 -05:00 • committed by Roy Tam
commit 249667092c
5 changed files with 164 additions and 48 deletions

View file

@ -33,6 +33,7 @@ struct Class;
} // namespace js
namespace mozilla {
class AutoSlowOperation;
class JSGCThingParticipant: public nsCycleCollectionParticipant
{
@ -134,6 +135,17 @@ struct CycleCollectorResults
uint32_t mNumSlices;
};
class MicroTaskRunnable
{
public:
MicroTaskRunnable() {}
NS_INLINE_DECL_REFCOUNTING(MicroTaskRunnable)
virtual void Run(AutoSlowOperation& aAso) = 0;
virtual bool Suppressed() { return false; }
protected:
virtual ~MicroTaskRunnable() {}
};
class CycleCollectedJSContext
{
friend class JSGCThingParticipant;
@ -412,7 +424,7 @@ public:
void LeaveMicroTask()
{
if (--mMicroTaskLevel == 0) {
PerformMainThreadMicroTaskCheckpoint();
PerformMicroTaskCheckPoint();
}
}
@ -431,7 +443,9 @@ public:
mMicroTaskLevel = aLevel;
}
void PerformMainThreadMicroTaskCheckpoint();
void PerformMicroTaskCheckPoint();
void DispatchMicroTaskRunnable(already_AddRefed<MicroTaskRunnable> aRunnable);
// Storage for watching rejected promises waiting for some client to
// consume their rejection.
@ -484,6 +498,10 @@ private:
bool mDisableMicroTaskCheckpoint;
uint32_t mMicroTaskLevel;
std::queue<RefPtr<MicroTaskRunnable>> mPendingMicroTaskRunnables;
uint32_t mMicroTaskRecursionDepth;
OOMState mOutOfMemoryState;
OOMState mLargeAllocationFailureState;