Bug 1295103 - Use MOZ_MUST_USE in OriginAttributes. r=allstarschh draft
authorKan-Ru Chen <kanru@kanru.info>
Mon, 15 Aug 2016 18:22:44 +0800
changeset 404366 fafb3e005c6869a1c9943b89ffc7fce60397a3be
parent 404365 d7897a47bb5dc1c588bbbd6c57e8edce158690f2
child 529173 2661e94b8898959c81b36d7373ea66ab15de3892
push id27198
push userbmo:kchen@mozilla.com
push dateTue, 23 Aug 2016 10:29:41 +0000
reviewersallstarschh
bugs1295103
milestone51.0a1
Bug 1295103 - Use MOZ_MUST_USE in OriginAttributes. r=allstarschh MozReview-Commit-ID: PWUb81L8ya
caps/BasePrincipal.h
caps/nsJSPrincipals.cpp
caps/tests/gtest/TestOriginAttributes.cpp
--- a/caps/BasePrincipal.h
+++ b/caps/BasePrincipal.h
@@ -6,16 +6,17 @@
 
 #ifndef mozilla_BasePrincipal_h
 #define mozilla_BasePrincipal_h
 
 #include "nsIPrincipal.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsJSPrincipals.h"
 
+#include "mozilla/Attributes.h"
 #include "mozilla/dom/ChromeUtilsBinding.h"
 
 class nsIContentSecurityPolicy;
 class nsIObjectOutputStream;
 class nsIObjectInputStream;
 class nsIURI;
 
 class nsExpandedPrincipal;
@@ -40,21 +41,21 @@ public:
   {
     return !(*this == aOther);
   }
 
   // Serializes/Deserializes non-default values into the suffix format, i.e.
   // |!key1=value1&key2=value2|. If there are no non-default attributes, this
   // returns an empty string.
   void CreateSuffix(nsACString& aStr) const;
-  bool PopulateFromSuffix(const nsACString& aStr);
+  MOZ_MUST_USE bool PopulateFromSuffix(const nsACString& aStr);
 
   // Populates the attributes from a string like
   // |uri!key1=value1&key2=value2| and returns the uri without the suffix.
-  bool PopulateFromOrigin(const nsACString& aOrigin,
+  MOZ_MUST_USE bool PopulateFromOrigin(const nsACString& aOrigin,
                           nsACString& aOriginNoSuffix);
 
   // Helper function to match mIsPrivateBrowsing to existing private browsing
   // flags. Once all other flags are removed, this can be removed too.
   void SyncAttributesWithPrivateBrowsing(bool aInPrivateBrowsing);
 
 protected:
   OriginAttributes() {}
--- a/caps/nsJSPrincipals.cpp
+++ b/caps/nsJSPrincipals.cpp
@@ -134,17 +134,19 @@ ReadSuffixAndSpec(JSStructuredCloneReade
     }
 
     nsAutoCString suffix;
     suffix.SetLength(suffixLength);
     if (!JS_ReadBytes(aReader, suffix.BeginWriting(), suffixLength)) {
         return false;
     }
 
-    aAttrs.PopulateFromSuffix(suffix);
+    if (!aAttrs.PopulateFromSuffix(suffix)) {
+        return false;
+    }
 
     aSpec.SetLength(specLength);
     if (!JS_ReadBytes(aReader, aSpec.BeginWriting(), specLength)) {
         return false;
     }
 
     return true;
 }
--- a/caps/tests/gtest/TestOriginAttributes.cpp
+++ b/caps/tests/gtest/TestOriginAttributes.cpp
@@ -8,17 +8,18 @@ using mozilla::PrincipalOriginAttributes
 
 static void
 TestSuffix(const PrincipalOriginAttributes& attrs)
 {
   nsAutoCString suffix;
   attrs.CreateSuffix(suffix);
 
   PrincipalOriginAttributes attrsFromSuffix;
-  attrsFromSuffix.PopulateFromSuffix(suffix);
+  bool success = attrsFromSuffix.PopulateFromSuffix(suffix);
+  EXPECT_TRUE(success);
 
   EXPECT_EQ(attrs, attrsFromSuffix);
 }
 
 TEST(PrincipalOriginAttributes, Suffix_default)
 {
   PrincipalOriginAttributes attrs;
   TestSuffix(attrs);