diff options
Diffstat (limited to 'xpcom/base/CycleCollectedJSContext.h')
-rw-r--r-- | xpcom/base/CycleCollectedJSContext.h | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/xpcom/base/CycleCollectedJSContext.h b/xpcom/base/CycleCollectedJSContext.h index ac4cf4361..4cd1479ed 100644 --- a/xpcom/base/CycleCollectedJSContext.h +++ b/xpcom/base/CycleCollectedJSContext.h @@ -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; @@ -402,6 +414,39 @@ public: // Queue an async microtask to the current main or worker thread. virtual void DispatchToMicroTask(already_AddRefed<nsIRunnable> aRunnable); + // Call EnterMicroTask when you're entering JS execution. + // Usually the best way to do this is to use nsAutoMicroTask. + void EnterMicroTask() + { + ++mMicroTaskLevel; + } + + void LeaveMicroTask() + { + if (--mMicroTaskLevel == 0) { + PerformMicroTaskCheckPoint(); + } + } + + bool IsInMicroTask() + { + return mMicroTaskLevel != 0; + } + + uint32_t MicroTaskLevel() + { + return mMicroTaskLevel; + } + + void SetMicroTaskLevel(uint32_t aLevel) + { + mMicroTaskLevel = aLevel; + } + + void PerformMicroTaskCheckPoint(); + + void DispatchMicroTaskRunnable(already_AddRefed<MicroTaskRunnable> aRunnable); + // Storage for watching rejected promises waiting for some client to // consume their rejection. @@ -452,6 +497,11 @@ private: bool mDisableMicroTaskCheckpoint; + uint32_t mMicroTaskLevel; + std::queue<RefPtr<MicroTaskRunnable>> mPendingMicroTaskRunnables; + + uint32_t mMicroTaskRecursionDepth; + OOMState mOutOfMemoryState; OOMState mLargeAllocationFailureState; @@ -470,6 +520,25 @@ private: EnvironmentPreparer mEnvironmentPreparer; }; +class MOZ_STACK_CLASS nsAutoMicroTask +{ +public: + nsAutoMicroTask() + { + CycleCollectedJSContext* ccjs = CycleCollectedJSContext::Get(); + if (ccjs) { + ccjs->EnterMicroTask(); + } + } + ~nsAutoMicroTask() + { + CycleCollectedJSContext* ccjs = CycleCollectedJSContext::Get(); + if (ccjs) { + ccjs->LeaveMicroTask(); + } + } +}; + void TraceScriptHolder(nsISupports* aHolder, JSTracer* aTracer); // Returns true if the JS::TraceKind is one the cycle collector cares about. |