Bug 1267989 part 1. Rename nsScriptLoader::Add/RemoveExecuteBlocker to Add/RemoveParserBlockingScriptBlocker, to more clearly reflect what it does. r=smaug
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 20 May 2016 23:13:18 -0400
changeset 298336 ec2fd25740c85e48bd0d6465319923d83aa08e44
parent 298335 1287ce64f050a1f21cd19197b7d5ce7659b18ff4
child 298337 88a7fdbd52bad27d0aece53baeae1072dc1e09a5
push id30281
push usercbook@mozilla.com
push dateTue, 24 May 2016 12:54:02 +0000
treeherdermozilla-central@829d3be6ba64 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1267989
milestone49.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 1267989 part 1. Rename nsScriptLoader::Add/RemoveExecuteBlocker to Add/RemoveParserBlockingScriptBlocker, to more clearly reflect what it does. r=smaug
dom/base/ImportManager.cpp
dom/base/nsContentSink.cpp
dom/base/nsScriptLoader.cpp
dom/base/nsScriptLoader.h
dom/xml/nsXMLContentSink.cpp
parser/html/nsHtml5DocumentBuilder.cpp
--- a/dom/base/ImportManager.cpp
+++ b/dom/base/ImportManager.cpp
@@ -142,17 +142,18 @@ ImportLoader::Updater::UpdateMainReferre
 
   // This new link means we have to execute our scripts sooner...
   // Let's make sure that unblocking a loader does not trigger a script execution.
   // So we start with placing the new blockers and only then will we remove any
   // blockers.
   if (mLoader->IsBlocking()) {
     // Our import parent is changed, let's block the new one and later unblock
     // the old one.
-    newMainReferrer->OwnerDoc()->ScriptLoader()->AddExecuteBlocker();
+    newMainReferrer->OwnerDoc()->
+      ScriptLoader()->AddParserBlockingScriptExecutionBlocker();
     newMainReferrer->OwnerDoc()->BlockDOMContentLoaded();
   }
 
   if (mLoader->mDocument) {
     // Our nearest predecessor has changed. So let's add the ScriptLoader to the
     // new one if there is any. And remove it from the old one.
     RefPtr<ImportManager> manager = mLoader->Manager();
     nsScriptLoader* loader = mLoader->mDocument->ScriptLoader();
@@ -162,17 +163,18 @@ ImportLoader::Updater::UpdateMainReferre
       if (newPred) {
         newPred->AddBlockedScriptLoader(loader);
       }
       pred->RemoveBlockedScriptLoader(loader);
     }
   }
 
   if (mLoader->IsBlocking()) {
-    mLoader->mImportParent->ScriptLoader()->RemoveExecuteBlocker();
+    mLoader->mImportParent->
+      ScriptLoader()->RemoveParserBlockingScriptExecutionBlocker();
     mLoader->mImportParent->UnblockDOMContentLoaded();
   }
 
   // Finally update mMainReferrer to point to the newly added link.
   mLoader->mMainReferrer = aNewIdx;
   mLoader->mImportParent = newMainReferrer->OwnerDoc();
 }
 
@@ -295,29 +297,29 @@ ImportLoader::ImportLoader(nsIURI* aURI,
   , mUpdater(this)
 {
 }
 
 void
 ImportLoader::BlockScripts()
 {
   MOZ_ASSERT(!mBlockingScripts);
-  mImportParent->ScriptLoader()->AddExecuteBlocker();
+  mImportParent->ScriptLoader()->AddParserBlockingScriptExecutionBlocker();
   mImportParent->BlockDOMContentLoaded();
   mBlockingScripts = true;
 }
 
 void
 ImportLoader::UnblockScripts()
 {
   MOZ_ASSERT(mBlockingScripts);
-  mImportParent->ScriptLoader()->RemoveExecuteBlocker();
+  mImportParent->ScriptLoader()->RemoveParserBlockingScriptExecutionBlocker();
   mImportParent->UnblockDOMContentLoaded();
   for (uint32_t i = 0; i < mBlockedScriptLoaders.Length(); i++) {
-    mBlockedScriptLoaders[i]->RemoveExecuteBlocker();
+    mBlockedScriptLoaders[i]->RemoveParserBlockingScriptExecutionBlocker();
   }
   mBlockedScriptLoaders.Clear();
   mBlockingScripts = false;
 }
 
 void
 ImportLoader::SetBlockingPredecessor(ImportLoader* aLoader)
 {
@@ -338,26 +340,26 @@ ImportLoader::DispatchEventIfFinished(ns
 
 void
 ImportLoader::AddBlockedScriptLoader(nsScriptLoader* aScriptLoader)
 {
   if (mBlockedScriptLoaders.Contains(aScriptLoader)) {
     return;
   }
 
-  aScriptLoader->AddExecuteBlocker();
+  aScriptLoader->AddParserBlockingScriptExecutionBlocker();
 
   // Let's keep track of the pending script loaders.
   mBlockedScriptLoaders.AppendElement(aScriptLoader);
 }
 
 bool
 ImportLoader::RemoveBlockedScriptLoader(nsScriptLoader* aScriptLoader)
 {
-  aScriptLoader->RemoveExecuteBlocker();
+  aScriptLoader->RemoveParserBlockingScriptExecutionBlocker();
   return mBlockedScriptLoaders.RemoveElement(aScriptLoader);
 }
 
 void
 ImportLoader::AddLinkElement(nsINode* aNode)
 {
   // If a new link element is added to the import tree that
   // refers to an import that is already finished loading or
--- a/dom/base/nsContentSink.cpp
+++ b/dom/base/nsContentSink.cpp
@@ -230,17 +230,17 @@ nsContentSink::StyleSheetLoaded(StyleShe
         // don't need to worry about it.
         StartLayout(false);
       }
 
       // Go ahead and try to scroll to our ref if we have one
       ScrollToRef();
     }
     
-    mScriptLoader->RemoveExecuteBlocker();
+    mScriptLoader->RemoveParserBlockingScriptExecutionBlocker();
   }
 
   return NS_OK;
 }
 
 nsresult
 nsContentSink::ProcessHTTPHeaders(nsIChannel* aChannel)
 {
@@ -767,17 +767,17 @@ nsContentSink::ProcessStyleLink(nsIConte
   rv = mCSSLoader->LoadStyleLink(aElement, url, aTitle, aMedia, aAlternate,
                                  CORS_NONE, mDocument->GetReferrerPolicy(),
                                  integrity, mRunsToCompletion ? nullptr : this,
                                  &isAlternate);
   NS_ENSURE_SUCCESS(rv, rv);
   
   if (!isAlternate && !mRunsToCompletion) {
     ++mPendingSheetCount;
-    mScriptLoader->AddExecuteBlocker();
+    mScriptLoader->AddParserBlockingScriptExecutionBlocker();
   }
 
   return NS_OK;
 }
 
 
 nsresult
 nsContentSink::ProcessMETATag(nsIContent* aContent)
--- a/dom/base/nsScriptLoader.cpp
+++ b/dom/base/nsScriptLoader.cpp
@@ -428,17 +428,17 @@ NS_IMPL_CYCLE_COLLECTION(nsScriptLoader,
                          mPendingChildLoaders,
                          mFetchedModules)
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsScriptLoader)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsScriptLoader)
 
 nsScriptLoader::nsScriptLoader(nsIDocument *aDocument)
   : mDocument(aDocument),
-    mBlockerCount(0),
+    mParserBlockingBlockerCount(0),
     mNumberOfProcessors(0),
     mEnabled(true),
     mDeferEnabled(false),
     mDocumentParsingDone(false),
     mBlockingDOMContentLoaded(false)
 {
 }
 
@@ -474,17 +474,17 @@ nsScriptLoader::~nsScriptLoader()
       req;
       req = req->getNext()) {
     req->FireScriptAvailable(NS_ERROR_ABORT);
   }
 
   // Unblock the kids, in case any of them moved to a different document
   // subtree in the meantime and therefore aren't actually going away.
   for (uint32_t j = 0; j < mPendingChildLoaders.Length(); ++j) {
-    mPendingChildLoaders[j]->RemoveExecuteBlocker();
+    mPendingChildLoaders[j]->RemoveParserBlockingScriptExecutionBlocker();
   }
 }
 
 // Helper method for checking if the script element is an event-handler
 // This means that it has both a for-attribute and a event-attribute.
 // Also, if the for-attribute has a value that matches "\s*window\s*",
 // and the event-attribute matches "\s*onload([ \(].*)?" then it isn't an
 // eventhandler. (both matches are case insensitive).
@@ -1454,17 +1454,17 @@ nsScriptLoader::ProcessScriptElement(nsI
       if (request->IsReadyToRun()) {
         // The script is available already. Run it ASAP when the event
         // loop gets a chance to spin.
         ProcessPendingRequestsAsync();
       }
       return true;
     }
 
-    if (request->IsReadyToRun() && ReadyToExecuteScripts()) {
+    if (request->IsReadyToRun() && ReadyToExecuteParserBlockingScripts()) {
       // The request has already been loaded and there are no pending style
       // sheets. If the script comes from the network stream, cheat for
       // performance reasons and avoid a trip through the event loop.
       if (aElement->GetParserCreated() == FROM_PARSER_NETWORK) {
         return ProcessRequest(request) == NS_ERROR_HTMLPARSER_BLOCK;
       }
       // Otherwise, we've got a document.written script, make a trip through
       // the event loop to hide the preload effects from the scripts on the
@@ -1517,32 +1517,32 @@ nsScriptLoader::ProcessScriptElement(nsI
       mLoadingAsyncRequests.AppendElement(request);
     } else {
       AddDeferRequest(request);
     }
     return false;
   }
   request->mProgress = nsScriptLoadRequest::Progress::Ready;
   if (aElement->GetParserCreated() == FROM_PARSER_XSLT &&
-      (!ReadyToExecuteScripts() || !mXSLTRequests.isEmpty())) {
+      (!ReadyToExecuteParserBlockingScripts() || !mXSLTRequests.isEmpty())) {
     // Need to maintain order for XSLT-inserted scripts
     NS_ASSERTION(!mParserBlockingRequest,
         "Parser-blocking scripts and XSLT scripts in the same doc!");
     mXSLTRequests.AppendElement(request);
     return true;
   }
   if (aElement->GetParserCreated() == NOT_FROM_PARSER) {
     NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(),
         "A script-inserted script is inserted without an update batch?");
     nsContentUtils::AddScriptRunner(new nsScriptRequestProcessor(this,
                                                                  request));
     return false;
   }
   if (aElement->GetParserCreated() == FROM_PARSER_NETWORK &&
-      !ReadyToExecuteScripts()) {
+      !ReadyToExecuteParserBlockingScripts()) {
     NS_ASSERTION(!mParserBlockingRequest,
         "There can be only one parser-blocking script at a time");
     mParserBlockingRequest = request;
     NS_ASSERTION(mXSLTRequests.isEmpty(),
         "Parser-blocking scripts and XSLT scripts in the same doc!");
     return true;
   }
   // We now have a document.written inline script or we have an inline script
@@ -1600,17 +1600,17 @@ nsScriptLoader::ProcessOffThreadRequest(
       request->LoadFailed();
     }
     return rv;
   }
 
   aRequest->SetReady();
 
   if (aRequest == mParserBlockingRequest) {
-    if (!ReadyToExecuteScripts()) {
+    if (!ReadyToExecuteParserBlockingScripts()) {
       // If not ready to execute scripts, schedule an async call to
       // ProcessPendingRequests to handle it.
       ProcessPendingRequestsAsync();
       return NS_OK;
     }
 
     // Same logic as in top of ProcessPendingRequests.
     mParserBlockingRequest = nullptr;
@@ -2040,27 +2040,27 @@ nsScriptLoader::ProcessPendingRequestsAs
 
 void
 nsScriptLoader::ProcessPendingRequests()
 {
   RefPtr<nsScriptLoadRequest> request;
 
   if (mParserBlockingRequest &&
       mParserBlockingRequest->IsReadyToRun() &&
-      ReadyToExecuteScripts()) {
+      ReadyToExecuteParserBlockingScripts()) {
     request.swap(mParserBlockingRequest);
     UnblockParser(request);
     ProcessRequest(request);
     if (request->mWasCompiledOMT) {
       mDocument->UnblockOnload(false);
     }
     ContinueParserAsync(request);
   }
 
-  while (ReadyToExecuteScripts() &&
+  while (ReadyToExecuteParserBlockingScripts() &&
          !mXSLTRequests.isEmpty() &&
          mXSLTRequests.getFirst()->IsReadyToRun()) {
     request = mXSLTRequests.StealFirst();
     ProcessRequest(request);
   }
 
   while (mEnabled && !mLoadedAsyncRequests.isEmpty()) {
     request = mLoadedAsyncRequests.StealFirst();
@@ -2083,20 +2083,21 @@ nsScriptLoader::ProcessPendingRequests()
 
   if (mDocumentParsingDone && mXSLTRequests.isEmpty()) {
     while (!mDeferRequests.isEmpty() && mDeferRequests.getFirst()->IsReadyToRun()) {
       request = mDeferRequests.StealFirst();
       ProcessRequest(request);
     }
   }
 
-  while (!mPendingChildLoaders.IsEmpty() && ReadyToExecuteScripts()) {
+  while (!mPendingChildLoaders.IsEmpty() &&
+         ReadyToExecuteParserBlockingScripts()) {
     RefPtr<nsScriptLoader> child = mPendingChildLoaders[0];
     mPendingChildLoaders.RemoveElementAt(0);
-    child->RemoveExecuteBlocker();
+    child->RemoveParserBlockingScriptExecutionBlocker();
   }
 
   if (mDocumentParsingDone && mDocument && !mParserBlockingRequest &&
       mNonAsyncExternalScriptInsertedRequests.isEmpty() &&
       mXSLTRequests.isEmpty() && mDeferRequests.isEmpty() &&
       MaybeRemovedDeferRequests()) {
     return ProcessPendingRequests();
   }
@@ -2110,29 +2111,29 @@ nsScriptLoader::ProcessPendingRequests()
     // OK to unblock onload synchronously here, since callers must be
     // prepared for the world changing anyway.
     mDocumentParsingDone = false;
     mDocument->UnblockOnload(true);
   }
 }
 
 bool
-nsScriptLoader::ReadyToExecuteScripts()
+nsScriptLoader::ReadyToExecuteParserBlockingScripts()
 {
-  // Make sure the SelfReadyToExecuteScripts check is first, so that
-  // we don't block twice on an ancestor.
-  if (!SelfReadyToExecuteScripts()) {
+  // Make sure the SelfReadyToExecuteParserBlockingScripts check is first, so
+  // that we don't block twice on an ancestor.
+  if (!SelfReadyToExecuteParserBlockingScripts()) {
     return false;
   }
 
   for (nsIDocument* doc = mDocument; doc; doc = doc->GetParentDocument()) {
     nsScriptLoader* ancestor = doc->ScriptLoader();
-    if (!ancestor->SelfReadyToExecuteScripts() &&
+    if (!ancestor->SelfReadyToExecuteParserBlockingScripts() &&
         ancestor->AddPendingChildLoader(this)) {
-      AddExecuteBlocker();
+      AddParserBlockingScriptExecutionBlocker();
       return false;
     }
   }
 
   if (mDocument && !mDocument->IsMasterDocument()) {
     RefPtr<ImportManager> im = mDocument->ImportManager();
     RefPtr<ImportLoader> loader = im->Find(mDocument);
     MOZ_ASSERT(loader, "How can we have an import document without a loader?");
@@ -2148,17 +2149,18 @@ nsScriptLoader::ReadyToExecuteScripts()
     // which is the neares one to us in the order.
     RefPtr<ImportLoader> lastPred = im->GetNearestPredecessor(referrer);
     if (!lastPred) {
       // If there is no predecessor we can run.
       return true;
     }
 
     nsCOMPtr<nsIDocument> doc = lastPred->GetDocument();
-    if (lastPred->IsBlocking() || !doc || (doc && !doc->ScriptLoader()->SelfReadyToExecuteScripts())) {
+    if (lastPred->IsBlocking() || !doc ||
+        !doc->ScriptLoader()->SelfReadyToExecuteParserBlockingScripts()) {
       // Document has not been created yet or it was created but not ready.
       // Either case we are blocked by it. The ImportLoader will take care
       // of blocking us, and adding the pending child loader to the blocking
       // ScriptLoader when it's possible (at this point the blocking loader
       // might not have created the document/ScriptLoader)
       lastPred->AddBlockedScriptLoader(this);
       // As more imports are parsed, this can change, let's cache what we
       // blocked, so it can be later updated if needed (see: ImportLoader::Updater).
--- a/dom/base/nsScriptLoader.h
+++ b/dom/base/nsScriptLoader.h
@@ -337,26 +337,27 @@ public:
   {
     if (!mEnabled && aEnabled) {
       ProcessPendingRequestsAsync();
     }
     mEnabled = aEnabled;
   }
 
   /**
-   * Add/remove blocker. Blockers will stop scripts from executing, but not
-   * from loading.
+   * Add/remove a blocker for parser-blocking scripts (and XSLT
+   * scripts). Blockers will stop such scripts from executing, but not from
+   * loading.
    */
-  void AddExecuteBlocker()
+  void AddParserBlockingScriptExecutionBlocker()
   {
-    ++mBlockerCount;
+    ++mParserBlockingBlockerCount;
   }
-  void RemoveExecuteBlocker()
+  void RemoveParserBlockingScriptExecutionBlocker()
   {
-    if (!--mBlockerCount) {
+    if (!--mParserBlockingBlockerCount) {
       ProcessPendingRequestsAsync();
     }
   }
 
   /**
    * Convert the given buffer to a UTF-16 string.
    * @param aChannel     Channel corresponding to the data. May be null.
    * @param aData        The data to convert
@@ -494,29 +495,30 @@ private:
    * are any. Note that this is a no-op if there aren't any currently pending
    * requests.
    *
    * This function is virtual to allow cross-library calls to SetEnabled()
    */
   virtual void ProcessPendingRequestsAsync();
 
   /**
-   * If true, the loader is ready to execute scripts, and so are all its
-   * ancestors.  If the loader itself is ready but some ancestor is not, this
-   * function will add an execute blocker and ask the ancestor to remove it
+   * If true, the loader is ready to execute parser-blocking scripts, and so are
+   * all its ancestors.  If the loader itself is ready but some ancestor is not,
+   * this function will add an execute blocker and ask the ancestor to remove it
    * once it becomes ready.
    */
-  bool ReadyToExecuteScripts();
+  bool ReadyToExecuteParserBlockingScripts();
 
   /**
-   * Return whether just this loader is ready to execute scripts.
+   * Return whether just this loader is ready to execute parser-blocking
+   * scripts.
    */
-  bool SelfReadyToExecuteScripts()
+  bool SelfReadyToExecuteParserBlockingScripts()
   {
-    return mEnabled && !mBlockerCount;
+    return mEnabled && !mParserBlockingBlockerCount;
   }
 
   nsresult AttemptAsyncScriptCompile(nsScriptLoadRequest* aRequest);
   nsresult ProcessRequest(nsScriptLoadRequest* aRequest);
   nsresult CompileOffThreadOrProcessRequest(nsScriptLoadRequest* aRequest);
   void FireScriptAvailable(nsresult aResult,
                            nsScriptLoadRequest* aRequest);
   void FireScriptEvaluated(nsresult aResult,
@@ -596,17 +598,17 @@ private:
   struct PreloadURIComparator {
     bool Equals(const PreloadInfo &aPi, nsIURI * const &aURI) const;
   };
   nsTArray<PreloadInfo> mPreloads;
 
   nsCOMPtr<nsIScriptElement> mCurrentScript;
   nsCOMPtr<nsIScriptElement> mCurrentParserInsertedScript;
   nsTArray< RefPtr<nsScriptLoader> > mPendingChildLoaders;
-  uint32_t mBlockerCount;
+  uint32_t mParserBlockingBlockerCount;
   uint32_t mNumberOfProcessors;
   bool mEnabled;
   bool mDeferEnabled;
   bool mDocumentParsingDone;
   bool mBlockingDOMContentLoaded;
 
   // Module map
   nsRefPtrHashtable<nsURIHashKey, mozilla::GenericPromise::Private> mFetchingModules;
--- a/dom/xml/nsXMLContentSink.cpp
+++ b/dom/xml/nsXMLContentSink.cpp
@@ -587,17 +587,17 @@ nsXMLContentSink::CloseElement(nsIConten
       ssle->SetEnableUpdates(true);
       bool willNotify;
       bool isAlternate;
       rv = ssle->UpdateStyleSheet(mRunsToCompletion ? nullptr : this,
                                   &willNotify,
                                   &isAlternate);
       if (NS_SUCCEEDED(rv) && willNotify && !isAlternate && !mRunsToCompletion) {
         ++mPendingSheetCount;
-        mScriptLoader->AddExecuteBlocker();
+        mScriptLoader->AddParserBlockingScriptExecutionBlocker();
       }
     }
   }
 
   return rv;
 }
 
 nsresult
@@ -1208,17 +1208,17 @@ nsXMLContentSink::HandleProcessingInstru
                                 &willNotify,
                                 &isAlternate);
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (willNotify) {
       // Successfully started a stylesheet load
       if (!isAlternate && !mRunsToCompletion) {
         ++mPendingSheetCount;
-        mScriptLoader->AddExecuteBlocker();
+        mScriptLoader->AddParserBlockingScriptExecutionBlocker();
       }
 
       return NS_OK;
     }
   }
 
   // If it's not a CSS stylesheet PI...
   nsAutoString type;
--- a/parser/html/nsHtml5DocumentBuilder.cpp
+++ b/parser/html/nsHtml5DocumentBuilder.cpp
@@ -73,17 +73,17 @@ nsHtml5DocumentBuilder::UpdateStyleSheet
 
   bool willNotify;
   bool isAlternate;
   nsresult rv = ssle->UpdateStyleSheet(mRunsToCompletion ? nullptr : this,
                                        &willNotify,
                                        &isAlternate);
   if (NS_SUCCEEDED(rv) && willNotify && !isAlternate && !mRunsToCompletion) {
     ++mPendingSheetCount;
-    mScriptLoader->AddExecuteBlocker();
+    mScriptLoader->AddParserBlockingScriptExecutionBlocker();
   }
 
   // Re-open update
   BeginDocUpdate();
 }
 
 void
 nsHtml5DocumentBuilder::SetDocumentMode(nsHtml5DocumentMode m)