Bug 1081038 - part1: Microtask in AutoEntryScript. r=bholley
authorGabor Krizsanits <gkrizsanits@mozilla.com>
Fri, 14 Nov 2014 16:46:26 +0100
changeset 240150 c638dcabef9ac510bc6e6b8d0a415d4a7244f8fb
parent 240149 53e97446fed99facc45642c93dca086a542cb94a
child 240151 044d2a98a497a39f7df5b502043c4eacb440a8b1
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1081038
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1081038 - part1: Microtask in AutoEntryScript. r=bholley
dom/base/ScriptSettings.cpp
dom/base/ScriptSettings.h
--- a/dom/base/ScriptSettings.cpp
+++ b/dom/base/ScriptSettings.cpp
@@ -512,20 +512,24 @@ AutoJSAPI::StealException(JS::MutableHan
 AutoEntryScript::AutoEntryScript(nsIGlobalObject* aGlobalObject,
                                  bool aIsMainThread,
                                  JSContext* aCx)
   : AutoJSAPI(aGlobalObject, aIsMainThread,
               aCx ? aCx : FindJSContext(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<nsPIDOMWindow> window = do_QueryInterface(aGlobalObject);
     if (window) {
         mDocShellForJSRunToCompletion = window->GetDocShell();
     }
   }
 
@@ -535,16 +539,20 @@ AutoEntryScript::AutoEntryScript(nsIGlob
 }
 
 AutoEntryScript::~AutoEntryScript()
 {
   if (mDocShellForJSRunToCompletion) {
     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.
   JS_MaybeGC(cx());
 }
 
 AutoIncumbentScript::AutoIncumbentScript(nsIGlobalObject* aGlobalObject)
   : ScriptSettingsStackEntry(aGlobalObject, /* aCandidate = */ false)
--- a/dom/base/ScriptSettings.h
+++ b/dom/base/ScriptSettings.h
@@ -339,16 +339,18 @@ private:
   // the aIsJSImplementedWebIDL case.  And in that case, the subject principal
   // is the principal of the callee function that is part of the CallArgs just a
   // bit up the stack, and which will outlive us.  So we know the principal
   // can't go away until then either.
   nsIPrincipal* mWebIDLCallerPrincipal;
   friend nsIPrincipal* GetWebIDLCallerPrincipal();
 
   nsIDocShell* mDocShellForJSRunToCompletion;
+
+  bool mIsMainThread;
 };
 
 /*
  * A class that can be used to force a particular incumbent script on the stack.
  */
 class AutoIncumbentScript : protected ScriptSettingsStackEntry {
 public:
   explicit AutoIncumbentScript(nsIGlobalObject* aGlobalObject);