Bug 1329403 - ensure onload blocker is added once mScriptGlobalObject is set. r=smaug draft
authorJW Wang <jwwang@mozilla.com>
Mon, 16 Jan 2017 17:12:33 +0800
changeset 462365 fdfbee5da5378ee79343191cd5fa8165ece921c9
parent 462364 fdbc7566dcd8fe14b2ed5a8444359433b6df6e5e
child 462366 7335925ca999f421e3699d28435906c02d6ce127
push id41718
push userjwwang@mozilla.com
push dateTue, 17 Jan 2017 06:24:55 +0000
reviewerssmaug
bugs1329403
milestone53.0a1
Bug 1329403 - ensure onload blocker is added once mScriptGlobalObject is set. r=smaug MozReview-Commit-ID: KREnly28m0v
dom/base/nsDocument.cpp
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -4565,18 +4565,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) {
     // Go back to using the docshell for the layout history state
     mLayoutHistoryState = nullptr;
     SetScopeObject(aScriptGlobalObject);
     mHasHadDefaultView = true;
 #ifdef DEBUG
     if (!mWillReparent) {
       // We really shouldn't have a wrapper here but if we do we need to make sure