diff --git a/dom/base/ScriptSettings.cpp b/dom/base/ScriptSettings.cpp index 550b25148c5..5db474c7f4c 100644 --- a/dom/base/ScriptSettings.cpp +++ b/dom/base/ScriptSettings.cpp @@ -517,10 +517,14 @@ AutoEntryScript::AutoEntryScript(nsIGlobalObject* aGlobalObject, , ScriptSettingsStackEntry(aGlobalObject, /* aCandidate = */ true) , mWebIDLCallerPrincipal(nullptr) , mDocShellForJSRunToCompletion(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(); + } if (aIsMainThread && gRunToCompletionListeners > 0) { nsCOMPtr window = do_QueryInterface(aGlobalObject); @@ -540,6 +544,10 @@ AutoEntryScript::~AutoEntryScript() mDocShellForJSRunToCompletion->NotifyJSRunToCompletionStop(); } + 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 4debd1ae091..5df78e23024 100644 --- a/dom/base/ScriptSettings.h +++ b/dom/base/ScriptSettings.h @@ -344,6 +344,8 @@ private: friend nsIPrincipal* GetWebIDLCallerPrincipal(); nsIDocShell* mDocShellForJSRunToCompletion; + + bool mIsMainThread; }; /*