Bug 1497301 part 1. Remove the JSContext arg of Location::GetSourceBaseURL. r=farre
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 12 Oct 2018 11:07:17 -0400
changeset 489207 9340d1867b1f4785bb3e6b2f1b97a969d7846632
parent 489206 80983dcd1180daeaaf7da3201b48c63506b6f6c7
child 489208 c9e04519cd763068fa380109ffdf21978932c77e
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersfarre
bugs1497301
milestone64.0a1
Bug 1497301 part 1. Remove the JSContext arg of Location::GetSourceBaseURL. r=farre It's unused. Also, this function never fails, so there's no reason to have the nsresult return type.
dom/base/Location.cpp
dom/base/Location.h
--- a/dom/base/Location.cpp
+++ b/dom/base/Location.cpp
@@ -455,24 +455,18 @@ Location::SetHref(const nsAString& aHref
     return;
   }
 }
 
 nsresult
 Location::SetHrefWithContext(JSContext* cx, const nsAString& aHref,
                              bool aReplace)
 {
-  nsCOMPtr<nsIURI> base;
-
   // Get the source of the caller
-  nsresult result = GetSourceBaseURL(cx, getter_AddRefs(base));
-
-  if (NS_FAILED(result)) {
-    return result;
-  }
+  nsCOMPtr<nsIURI> base = GetSourceBaseURL();
 
   return SetHrefWithBase(aHref, base, aReplace);
 }
 
 nsresult
 Location::SetHrefWithBase(const nsAString& aHref, nsIURI* aBase,
                           bool aReplace)
 {
@@ -934,38 +928,36 @@ Location::Assign(const nsAString& aUrl,
     return;
   }
 
   if (oldUri) {
     aRv = SetHrefWithBase(aUrl, oldUri, false);
   }
 }
 
-nsresult
-Location::GetSourceBaseURL(JSContext* cx, nsIURI** sourceURL)
+already_AddRefed<nsIURI>
+Location::GetSourceBaseURL()
 {
-  *sourceURL = nullptr;
   nsIDocument* doc = GetEntryDocument();
   // If there's no entry document, we either have no Script Entry Point or one
   // that isn't a DOM Window.  This doesn't generally happen with the DOM, but
   // can sometimes happen with extension code in certain IPC configurations.  If
   // this happens, try falling back on the current document associated with the
   // docshell. If that fails, just return null and hope that the caller passed
   // an absolute URI.
   nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell));
   if (!doc && docShell) {
     nsCOMPtr<nsPIDOMWindowOuter> docShellWin =
       do_QueryInterface(docShell->GetScriptGlobalObject());
     if (docShellWin) {
       doc = docShellWin->GetDoc();
     }
   }
-  NS_ENSURE_TRUE(doc, NS_OK);
-  *sourceURL = doc->GetBaseURI().take();
-  return NS_OK;
+  NS_ENSURE_TRUE(doc, nullptr);
+  return doc->GetBaseURI();
 }
 
 bool
 Location::CallerSubsumes(nsIPrincipal* aSubjectPrincipal)
 {
   MOZ_ASSERT(aSubjectPrincipal);
 
   // Get the principal associated with the location object.  Note that this is
--- a/dom/base/Location.h
+++ b/dom/base/Location.h
@@ -167,17 +167,19 @@ protected:
   // if the docShell is null.
   nsresult GetURI(nsIURI** aURL, bool aGetInnermostURI = false);
   nsresult SetURI(nsIURI* aURL, bool aReplace = false);
   nsresult SetHrefWithBase(const nsAString& aHref, nsIURI* aBase,
                            bool aReplace);
   nsresult SetHrefWithContext(JSContext* cx, const nsAString& aHref,
                               bool aReplace);
 
-  nsresult GetSourceBaseURL(JSContext* cx, nsIURI** sourceURL);
+  // Get the base URL we should be using for our relative URL
+  // resolution for SetHref/Assign/Replace.
+  already_AddRefed<nsIURI> GetSourceBaseURL();
   nsresult CheckURL(nsIURI *url, nsDocShellLoadInfo** aLoadInfo);
   bool CallerSubsumes(nsIPrincipal* aSubjectPrincipal);
 
   nsString mCachedHash;
   nsCOMPtr<nsPIDOMWindowInner> mInnerWindow;
   nsWeakPtr mDocShell;
 };