Bug 1625172 - Use early return in LocationBase::SetURI. r=nika
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 26 Mar 2020 15:29:53 +0000
changeset 520594 2af0c41aaf248806017dcc4cdf6b0563b8ce4d0f
parent 520593 37445084f5f86f46d281d007ed5d26ae76ad6c37
child 520595 68e481a7ae7d8db3f1f83605af1fc20b9d748cbc
push id37253
push usernerli@mozilla.com
push dateThu, 26 Mar 2020 21:36:52 +0000
treeherdermozilla-central@c644dd16e2cc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnika
bugs1625172
milestone76.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 1625172 - Use early return in LocationBase::SetURI. r=nika Just a minor cleanup while I was reading through our navigation code. Differential Revision: https://phabricator.services.mozilla.com/D68393
dom/base/LocationBase.cpp
--- a/dom/base/LocationBase.cpp
+++ b/dom/base/LocationBase.cpp
@@ -105,45 +105,47 @@ already_AddRefed<nsDocShellLoadState> Lo
   }
 
   return loadState.forget();
 }
 
 void LocationBase::SetURI(nsIURI* aURI, nsIPrincipal& aSubjectPrincipal,
                           ErrorResult& aRv, bool aReplace) {
   RefPtr<BrowsingContext> bc = GetBrowsingContext();
-  if (bc && !bc->IsDiscarded()) {
-    RefPtr<nsDocShellLoadState> loadState =
-        CheckURL(aURI, aSubjectPrincipal, aRv);
-    if (aRv.Failed()) {
-      return;
-    }
+  if (!bc || bc->IsDiscarded()) {
+    return;
+  }
 
-    if (aReplace) {
-      loadState->SetLoadType(LOAD_STOP_CONTENT_AND_REPLACE);
-    } else {
-      loadState->SetLoadType(LOAD_STOP_CONTENT);
-    }
+  RefPtr<nsDocShellLoadState> loadState =
+      CheckURL(aURI, aSubjectPrincipal, aRv);
+  if (aRv.Failed()) {
+    return;
+  }
+
+  if (aReplace) {
+    loadState->SetLoadType(LOAD_STOP_CONTENT_AND_REPLACE);
+  } else {
+    loadState->SetLoadType(LOAD_STOP_CONTENT);
+  }
 
-    // Get the incumbent script's browsing context to set as source.
-    nsCOMPtr<nsPIDOMWindowInner> sourceWindow =
-        nsContentUtils::CallerInnerWindow();
-    RefPtr<BrowsingContext> accessingBC;
-    if (sourceWindow) {
-      accessingBC = sourceWindow->GetBrowsingContext();
-      loadState->SetSourceDocShell(sourceWindow->GetDocShell());
-    }
+  // Get the incumbent script's browsing context to set as source.
+  nsCOMPtr<nsPIDOMWindowInner> sourceWindow =
+      nsContentUtils::CallerInnerWindow();
+  RefPtr<BrowsingContext> accessingBC;
+  if (sourceWindow) {
+    accessingBC = sourceWindow->GetBrowsingContext();
+    loadState->SetSourceDocShell(sourceWindow->GetDocShell());
+  }
 
-    loadState->SetLoadFlags(nsIWebNavigation::LOAD_FLAGS_NONE);
-    loadState->SetFirstParty(true);
+  loadState->SetLoadFlags(nsIWebNavigation::LOAD_FLAGS_NONE);
+  loadState->SetFirstParty(true);
 
-    nsresult rv = bc->LoadURI(accessingBC, loadState);
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-      aRv.Throw(rv);
-    }
+  nsresult rv = bc->LoadURI(accessingBC, loadState);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    aRv.Throw(rv);
   }
 }
 
 void LocationBase::SetHref(const nsAString& aHref,
                            nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv) {
   DoSetHref(aHref, aSubjectPrincipal, false, aRv);
 }