Bug 1497658 part 2. Stop using GetCurrentJSContext in CallerInnerWindow. r=mccr8
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 09 Oct 2018 17:02:13 -0400
changeset 440256 296fa4a869ae27297569005bb09b5bc4f3750ca0
parent 440255 b635e6611d125ec4ba09fa7733ffb6124784b276
child 440257 c19f84cb5fcbf896171350432d4476ba27d11d15
push id108772
push userbzbarsky@mozilla.com
push dateTue, 09 Oct 2018 21:02:34 +0000
treeherdermozilla-inbound@296fa4a869ae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
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 1497658 part 2. Stop using GetCurrentJSContext in CallerInnerWindow. r=mccr8 We're always called from script, so just pass through the JSContext.
--- a/dom/base/nsGlobalWindowOuter.cpp
+++ b/dom/base/nsGlobalWindowOuter.cpp
@@ -5614,35 +5614,33 @@ already_AddRefed<nsPIDOMWindowOuter>
   RefPtr<nsPIDOMWindowOuter> frames(this);
   return frames.forget();
-  JSContext *cx = nsContentUtils::GetCurrentJSContext();
-  NS_ENSURE_TRUE(cx, nullptr);
+nsGlobalWindowOuter::CallerInnerWindow(JSContext* aCx)
   nsIGlobalObject* global = GetIncumbentGlobal();
   NS_ENSURE_TRUE(global, nullptr);
-  JS::Rooted<JSObject*> scope(cx, global->GetGlobalJSObject());
+  JS::Rooted<JSObject*> scope(aCx, global->GetGlobalJSObject());
   NS_ENSURE_TRUE(scope, nullptr);
   // When Jetpack runs content scripts inside a sandbox, it uses
   // sandboxPrototype to make them appear as though they're running in the
   // scope of the page. So when a content script invokes postMessage, it expects
   // the |source| of the received message to be the window set as the
   // sandboxPrototype. This used to work incidentally for unrelated reasons, but
   // now we need to do some special handling to support it.
   if (xpc::IsSandbox(scope)) {
-    JSAutoRealm ar(cx, scope);
-    JS::Rooted<JSObject*> scopeProto(cx);
-    bool ok = JS_GetPrototype(cx, scope, &scopeProto);
+    JSAutoRealm ar(aCx, scope);
+    JS::Rooted<JSObject*> scopeProto(aCx);
+    bool ok = JS_GetPrototype(aCx, scope, &scopeProto);
     NS_ENSURE_TRUE(ok, nullptr);
     if (scopeProto && xpc::IsSandboxPrototypeProxy(scopeProto) &&
         (scopeProto = js::CheckedUnwrap(scopeProto, /* stopAtWindowProxy = */ false)))
       global = xpc::NativeGlobal(scopeProto);
       NS_ENSURE_TRUE(global, nullptr);
@@ -5664,17 +5662,17 @@ nsGlobalWindowOuter::PostMessageMozOuter
   // Window.postMessage is an intentional subversion of the same-origin policy.
   // As such, this code must be particularly careful in the information it
   // exposes to calling code.
   // http://www.whatwg.org/specs/web-apps/current-work/multipage/section-crossDocumentMessages.html
   // First, get the caller's window
-  RefPtr<nsGlobalWindowInner> callerInnerWin = CallerInnerWindow();
+  RefPtr<nsGlobalWindowInner> callerInnerWin = CallerInnerWindow(aCx);
   nsIPrincipal* callerPrin;
   if (callerInnerWin) {
     // Compute the caller's origin either from its principal or, in the case the
     // principal doesn't carry a URI (e.g. the system principal), the caller's
     // document.  We must get this now instead of when the event is created and
     // dispatched, because ultimately it is the identity of the calling window
     // *now* that determines who sent the message (and not an identity which might
     // have changed due to intervening navigations).
--- a/dom/base/nsGlobalWindowOuter.h
+++ b/dom/base/nsGlobalWindowOuter.h
@@ -802,17 +802,18 @@ protected:
   void DropOuterWindowDocs();
   void CleanUp();
   void ClearControllers();
   // Outer windows only.
   void FinalClose();
   inline void MaybeClearInnerWindow(nsGlobalWindowInner* aExpectedInner);
-  nsGlobalWindowInner *CallerInnerWindow();
+  // We need a JSContext to get prototypes inside CallerInnerWindow.
+  nsGlobalWindowInner* CallerInnerWindow(JSContext* aCx);
   // Get the parent, returns null if this is a toplevel window
   nsPIDOMWindowOuter* GetParentInternal();
   // popup tracking
   bool IsPopupSpamWindow();