Bug 1518956 - Make C++ infallible/simplified versions of nsIURI::SchemeIs; r=valentin
authorKyle Machulis <kyle@nonpolynomial.com>
Fri, 11 Jan 2019 08:09:33 +0000
changeset 510632 85cbb065250d22e6d4e34fa5db536603cb205fbd
parent 510631 92a30f1b817cba3154156a74bee123fc1af7b647
child 510633 9a0c93ab6a40c523de1e808c2ef38b50b247232d
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1518956
milestone66.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 1518956 - Make C++ infallible/simplified versions of nsIURI::SchemeIs; r=valentin SchemeIs only throws exceptions on null arguments now. Assert arguments, as they should never be null anyways, and create an infallible C++ version. Differential Revision: https://phabricator.services.mozilla.com/D16143
image/decoders/icon/nsIconURI.cpp
modules/libjar/nsJARURI.cpp
netwerk/base/nsIURI.idl
netwerk/base/nsSimpleURI.cpp
netwerk/base/nsStandardURL.cpp
--- a/image/decoders/icon/nsIconURI.cpp
+++ b/image/decoders/icon/nsIconURI.cpp
@@ -413,20 +413,18 @@ NS_IMETHODIMP
 nsMozIconURI::EqualsExceptRef(nsIURI* other, bool* result) {
   // GetRef/SetRef not supported by nsMozIconURI, so
   // EqualsExceptRef() is the same as Equals().
   return Equals(other, result);
 }
 
 NS_IMETHODIMP
 nsMozIconURI::SchemeIs(const char* aScheme, bool* aEquals) {
-  NS_ENSURE_ARG_POINTER(aEquals);
-  if (!aScheme) {
-    return NS_ERROR_INVALID_ARG;
-  }
+  MOZ_ASSERT(aScheme);
+  MOZ_ASSERT(aEquals, "null pointer");
 
   *aEquals = PL_strcasecmp("moz-icon", aScheme) ? false : true;
   return NS_OK;
 }
 
 nsresult nsMozIconURI::Clone(nsIURI** result) {
   nsCOMPtr<nsIURL> newIconURL;
   if (mIconURL) {
--- a/modules/libjar/nsJARURI.cpp
+++ b/modules/libjar/nsJARURI.cpp
@@ -470,24 +470,20 @@ nsJARURI::EqualsExceptRef(nsIURI *other,
 
   return refHandlingMode == eHonorRef
              ? mJAREntry->Equals(otherJAR->mJAREntry, result)
              : mJAREntry->EqualsExceptRef(otherJAR->mJAREntry, result);
 }
 
 NS_IMETHODIMP
 nsJARURI::SchemeIs(const char *i_Scheme, bool *o_Equals) {
-  NS_ENSURE_ARG_POINTER(o_Equals);
-  if (!i_Scheme) return NS_ERROR_INVALID_ARG;
+  MOZ_ASSERT(i_Scheme);
+  MOZ_ASSERT(o_Equals);
 
-  if (*i_Scheme == 'j' || *i_Scheme == 'J') {
-    *o_Equals = PL_strcasecmp("jar", i_Scheme) ? false : true;
-  } else {
-    *o_Equals = false;
-  }
+  *o_Equals = PL_strcasecmp("jar", i_Scheme) ? false : true;
   return NS_OK;
 }
 
 nsresult nsJARURI::Clone(nsIURI **result) {
   nsresult rv;
 
   nsCOMPtr<nsIJARURI> uri;
   rv = CloneWithJARFileInternal(mJARFile, eHonorRef, getter_AddRefs(uri));
--- a/netwerk/base/nsIURI.idl
+++ b/netwerk/base/nsIURI.idl
@@ -176,16 +176,27 @@ interface nsIURI : nsISupports
 
     /**
      * An optimization to do scheme checks without requiring the users of nsIURI
      * to GetScheme, thereby saving extra allocating and freeing. Returns true if
      * the schemes match (case ignored).
      */
     boolean schemeIs(in string scheme);
 
+    /*
+     * Infallible version of SchemeIs for C++ callers.
+     */
+    %{C++
+     bool SchemeIs(const char* aScheme) {
+       bool ret;
+       mozilla::Unused << SchemeIs(aScheme, &ret);
+       return ret;
+     }
+    %}
+
     /**
      * This method resolves a relative string into an absolute URI string,
      * using this URI as the base. 
      *
      * NOTE: some implementations may have no concept of a relative URI.
      */
     AUTF8String resolve(in AUTF8String relativePath);
 
--- a/netwerk/base/nsSimpleURI.cpp
+++ b/netwerk/base/nsSimpleURI.cpp
@@ -518,18 +518,18 @@ bool nsSimpleURI::EqualsInternal(nsSimpl
               (!mIsRefValid || mRef == otherUri->mRef));
   }
 
   return result;
 }
 
 NS_IMETHODIMP
 nsSimpleURI::SchemeIs(const char *i_Scheme, bool *o_Equals) {
-  NS_ENSURE_ARG_POINTER(o_Equals);
-  if (!i_Scheme) return NS_ERROR_NULL_POINTER;
+  MOZ_ASSERT(i_Scheme);
+  MOZ_ASSERT(o_Equals, "null pointer");
 
   const char *this_scheme = mScheme.get();
 
   // mScheme is guaranteed to be lower case.
   if (*i_Scheme == *this_scheme || *i_Scheme == (*this_scheme - ('a' - 'A'))) {
     *o_Equals = PL_strcasecmp(this_scheme, i_Scheme) ? false : true;
   } else {
     *o_Equals = false;
--- a/netwerk/base/nsStandardURL.cpp
+++ b/netwerk/base/nsStandardURL.cpp
@@ -2199,16 +2199,17 @@ nsresult nsStandardURL::EqualsInternal(
   // same file, so they are different.
   *result = false;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsStandardURL::SchemeIs(const char *scheme, bool *result) {
+  MOZ_ASSERT(scheme);
   MOZ_ASSERT(result, "null pointer");
 
   *result = SegmentIs(mScheme, scheme);
   return NS_OK;
 }
 
 /* virtual */ nsStandardURL *nsStandardURL::StartClone() {
   nsStandardURL *clone = new nsStandardURL();