diff --git a/dom/base/ScriptSettings.cpp b/dom/base/ScriptSettings.cpp index d7c26096da1..e02d1fc288f 100644 --- a/dom/base/ScriptSettings.cpp +++ b/dom/base/ScriptSettings.cpp @@ -463,14 +463,22 @@ AutoEntryScript::AutoEntryScript(nsIGlobalObject* aGlobalObject, aCx ? aCx : FindJSContext(aGlobalObject)) , ScriptSettingsStackEntry(aGlobalObject, /* aCandidate = */ true) , mWebIDLCallerPrincipal(nullptr) + , mIsMainThread(aIsMainThread) { MOZ_ASSERT(aGlobalObject); MOZ_ASSERT_IF(!aCx, aIsMainThread); // cx is mandatory off-main-thread. MOZ_ASSERT_IF(aCx && aIsMainThread, aCx == FindJSContext(aGlobalObject)); + if (aIsMainThread) { + nsContentUtils::EnterMicroTask(); + } } AutoEntryScript::~AutoEntryScript() { + if (mIsMainThread) { + nsContentUtils::LeaveMicroTask(); + } + // GC when we pop a script entry point. This is a useful heuristic that helps // us out on certain (flawed) benchmarks like sunspider, because it lets us // avoid GCing during the timing loop. diff --git a/dom/base/ScriptSettings.h b/dom/base/ScriptSettings.h index f6559a447e0..ffb78ae6f73 100644 --- a/dom/base/ScriptSettings.h +++ b/dom/base/ScriptSettings.h @@ -330,6 +330,7 @@ private: // bit up the stack, and which will outlive us. So we know the principal // can't go away until then either. nsIPrincipal* mWebIDLCallerPrincipal; + bool mIsMainThread; friend nsIPrincipal* GetWebIDLCallerPrincipal(); };