Bug 981796 - Don't assume that the active global is our global. r=smaug draft
authorBlake Kaplan <mrbkap@gmail.com>
Fri, 16 Jun 2017 11:42:23 -0700
changeset 595794 99ec17bc0c0cbc3be8d50fe2d3fb2e4464d15103
parent 595793 e287a9e6be8d33b713ec99cad625ae35cc51f61d
child 595795 e5909e66dcd888abd774abf0a1fadcf12b518824
push id64450
push userbmo:mrbkap@mozilla.com
push dateFri, 16 Jun 2017 21:30:02 +0000
reviewerssmaug
bugs981796
milestone56.0a1
Bug 981796 - Don't assume that the active global is our global. r=smaug Without this, grabbing another window's showModalDialog function and calling it with this being a second window asserts. MozReview-Commit-ID: GvGUClFwdoN
dom/base/nsGlobalWindow.cpp
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -10114,18 +10114,22 @@ nsGlobalWindow::ShowModalDialog(JSContex
   nsCOMPtr<nsIVariant> retVal =
     ShowModalDialog(aUrl, args, aOptions, aSubjectPrincipal, aError);
   if (aError.Failed()) {
     return;
   }
 
   JS::Rooted<JS::Value> result(aCx);
   if (retVal) {
+    JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
+    if (!global) {
+      global = FastGetGlobalJSObject();
+    }
     aError = nsContentUtils::XPConnect()->VariantToJS(aCx,
-                                                      FastGetGlobalJSObject(),
+                                                      global,
                                                       retVal, aRetval);
   } else {
     aRetval.setNull();
   }
 }
 
 class ChildCommandDispatcher : public Runnable
 {