Bug 1329403 - Ensure onload blocker is added once mScriptGlobalObject is set. r=smaug, a=lizzard
authorJW Wang <jwwang@mozilla.com>
Mon, 16 Jan 2017 17:12:33 +0800
changeset 487393 910ad552cbf529656161b68f394a205216754f06
parent 487392 237c1ca6e035e9c60d8f4585550749efad1a8538
child 487394 6e61b5e5a06040c7be3c9127674419bae9421e39
push id46228
push userpaul@paul.cx
push dateTue, 21 Feb 2017 16:19:44 +0000
reviewerssmaug, lizzard
bugs1329403
milestone45.7.0
Bug 1329403 - Ensure onload blocker is added once mScriptGlobalObject is set. r=smaug, a=lizzard MozReview-Commit-ID: KREnly28m0v
dom/base/nsDocument.cpp
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -4525,18 +4525,26 @@ nsDocument::SetScriptGlobalObject(nsIScr
     if (mOnloadBlockCount != 0) {
       nsCOMPtr<nsILoadGroup> loadGroup = GetDocumentLoadGroup();
       if (loadGroup) {
         loadGroup->RemoveRequest(mOnloadBlocker, nullptr, NS_OK);
       }
     }
   }
 
+  // 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) {