Bug 1473865 part 4 - Use xpc::WindowOrNull instead of xpc::WindowGlobalOrNull in a few places. r=bz
authorJan de Mooij <jdemooij@mozilla.com>
Thu, 12 Jul 2018 16:17:44 +0200
changeset 481475 794fbe33724434570e3d87c770d10d4efa2772a9
parent 481474 3db02eb59e35c5a768bf5572b4392a35f5dfc459
child 481476 0e4f878576362662b150d36258cca477af4b53f4
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1473865
milestone63.0a1
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 1473865 part 4 - Use xpc::WindowOrNull instead of xpc::WindowGlobalOrNull in a few places. r=bz
dom/base/nsContentUtils.cpp
dom/base/nsDocument.cpp
dom/base/nsDocument.h
dom/script/ScriptSettings.cpp
js/xpconnect/wrappers/XrayWrapper.cpp
toolkit/mozapps/extensions/AddonManagerWebAPI.cpp
toolkit/mozapps/extensions/AddonManagerWebAPI.h
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -9650,17 +9650,18 @@ nsContentUtils::SerializeNodeToMarkup(ns
 
 bool
 nsContentUtils::IsSpecificAboutPage(JSObject* aGlobal, const char* aUri)
 {
   // aUri must start with about: or this isn't the right function to be using.
   MOZ_ASSERT(strncmp(aUri, "about:", 6) == 0);
 
   // Make sure the global is a window
-  nsGlobalWindowInner* win = xpc::WindowGlobalOrNull(aGlobal);
+  MOZ_DIAGNOSTIC_ASSERT(JS_IsGlobalObject(aGlobal));
+  nsGlobalWindowInner* win = xpc::WindowOrNull(aGlobal);
   if (!win) {
     return false;
   }
 
   nsCOMPtr<nsIPrincipal> principal = win->GetPrincipal();
   NS_ENSURE_TRUE(principal, false);
   nsCOMPtr<nsIURI> uri;
   principal->GetURI(getter_AddRefs(uri));
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -2594,19 +2594,20 @@ WarnIfSandboxIneffective(nsIDocShell* aD
 
 bool
 nsIDocument::IsSynthesized() {
   nsCOMPtr<nsILoadInfo> loadInfo = mChannel ? mChannel->GetLoadInfo() : nullptr;
   return loadInfo && loadInfo->GetServiceWorkerTaintingSynthesized();
 }
 
 bool
-nsDocument::IsShadowDOMEnabled(JSContext* aCx, JSObject* aObject)
-{
-  nsCOMPtr<nsPIDOMWindowInner> window = xpc::WindowGlobalOrNull(aObject);
+nsDocument::IsShadowDOMEnabled(JSContext* aCx, JSObject* aGlobal)
+{
+  MOZ_DIAGNOSTIC_ASSERT(JS_IsGlobalObject(aGlobal));
+  nsCOMPtr<nsPIDOMWindowInner> window = xpc::WindowOrNull(aGlobal);
 
   nsIDocument* doc = window ? window->GetExtantDoc() : nullptr;
   if (!doc) {
     return false;
   }
 
   return doc->IsShadowDOMEnabled();
 }
--- a/dom/base/nsDocument.h
+++ b/dom/base/nsDocument.h
@@ -189,18 +189,18 @@ public:
                                        bool aRequiredAdded) override;
   virtual bool GetValueMissingState(const nsAString& aName) const override;
   virtual void SetValueMissingState(const nsAString& aName, bool aValue) override;
 
   // for radio group
   nsRadioGroupStruct* GetRadioGroup(const nsAString& aName) const;
   nsRadioGroupStruct* GetOrCreateRadioGroup(const nsAString& aName);
 
-  // Check whether shadow DOM is enabled for the global of aObject.
-  static bool IsShadowDOMEnabled(JSContext* aCx, JSObject* aObject);
+  // Check whether shadow DOM is enabled for aGlobal.
+  static bool IsShadowDOMEnabled(JSContext* aCx, JSObject* aGlobal);
   // Check whether shadow DOM is enabled for the document this node belongs to.
   static bool IsShadowDOMEnabled(const nsINode* aNode);
 
 public:
   using mozilla::dom::DocumentOrShadowRoot::GetElementById;
   using mozilla::dom::DocumentOrShadowRoot::GetElementsByTagName;
   using mozilla::dom::DocumentOrShadowRoot::GetElementsByTagNameNS;
   using mozilla::dom::DocumentOrShadowRoot::GetElementsByClassName;
--- a/dom/script/ScriptSettings.cpp
+++ b/dom/script/ScriptSettings.cpp
@@ -563,25 +563,26 @@ AutoJSAPI::ReportException()
   JS::Rooted<JSObject*> errorGlobal(cx(), JS::CurrentGlobalOrNull(cx()));
   if (!errorGlobal) {
     if (mIsMainThread) {
       errorGlobal = xpc::PrivilegedJunkScope();
     } else {
       errorGlobal = GetCurrentThreadWorkerGlobal();
     }
   }
+  MOZ_ASSERT(JS_IsGlobalObject(errorGlobal));
   JSAutoRealm ar(cx(), errorGlobal);
   JS::Rooted<JS::Value> exn(cx());
   js::ErrorReport jsReport(cx());
   if (StealException(&exn) &&
       jsReport.init(cx(), exn, js::ErrorReport::WithSideEffects)) {
     if (mIsMainThread) {
       RefPtr<xpc::ErrorReport> xpcReport = new xpc::ErrorReport();
 
-      RefPtr<nsGlobalWindowInner> win = xpc::WindowGlobalOrNull(errorGlobal);
+      RefPtr<nsGlobalWindowInner> win = xpc::WindowOrNull(errorGlobal);
       nsPIDOMWindowInner* inner = win ? win->AsInner() : nullptr;
       bool isChrome = nsContentUtils::IsSystemPrincipal(
         nsContentUtils::ObjectPrincipal(errorGlobal));
       xpcReport->Init(jsReport.report(), jsReport.toStringResult().c_str(),
                       isChrome,
                       inner ? inner->WindowID() : 0);
       if (inner && jsReport.report()->errorNumber != JSMSG_OUT_OF_MEMORY) {
         JS::RootingContext* rcx = JS::RootingContext::get(cx());
--- a/js/xpconnect/wrappers/XrayWrapper.cpp
+++ b/js/xpconnect/wrappers/XrayWrapper.cpp
@@ -228,18 +228,17 @@ ReportWrapperDenial(JSContext* cx, Handl
     // Grab the pieces.
     nsCOMPtr<nsIConsoleService> consoleService = do_GetService(NS_CONSOLESERVICE_CONTRACTID);
     NS_ENSURE_TRUE(consoleService, true);
     nsCOMPtr<nsIScriptError> errorObject = do_CreateInstance(NS_SCRIPTERROR_CONTRACTID);
     NS_ENSURE_TRUE(errorObject, true);
 
     // Compute the current window id if any.
     uint64_t windowId = 0;
-    nsGlobalWindowInner* win = WindowGlobalOrNull(CurrentGlobalOrNull(cx));
-    if (win)
+    if (nsGlobalWindowInner* win = CurrentWindowOrNull(cx))
       windowId = win->WindowID();
 
 
     Maybe<nsPrintfCString> errorMessage;
     if (type == WrapperDenialForXray) {
         errorMessage.emplace("XrayWrapper denied access to property %s (reason: %s). "
                              "See https://developer.mozilla.org/en-US/docs/Xray_vision "
                              "for more information. Note that only the first denied "
--- a/toolkit/mozapps/extensions/AddonManagerWebAPI.cpp
+++ b/toolkit/mozapps/extensions/AddonManagerWebAPI.cpp
@@ -87,19 +87,20 @@ AddonManagerWebAPI::IsValidSite(nsIURI* 
   if (NS_FAILED(rv)) {
     return false;
   }
 
   return IsValidHost(host);
 }
 
 bool
-AddonManagerWebAPI::IsAPIEnabled(JSContext* cx, JSObject* obj)
+AddonManagerWebAPI::IsAPIEnabled(JSContext* aCx, JSObject* aGlobal)
 {
-  nsGlobalWindowInner* global = xpc::WindowGlobalOrNull(obj);
+  MOZ_DIAGNOSTIC_ASSERT(JS_IsGlobalObject(aGlobal));
+  nsGlobalWindowInner* global = xpc::WindowOrNull(aGlobal);
   if (!global) {
     return false;
   }
 
   nsCOMPtr<nsPIDOMWindowInner> win = global->AsInner();
   if (!win) {
     return false;
   }
--- a/toolkit/mozapps/extensions/AddonManagerWebAPI.h
+++ b/toolkit/mozapps/extensions/AddonManagerWebAPI.h
@@ -8,17 +8,17 @@
 #define addonmanagerwebapi_h_
 
 #include "nsPIDOMWindow.h"
 
 namespace mozilla {
 
 class AddonManagerWebAPI {
 public:
-  static bool IsAPIEnabled(JSContext* cx, JSObject* obj);
+  static bool IsAPIEnabled(JSContext* aCx, JSObject* aGlobal);
 
   static bool IsValidSite(nsIURI* uri);
 };
 
 namespace dom {
 
 class AddonManagerPermissions {
 public: