summaryrefslogtreecommitdiffstats
path: root/xpcom/base/CycleCollectedJSContext.h
diff options
context:
space:
mode:
authorGaming4JC <g4jc@hyperbola.info>2020-01-22 19:28:33 -0500
committerGaming4JC <g4jc@hyperbola.info>2020-01-26 15:50:49 -0500
commit43a8113072b96affb2b7a3a7a4e965547d3d0c41 (patch)
treedd685edd37f2bffec27c55060e50ba8289e05760 /xpcom/base/CycleCollectedJSContext.h
parent14d115cfe32ab72b7193a4fb74e13c06c6d4cc8f (diff)
downloadUXP-43a8113072b96affb2b7a3a7a4e965547d3d0c41.tar
UXP-43a8113072b96affb2b7a3a7a4e965547d3d0c41.tar.gz
UXP-43a8113072b96affb2b7a3a7a4e965547d3d0c41.tar.lz
UXP-43a8113072b96affb2b7a3a7a4e965547d3d0c41.tar.xz
UXP-43a8113072b96affb2b7a3a7a4e965547d3d0c41.zip
Bug 1405821 - Move microtask handling to CycleCollectedJSContext
Tag UXP Issue #1344
Diffstat (limited to 'xpcom/base/CycleCollectedJSContext.h')
-rw-r--r--xpcom/base/CycleCollectedJSContext.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/xpcom/base/CycleCollectedJSContext.h b/xpcom/base/CycleCollectedJSContext.h
index ac4cf4361..2197eae92 100644
--- a/xpcom/base/CycleCollectedJSContext.h
+++ b/xpcom/base/CycleCollectedJSContext.h
@@ -402,6 +402,37 @@ 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) {
+ PerformMainThreadMicroTaskCheckpoint();
+ }
+ }
+
+ bool IsInMicroTask()
+ {
+ return mMicroTaskLevel != 0;
+ }
+
+ uint32_t MicroTaskLevel()
+ {
+ return mMicroTaskLevel;
+ }
+
+ void SetMicroTaskLevel(uint32_t aLevel)
+ {
+ mMicroTaskLevel = aLevel;
+ }
+
+ void PerformMainThreadMicroTaskCheckpoint();
+
// Storage for watching rejected promises waiting for some client to
// consume their rejection.
@@ -452,6 +483,7 @@ private:
bool mDisableMicroTaskCheckpoint;
+ uint32_t mMicroTaskLevel;
OOMState mOutOfMemoryState;
OOMState mLargeAllocationFailureState;
@@ -470,6 +502,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.