Bug 1497301 part 2. Remove some dead code in Location methods. r=farre
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 12 Oct 2018 11:07:17 -0400
changeset 489208 c9e04519cd763068fa380109ffdf21978932c77e
parent 489207 9340d1867b1f4785bb3e6b2f1b97a969d7846632
child 489209 5d0df5f741700ae8e74d894ae95ae590b239e0ec
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersfarre
bugs1497301
milestone64.0a1
Bug 1497301 part 2. Remove some dead code in Location methods. r=farre The JSContext arg of SetHrefWithContext is unused, and the function should have a different name. All the current callers of SetHrefWithContext are always called from bindings, so we can't hit the "no jscontext" cases.
dom/base/Location.cpp
dom/base/Location.h
--- a/dom/base/Location.cpp
+++ b/dom/base/Location.cpp
@@ -427,48 +427,26 @@ Location::GetHref(nsAString& aHref)
   AppendUTF8toUTF16(uriString, aHref);
   return NS_OK;
 }
 
 void
 Location::SetHref(const nsAString& aHref,
                   ErrorResult& aRv)
 {
-  JSContext *cx = nsContentUtils::GetCurrentJSContext();
-  if (cx) {
-    aRv = SetHrefWithContext(cx, aHref, false);
-    return;
-  }
-
-  nsAutoString oldHref;
-  aRv = GetHref(oldHref);
-  if (NS_WARN_IF(aRv.Failed())) {
-    return;
-  }
-
-  nsCOMPtr<nsIURI> oldUri;
-  aRv = NS_NewURI(getter_AddRefs(oldUri), oldHref);
-  if (NS_WARN_IF(aRv.Failed())) {
-    return;
-  }
-
-  aRv = SetHrefWithBase(aHref, oldUri, false);
-  if (NS_WARN_IF(aRv.Failed())) {
-    return;
-  }
+  DoSetHref(aHref, false, aRv);
 }
 
-nsresult
-Location::SetHrefWithContext(JSContext* cx, const nsAString& aHref,
-                             bool aReplace)
+void
+Location::DoSetHref(const nsAString& aHref, bool aReplace, ErrorResult& aRv)
 {
   // Get the source of the caller
   nsCOMPtr<nsIURI> base = GetSourceBaseURL();
 
-  return SetHrefWithBase(aHref, base, aReplace);
+  aRv = SetHrefWithBase(aHref, base, aReplace);
 }
 
 nsresult
 Location::SetHrefWithBase(const nsAString& aHref, nsIURI* aBase,
                           bool aReplace)
 {
   nsresult result;
   nsCOMPtr<nsIURI> newUri;
@@ -875,67 +853,30 @@ Location::Reload(bool aForceget)
   return rv;
 }
 
 void
 Location::Replace(const nsAString& aUrl,
                   nsIPrincipal& aSubjectPrincipal,
                   ErrorResult& aRv)
 {
-  if (JSContext *cx = nsContentUtils::GetCurrentJSContext()) {
-    aRv = SetHrefWithContext(cx, aUrl, true);
-    return;
-  }
-
-  nsAutoString oldHref;
-  aRv = GetHref(oldHref);
-  if (NS_WARN_IF(aRv.Failed())) {
-    return;
-  }
-
-  nsCOMPtr<nsIURI> oldUri;
-
-  aRv = NS_NewURI(getter_AddRefs(oldUri), oldHref);
-  if (NS_WARN_IF(aRv.Failed())) {
-    return;
-  }
-
-  aRv = SetHrefWithBase(aUrl, oldUri, true);
+  DoSetHref(aUrl, true, aRv);
 }
 
 void
 Location::Assign(const nsAString& aUrl,
                  nsIPrincipal& aSubjectPrincipal,
                  ErrorResult& aRv)
 {
   if (!CallerSubsumes(&aSubjectPrincipal)) {
     aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
     return;
   }
 
-  if (JSContext *cx = nsContentUtils::GetCurrentJSContext()) {
-    aRv = SetHrefWithContext(cx, aUrl, false);
-    return;
-  }
-
-  nsAutoString oldHref;
-  aRv = GetHref(oldHref);
-  if (NS_WARN_IF(aRv.Failed())) {
-    return;
-  }
-
-  nsCOMPtr<nsIURI> oldUri;
-  aRv = NS_NewURI(getter_AddRefs(oldUri), oldHref);
-  if (NS_WARN_IF(aRv.Failed())) {
-    return;
-  }
-
-  if (oldUri) {
-    aRv = SetHrefWithBase(aUrl, oldUri, false);
-  }
+  DoSetHref(aUrl, false, aRv);
 }
 
 already_AddRefed<nsIURI>
 Location::GetSourceBaseURL()
 {
   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
--- a/dom/base/Location.h
+++ b/dom/base/Location.h
@@ -164,18 +164,19 @@ protected:
   // fetched from as the URI instead of the jar: uri itself.  Pass in
   // true for aGetInnermostURI when that's the case.
   // Note, this method can return NS_OK with a null value for aURL. This happens
   // 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);
+
+  // Helper for Assign/SetHref/Replace
+  void DoSetHref(const nsAString& aHref, bool aReplace, ErrorResult& aRv);
 
   // 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;