Bug 1329403 - Ensure onload blocker is added once mScriptGlobalObject is set. r=smaug, a=lizzard FIREFOX_BETA_51_END
authorJW Wang <jwwang@mozilla.com>
Mon, 16 Jan 2017 17:12:33 +0800
changeset 359418 8e692dd4176cba81ce020b29ae8b352dc1db724a
parent 359416 dd4b8065a9a9ba168c84674bcd4071b0b4a8b7b0
child 359419 ea82b5e20cbbd103f8fa65f0df0386ee4135cc47
child 368800 af746446a1bf5ea06e79f10e6296fc81e5fee0c4
push id1334
push userryanvm@gmail.com
push dateWed, 18 Jan 2017 20:36:59 +0000
treeherdermozilla-release@ea82b5e20cbb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, lizzard
bugs1329403
milestone51.0
Bug 1329403 - Ensure onload blocker is added once mScriptGlobalObject is set. r=smaug, a=lizzard CLOSED TREE MozReview-Commit-ID: KREnly28m0v
dom/base/nsDocument.cpp
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -4519,18 +4519,26 @@ nsDocument::SetScriptGlobalObject(nsIScr
     // clients.  We only do this for content principal documents
     // since we can never observe system or null principals.
     nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
     if (os) {
       os->AddObserver(this, "service-worker-get-client", /* ownsWeak */ false);
     }
   }
 
+  // BlockOnload() might be called before mScriptGlobalObject is set.
+  // We may need to add the blocker once mScriptGlobalObject is set.
+  bool needOnloadBlocker = !mScriptGlobalObject && aScriptGlobalObject;
+
   mScriptGlobalObject = aScriptGlobalObject;
 
+  if (needOnloadBlocker) {
+    EnsureOnloadBlocker();
+  }
+
   if (aScriptGlobalObject) {
     mHasHadScriptHandlingObject = true;
     mHasHadDefaultView = true;
     // Go back to using the docshell for the layout history state
     mLayoutHistoryState = nullptr;
     mScopeObject = do_GetWeakReference(aScriptGlobalObject);
 #ifdef DEBUG
     if (!mWillReparent) {