Bug 1268772 (part 2) - Make infallible nsVariant methods return |void| instead of |nsresult|. r=erahm.
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 29 Apr 2016 13:47:44 +1000
changeset 295702 4cbd94383852a0f3840d59b951fc6b45f9e64d01
parent 295701 18a2873bb694e50649eb258cfa957a81bd45841f
child 295703 a2061ce934cbd547eb692165d819224a40d940c8
push id19015
push usercbook@mozilla.com
push dateMon, 02 May 2016 09:39:23 +0000
treeherderfx-team@2080375bc69d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm
bugs1268772
milestone49.0a1
Bug 1268772 (part 2) - Make infallible nsVariant methods return |void| instead of |nsresult|. r=erahm. This makes things clearer and removes some unnecessary nsresult checks. The patch also: - removes some unnecessary |new| and moz_xmalloc() checks; - adds MOZ_MUST_USE to some fallible nsVariant methods.
js/xpconnect/src/XPCVariant.cpp
xpcom/ds/nsVariant.cpp
xpcom/ds/nsVariant.h
--- a/js/xpconnect/src/XPCVariant.cpp
+++ b/js/xpconnect/src/XPCVariant.cpp
@@ -257,38 +257,47 @@ XPCArrayHomogenizer::GetTypeForArray(JSC
 }
 
 bool XPCVariant::InitializeData(JSContext* cx)
 {
     JS_CHECK_RECURSION(cx, return false);
 
     RootedValue val(cx, GetJSVal());
 
-    if (val.isInt32())
-        return NS_SUCCEEDED(mData.SetFromInt32(val.toInt32()));
-    if (val.isDouble())
-        return NS_SUCCEEDED(mData.SetFromDouble(val.toDouble()));
-    if (val.isBoolean())
-        return NS_SUCCEEDED(mData.SetFromBool(val.toBoolean()));
+    if (val.isInt32()) {
+        mData.SetFromInt32(val.toInt32());
+        return true;
+    }
+    if (val.isDouble()) {
+        mData.SetFromDouble(val.toDouble());
+        return true;
+    }
+    if (val.isBoolean()) {
+        mData.SetFromBool(val.toBoolean());
+        return true;
+    }
     // We can't represent symbol on C++ side, so pretend it is void.
-    if (val.isUndefined() || val.isSymbol())
-        return NS_SUCCEEDED(mData.SetToVoid());
-    if (val.isNull())
-        return NS_SUCCEEDED(mData.SetToEmpty());
+    if (val.isUndefined() || val.isSymbol()) {
+        mData.SetToVoid();
+        return true;
+    }
+    if (val.isNull()) {
+        mData.SetToEmpty();
+        return true;
+    }
     if (val.isString()) {
         JSString* str = val.toString();
         if (!str)
             return false;
 
         MOZ_ASSERT(mData.GetType() == nsIDataType::VTYPE_EMPTY,
                    "Why do we already have data?");
 
         size_t length = JS_GetStringLength(str);
-        if (!NS_SUCCEEDED(mData.AllocateWStringWithSize(length)))
-            return false;
+        mData.AllocateWStringWithSize(length);
 
         mozilla::Range<char16_t> destChars(mData.u.wstr.mWStringValue, length);
         if (!JS_CopyStringChars(cx, destChars, str))
             return false;
 
         MOZ_ASSERT(mData.u.wstr.mWStringValue[length] == '\0');
         return true;
     }
@@ -296,18 +305,20 @@ bool XPCVariant::InitializeData(JSContex
     // leaving only JSObject...
     MOZ_ASSERT(val.isObject(), "invalid type of jsval!");
 
     RootedObject jsobj(cx, &val.toObject());
 
     // Let's see if it is a xpcJSID.
 
     const nsID* id = xpc_JSObjectToID(cx, jsobj);
-    if (id)
-        return NS_SUCCEEDED(mData.SetFromID(*id));
+    if (id) {
+        mData.SetFromID(*id);
+        return true;
+    }
 
     // Let's see if it is a js array object.
 
     uint32_t len;
 
     bool isArray;
     if (!JS_IsArrayObject(cx, jsobj, &isArray) ||
         (isArray && !JS_GetArrayLength(cx, jsobj, &len)))
@@ -342,19 +353,22 @@ bool XPCVariant::InitializeData(JSContex
     }
 
     // XXX This could be smarter and pick some more interesting iface.
 
     nsXPConnect*  xpc = nsXPConnect::XPConnect();
     nsCOMPtr<nsISupports> wrapper;
     const nsIID& iid = NS_GET_IID(nsISupports);
 
-    return NS_SUCCEEDED(xpc->WrapJS(cx, jsobj,
-                                    iid, getter_AddRefs(wrapper))) &&
-           NS_SUCCEEDED(mData.SetFromInterface(iid, wrapper));
+    if (NS_FAILED(xpc->WrapJS(cx, jsobj, iid, getter_AddRefs(wrapper)))) {
+        return false;
+    }
+
+    mData.SetFromInterface(iid, wrapper);
+    return true;
 }
 
 NS_IMETHODIMP
 XPCVariant::GetAsJSVal(MutableHandleValue result)
 {
   result.set(GetJSVal());
   return NS_OK;
 }
--- a/xpcom/ds/nsVariant.cpp
+++ b/xpcom/ds/nsVariant.cpp
@@ -1196,18 +1196,17 @@ nsDiscriminatedUnion::ConvertToArray(uin
 
 /***************************************************************************/
 // static setter functions...
 
 #define DATA_SETTER_PROLOGUE                                                  \
     Cleanup()
 
 #define DATA_SETTER_EPILOGUE(type_)                                           \
-    mType = nsIDataType::type_;                                               \
-    return NS_OK
+    mType = nsIDataType::type_;
 
 #define DATA_SETTER(type_, member_, value_)                                   \
     DATA_SETTER_PROLOGUE;                                                     \
     u.member_ = value_;                                                       \
     DATA_SETTER_EPILOGUE(type_)
 
 #define DATA_SETTER_WITH_CAST(type_, member_, cast_, value_)                  \
     DATA_SETTER_PROLOGUE;                                                     \
@@ -1336,139 +1335,134 @@ nsDiscriminatedUnion::SetFromVariant(nsI
       CASE__SET_FROM_VARIANT_VTYPE_PROLOGUE(VTYPE_ARRAY);
       rv = aValue->GetAsArray(&u.array.mArrayType,
                               &u.array.mArrayInterfaceID,
                               &u.array.mArrayCount,
                               &u.array.mArrayValue);
       CASE__SET_FROM_VARIANT_VTYPE_EPILOGUE(VTYPE_ARRAY)
 
     case nsIDataType::VTYPE_VOID:
-      rv = SetToVoid();
+      SetToVoid();
+      rv = NS_OK;
       break;
     case nsIDataType::VTYPE_EMPTY_ARRAY:
-      rv = SetToEmptyArray();
+      SetToEmptyArray();
+      rv = NS_OK;
       break;
     case nsIDataType::VTYPE_EMPTY:
-      rv = SetToEmpty();
+      SetToEmpty();
+      rv = NS_OK;
       break;
     default:
       NS_ERROR("bad type in variant!");
       rv = NS_ERROR_FAILURE;
       break;
   }
   return rv;
 }
 
-nsresult
+void
 nsDiscriminatedUnion::SetFromInt8(uint8_t aValue)
 {
   DATA_SETTER_WITH_CAST(VTYPE_INT8, mInt8Value, (uint8_t), aValue);
 }
-nsresult
+void
 nsDiscriminatedUnion::SetFromInt16(int16_t aValue)
 {
   DATA_SETTER(VTYPE_INT16, mInt16Value, aValue);
 }
-nsresult
+void
 nsDiscriminatedUnion::SetFromInt32(int32_t aValue)
 {
   DATA_SETTER(VTYPE_INT32, mInt32Value, aValue);
 }
-nsresult
+void
 nsDiscriminatedUnion::SetFromInt64(int64_t aValue)
 {
   DATA_SETTER(VTYPE_INT64, mInt64Value, aValue);
 }
-nsresult
+void
 nsDiscriminatedUnion::SetFromUint8(uint8_t aValue)
 {
   DATA_SETTER(VTYPE_UINT8, mUint8Value, aValue);
 }
-nsresult
+void
 nsDiscriminatedUnion::SetFromUint16(uint16_t aValue)
 {
   DATA_SETTER(VTYPE_UINT16, mUint16Value, aValue);
 }
-nsresult
+void
 nsDiscriminatedUnion::SetFromUint32(uint32_t aValue)
 {
   DATA_SETTER(VTYPE_UINT32, mUint32Value, aValue);
 }
-nsresult
+void
 nsDiscriminatedUnion::SetFromUint64(uint64_t aValue)
 {
   DATA_SETTER(VTYPE_UINT64, mUint64Value, aValue);
 }
-nsresult
+void
 nsDiscriminatedUnion::SetFromFloat(float aValue)
 {
   DATA_SETTER(VTYPE_FLOAT, mFloatValue, aValue);
 }
-nsresult
+void
 nsDiscriminatedUnion::SetFromDouble(double aValue)
 {
   DATA_SETTER(VTYPE_DOUBLE, mDoubleValue, aValue);
 }
-nsresult
+void
 nsDiscriminatedUnion::SetFromBool(bool aValue)
 {
   DATA_SETTER(VTYPE_BOOL, mBoolValue, aValue);
 }
-nsresult
+void
 nsDiscriminatedUnion::SetFromChar(char aValue)
 {
   DATA_SETTER(VTYPE_CHAR, mCharValue, aValue);
 }
-nsresult
+void
 nsDiscriminatedUnion::SetFromWChar(char16_t aValue)
 {
   DATA_SETTER(VTYPE_WCHAR, mWCharValue, aValue);
 }
-nsresult
+void
 nsDiscriminatedUnion::SetFromID(const nsID& aValue)
 {
   DATA_SETTER(VTYPE_ID, mIDValue, aValue);
 }
-nsresult
+void
 nsDiscriminatedUnion::SetFromAString(const nsAString& aValue)
 {
   DATA_SETTER_PROLOGUE;
-  if (!(u.mAStringValue = new nsString(aValue))) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
+  u.mAStringValue = new nsString(aValue);
   DATA_SETTER_EPILOGUE(VTYPE_ASTRING);
 }
 
-nsresult
+void
 nsDiscriminatedUnion::SetFromDOMString(const nsAString& aValue)
 {
   DATA_SETTER_PROLOGUE;
-  if (!(u.mAStringValue = new nsString(aValue))) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
+  u.mAStringValue = new nsString(aValue);
   DATA_SETTER_EPILOGUE(VTYPE_DOMSTRING);
 }
 
-nsresult
+void
 nsDiscriminatedUnion::SetFromACString(const nsACString& aValue)
 {
   DATA_SETTER_PROLOGUE;
-  if (!(u.mCStringValue = new nsCString(aValue))) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
+  u.mCStringValue = new nsCString(aValue);
   DATA_SETTER_EPILOGUE(VTYPE_CSTRING);
 }
 
-nsresult
+void
 nsDiscriminatedUnion::SetFromAUTF8String(const nsAUTF8String& aValue)
 {
   DATA_SETTER_PROLOGUE;
-  if (!(u.mUTF8StringValue = new nsUTF8String(aValue))) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
+  u.mUTF8StringValue = new nsUTF8String(aValue);
   DATA_SETTER_EPILOGUE(VTYPE_UTF8STRING);
 }
 
 nsresult
 nsDiscriminatedUnion::SetFromString(const char* aValue)
 {
   DATA_SETTER_PROLOGUE;
   if (!aValue) {
@@ -1480,22 +1474,22 @@ nsresult
 nsDiscriminatedUnion::SetFromWString(const char16_t* aValue)
 {
   DATA_SETTER_PROLOGUE;
   if (!aValue) {
     return NS_ERROR_NULL_POINTER;
   }
   return SetFromWStringWithSize(NS_strlen(aValue), aValue);
 }
-nsresult
+void
 nsDiscriminatedUnion::SetFromISupports(nsISupports* aValue)
 {
   return SetFromInterface(NS_GET_IID(nsISupports), aValue);
 }
-nsresult
+void
 nsDiscriminatedUnion::SetFromInterface(const nsIID& aIID, nsISupports* aValue)
 {
   DATA_SETTER_PROLOGUE;
   NS_IF_ADDREF(aValue);
   u.iface.mInterfaceValue = aValue;
   u.iface.mInterfaceID = aIID;
   DATA_SETTER_EPILOGUE(VTYPE_INTERFACE_IS);
 }
@@ -1512,72 +1506,72 @@ nsDiscriminatedUnion::SetFromArray(uint1
                            &u.array.mArrayType,
                            &u.array.mArrayInterfaceID,
                            &u.array.mArrayCount,
                            &u.array.mArrayValue);
   if (NS_FAILED(rv)) {
     return rv;
   }
   DATA_SETTER_EPILOGUE(VTYPE_ARRAY);
+  return NS_OK;
 }
 nsresult
 nsDiscriminatedUnion::SetFromStringWithSize(uint32_t aSize,
                                             const char* aValue)
 {
   DATA_SETTER_PROLOGUE;
   if (!aValue) {
     return NS_ERROR_NULL_POINTER;
   }
   if (!(u.str.mStringValue =
         (char*)nsMemory::Clone(aValue, (aSize + 1) * sizeof(char)))) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
   u.str.mStringLength = aSize;
   DATA_SETTER_EPILOGUE(VTYPE_STRING_SIZE_IS);
+  return NS_OK;
 }
 nsresult
 nsDiscriminatedUnion::SetFromWStringWithSize(uint32_t aSize,
                                              const char16_t* aValue)
 {
   DATA_SETTER_PROLOGUE;
   if (!aValue) {
     return NS_ERROR_NULL_POINTER;
   }
   if (!(u.wstr.mWStringValue =
         (char16_t*)nsMemory::Clone(aValue, (aSize + 1) * sizeof(char16_t)))) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
   u.wstr.mWStringLength = aSize;
   DATA_SETTER_EPILOGUE(VTYPE_WSTRING_SIZE_IS);
+  return NS_OK;
 }
-nsresult
+void
 nsDiscriminatedUnion::AllocateWStringWithSize(uint32_t aSize)
 {
   DATA_SETTER_PROLOGUE;
-  if (!(u.wstr.mWStringValue =
-        (char16_t*)moz_xmalloc((aSize + 1) * sizeof(char16_t)))) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
+  u.wstr.mWStringValue = (char16_t*)moz_xmalloc((aSize + 1) * sizeof(char16_t));
   u.wstr.mWStringValue[aSize] = '\0';
   u.wstr.mWStringLength = aSize;
   DATA_SETTER_EPILOGUE(VTYPE_WSTRING_SIZE_IS);
 }
-nsresult
+void
 nsDiscriminatedUnion::SetToVoid()
 {
   DATA_SETTER_PROLOGUE;
   DATA_SETTER_EPILOGUE(VTYPE_VOID);
 }
-nsresult
+void
 nsDiscriminatedUnion::SetToEmpty()
 {
   DATA_SETTER_PROLOGUE;
   DATA_SETTER_EPILOGUE(VTYPE_EMPTY);
 }
-nsresult
+void
 nsDiscriminatedUnion::SetToEmptyArray()
 {
   DATA_SETTER_PROLOGUE;
   DATA_SETTER_EPILOGUE(VTYPE_EMPTY_ARRAY);
 }
 
 /***************************************************************************/
 
@@ -1916,171 +1910,189 @@ nsVariantBase::SetWritable(bool aWritabl
 // 'SetFrom' functions.
 
 NS_IMETHODIMP
 nsVariantBase::SetAsInt8(uint8_t aValue)
 {
   if (!mWritable) {
     return NS_ERROR_OBJECT_IS_IMMUTABLE;
   }
-  return mData.SetFromInt8(aValue);
+  mData.SetFromInt8(aValue);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsVariantBase::SetAsInt16(int16_t aValue)
 {
   if (!mWritable) {
     return NS_ERROR_OBJECT_IS_IMMUTABLE;
   }
-  return mData.SetFromInt16(aValue);
+  mData.SetFromInt16(aValue);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsVariantBase::SetAsInt32(int32_t aValue)
 {
   if (!mWritable) {
     return NS_ERROR_OBJECT_IS_IMMUTABLE;
   }
-  return mData.SetFromInt32(aValue);
+  mData.SetFromInt32(aValue);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsVariantBase::SetAsInt64(int64_t aValue)
 {
   if (!mWritable) {
     return NS_ERROR_OBJECT_IS_IMMUTABLE;
   }
-  return mData.SetFromInt64(aValue);
+  mData.SetFromInt64(aValue);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsVariantBase::SetAsUint8(uint8_t aValue)
 {
   if (!mWritable) {
     return NS_ERROR_OBJECT_IS_IMMUTABLE;
   }
-  return mData.SetFromUint8(aValue);
+  mData.SetFromUint8(aValue);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsVariantBase::SetAsUint16(uint16_t aValue)
 {
   if (!mWritable) {
     return NS_ERROR_OBJECT_IS_IMMUTABLE;
   }
-  return mData.SetFromUint16(aValue);
+  mData.SetFromUint16(aValue);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsVariantBase::SetAsUint32(uint32_t aValue)
 {
   if (!mWritable) {
     return NS_ERROR_OBJECT_IS_IMMUTABLE;
   }
-  return mData.SetFromUint32(aValue);
+  mData.SetFromUint32(aValue);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsVariantBase::SetAsUint64(uint64_t aValue)
 {
   if (!mWritable) {
     return NS_ERROR_OBJECT_IS_IMMUTABLE;
   }
-  return mData.SetFromUint64(aValue);
+  mData.SetFromUint64(aValue);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsVariantBase::SetAsFloat(float aValue)
 {
   if (!mWritable) {
     return NS_ERROR_OBJECT_IS_IMMUTABLE;
   }
-  return mData.SetFromFloat(aValue);
+  mData.SetFromFloat(aValue);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsVariantBase::SetAsDouble(double aValue)
 {
   if (!mWritable) {
     return NS_ERROR_OBJECT_IS_IMMUTABLE;
   }
-  return mData.SetFromDouble(aValue);
+  mData.SetFromDouble(aValue);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsVariantBase::SetAsBool(bool aValue)
 {
   if (!mWritable) {
     return NS_ERROR_OBJECT_IS_IMMUTABLE;
   }
-  return mData.SetFromBool(aValue);
+  mData.SetFromBool(aValue);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsVariantBase::SetAsChar(char aValue)
 {
   if (!mWritable) {
     return NS_ERROR_OBJECT_IS_IMMUTABLE;
   }
-  return mData.SetFromChar(aValue);
+  mData.SetFromChar(aValue);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsVariantBase::SetAsWChar(char16_t aValue)
 {
   if (!mWritable) {
     return NS_ERROR_OBJECT_IS_IMMUTABLE;
   }
-  return mData.SetFromWChar(aValue);
+  mData.SetFromWChar(aValue);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsVariantBase::SetAsID(const nsID& aValue)
 {
   if (!mWritable) {
     return NS_ERROR_OBJECT_IS_IMMUTABLE;
   }
-  return mData.SetFromID(aValue);
+  mData.SetFromID(aValue);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsVariantBase::SetAsAString(const nsAString& aValue)
 {
   if (!mWritable) {
     return NS_ERROR_OBJECT_IS_IMMUTABLE;
   }
-  return mData.SetFromAString(aValue);
+  mData.SetFromAString(aValue);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsVariantBase::SetAsDOMString(const nsAString& aValue)
 {
   if (!mWritable) {
     return NS_ERROR_OBJECT_IS_IMMUTABLE;
   }
 
-  return mData.SetFromDOMString(aValue);
+  mData.SetFromDOMString(aValue);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsVariantBase::SetAsACString(const nsACString& aValue)
 {
   if (!mWritable) {
     return NS_ERROR_OBJECT_IS_IMMUTABLE;
   }
-  return mData.SetFromACString(aValue);
+  mData.SetFromACString(aValue);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsVariantBase::SetAsAUTF8String(const nsAUTF8String& aValue)
 {
   if (!mWritable) {
     return NS_ERROR_OBJECT_IS_IMMUTABLE;
   }
-  return mData.SetFromAUTF8String(aValue);
+  mData.SetFromAUTF8String(aValue);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsVariantBase::SetAsString(const char* aValue)
 {
   if (!mWritable) {
     return NS_ERROR_OBJECT_IS_IMMUTABLE;
   }
@@ -2097,26 +2109,28 @@ nsVariantBase::SetAsWString(const char16
 }
 
 NS_IMETHODIMP
 nsVariantBase::SetAsISupports(nsISupports* aValue)
 {
   if (!mWritable) {
     return NS_ERROR_OBJECT_IS_IMMUTABLE;
   }
-  return mData.SetFromISupports(aValue);
+  mData.SetFromISupports(aValue);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsVariantBase::SetAsInterface(const nsIID& aIID, void* aInterface)
 {
   if (!mWritable) {
     return NS_ERROR_OBJECT_IS_IMMUTABLE;
   }
-  return mData.SetFromInterface(aIID, (nsISupports*)aInterface);
+  mData.SetFromInterface(aIID, (nsISupports*)aInterface);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsVariantBase::SetAsArray(uint16_t aType, const nsIID* aIID,
                       uint32_t aCount, void* aPtr)
 {
   if (!mWritable) {
     return NS_ERROR_OBJECT_IS_IMMUTABLE;
@@ -2143,35 +2157,38 @@ nsVariantBase::SetAsWStringWithSize(uint
 }
 
 NS_IMETHODIMP
 nsVariantBase::SetAsVoid()
 {
   if (!mWritable) {
     return NS_ERROR_OBJECT_IS_IMMUTABLE;
   }
-  return mData.SetToVoid();
+  mData.SetToVoid();
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsVariantBase::SetAsEmpty()
 {
   if (!mWritable) {
     return NS_ERROR_OBJECT_IS_IMMUTABLE;
   }
-  return mData.SetToEmpty();
+  mData.SetToEmpty();
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsVariantBase::SetAsEmptyArray()
 {
   if (!mWritable) {
     return NS_ERROR_OBJECT_IS_IMMUTABLE;
   }
-  return mData.SetToEmptyArray();
+  mData.SetToEmptyArray();
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsVariantBase::SetFromVariant(nsIVariant* aValue)
 {
   if (!mWritable) {
     return NS_ERROR_OBJECT_IS_IMMUTABLE;
   }
--- a/xpcom/ds/nsVariant.h
+++ b/xpcom/ds/nsVariant.h
@@ -38,89 +38,92 @@ public:
 
   nsDiscriminatedUnion& operator=(const nsDiscriminatedUnion&) = delete;
   nsDiscriminatedUnion& operator=(nsDiscriminatedUnion&&) = delete;
 
   void Cleanup();
 
   uint16_t GetType() const { return mType; }
 
-  nsresult ConvertToInt8(uint8_t* aResult) const;
-  nsresult ConvertToInt16(int16_t* aResult) const;
-  nsresult ConvertToInt32(int32_t* aResult) const;
-  nsresult ConvertToInt64(int64_t* aResult) const;
-  nsresult ConvertToUint8(uint8_t* aResult) const;
-  nsresult ConvertToUint16(uint16_t* aResult) const;
-  nsresult ConvertToUint32(uint32_t* aResult) const;
-  nsresult ConvertToUint64(uint64_t* aResult) const;
-  nsresult ConvertToFloat(float* aResult) const;
-  nsresult ConvertToDouble(double* aResult) const;
-  nsresult ConvertToBool(bool* aResult) const;
-  nsresult ConvertToChar(char* aResult) const;
-  nsresult ConvertToWChar(char16_t* aResult) const;
+  MOZ_MUST_USE nsresult ConvertToInt8(uint8_t* aResult) const;
+  MOZ_MUST_USE nsresult ConvertToInt16(int16_t* aResult) const;
+  MOZ_MUST_USE nsresult ConvertToInt32(int32_t* aResult) const;
+  MOZ_MUST_USE nsresult ConvertToInt64(int64_t* aResult) const;
+  MOZ_MUST_USE nsresult ConvertToUint8(uint8_t* aResult) const;
+  MOZ_MUST_USE nsresult ConvertToUint16(uint16_t* aResult) const;
+  MOZ_MUST_USE nsresult ConvertToUint32(uint32_t* aResult) const;
+  MOZ_MUST_USE nsresult ConvertToUint64(uint64_t* aResult) const;
+  MOZ_MUST_USE nsresult ConvertToFloat(float* aResult) const;
+  MOZ_MUST_USE nsresult ConvertToDouble(double* aResult) const;
+  MOZ_MUST_USE nsresult ConvertToBool(bool* aResult) const;
+  MOZ_MUST_USE nsresult ConvertToChar(char* aResult) const;
+  MOZ_MUST_USE nsresult ConvertToWChar(char16_t* aResult) const;
 
-  nsresult ConvertToID(nsID* aResult) const;
+  MOZ_MUST_USE nsresult ConvertToID(nsID* aResult) const;
 
-  nsresult ConvertToAString(nsAString& aResult) const;
-  nsresult ConvertToAUTF8String(nsAUTF8String& aResult) const;
-  nsresult ConvertToACString(nsACString& aResult) const;
-  nsresult ConvertToString(char** aResult) const;
-  nsresult ConvertToWString(char16_t** aResult) const;
-  nsresult ConvertToStringWithSize(uint32_t* aSize, char** aStr) const;
-  nsresult ConvertToWStringWithSize(uint32_t* aSize, char16_t** aStr) const;
+  MOZ_MUST_USE nsresult ConvertToAString(nsAString& aResult) const;
+  MOZ_MUST_USE nsresult ConvertToAUTF8String(nsAUTF8String& aResult) const;
+  MOZ_MUST_USE nsresult ConvertToACString(nsACString& aResult) const;
+  MOZ_MUST_USE nsresult ConvertToString(char** aResult) const;
+  MOZ_MUST_USE nsresult ConvertToWString(char16_t** aResult) const;
+  MOZ_MUST_USE nsresult ConvertToStringWithSize(uint32_t* aSize, char** aStr) const;
+  MOZ_MUST_USE nsresult ConvertToWStringWithSize(uint32_t* aSize, char16_t** aStr) const;
 
-  nsresult ConvertToISupports(nsISupports** aResult) const;
-  nsresult ConvertToInterface(nsIID** aIID, void** aInterface) const;
-  nsresult ConvertToArray(uint16_t* aType, nsIID* aIID,
-                          uint32_t* aCount, void** aPtr) const;
+  MOZ_MUST_USE nsresult ConvertToISupports(nsISupports** aResult) const;
+  MOZ_MUST_USE nsresult ConvertToInterface(nsIID** aIID, void** aInterface) const;
+  MOZ_MUST_USE nsresult ConvertToArray(uint16_t* aType, nsIID* aIID,
+                                       uint32_t* aCount, void** aPtr) const;
 
-  nsresult SetFromVariant(nsIVariant* aValue);
+  MOZ_MUST_USE nsresult SetFromVariant(nsIVariant* aValue);
 
-  nsresult SetFromInt8(uint8_t aValue);
-  nsresult SetFromInt16(int16_t aValue);
-  nsresult SetFromInt32(int32_t aValue);
-  nsresult SetFromInt64(int64_t aValue);
-  nsresult SetFromUint8(uint8_t aValue);
-  nsresult SetFromUint16(uint16_t aValue);
-  nsresult SetFromUint32(uint32_t aValue);
-  nsresult SetFromUint64(uint64_t aValue);
-  nsresult SetFromFloat(float aValue);
-  nsresult SetFromDouble(double aValue);
-  nsresult SetFromBool(bool aValue);
-  nsresult SetFromChar(char aValue);
-  nsresult SetFromWChar(char16_t aValue);
-  nsresult SetFromID(const nsID& aValue);
-  nsresult SetFromAString(const nsAString& aValue);
-  nsresult SetFromDOMString(const nsAString& aValue);
-  nsresult SetFromAUTF8String(const nsAUTF8String& aValue);
-  nsresult SetFromACString(const nsACString& aValue);
-  nsresult SetFromString(const char* aValue);
-  nsresult SetFromWString(const char16_t* aValue);
-  nsresult SetFromISupports(nsISupports* aValue);
-  nsresult SetFromInterface(const nsIID& aIID, nsISupports* aValue);
-  nsresult SetFromArray(uint16_t aType, const nsIID* aIID, uint32_t aCount,
-                        void* aValue);
-  nsresult SetFromStringWithSize(uint32_t aSize, const char* aValue);
-  nsresult SetFromWStringWithSize(uint32_t aSize, const char16_t* aValue);
+  void SetFromInt8(uint8_t aValue);
+  void SetFromInt16(int16_t aValue);
+  void SetFromInt32(int32_t aValue);
+  void SetFromInt64(int64_t aValue);
+  void SetFromUint8(uint8_t aValue);
+  void SetFromUint16(uint16_t aValue);
+  void SetFromUint32(uint32_t aValue);
+  void SetFromUint64(uint64_t aValue);
+  void SetFromFloat(float aValue);
+  void SetFromDouble(double aValue);
+  void SetFromBool(bool aValue);
+  void SetFromChar(char aValue);
+  void SetFromWChar(char16_t aValue);
+  void SetFromID(const nsID& aValue);
+  void SetFromAString(const nsAString& aValue);
+  void SetFromDOMString(const nsAString& aValue);
+  void SetFromAUTF8String(const nsAUTF8String& aValue);
+  void SetFromACString(const nsACString& aValue);
+  MOZ_MUST_USE nsresult SetFromString(const char* aValue);
+  MOZ_MUST_USE nsresult SetFromWString(const char16_t* aValue);
+  void SetFromISupports(nsISupports* aValue);
+  void SetFromInterface(const nsIID& aIID, nsISupports* aValue);
+  MOZ_MUST_USE nsresult SetFromArray(uint16_t aType, const nsIID* aIID,
+                                     uint32_t aCount, void* aValue);
+  MOZ_MUST_USE nsresult SetFromStringWithSize(uint32_t aSize,
+                                              const char* aValue);
+  MOZ_MUST_USE nsresult SetFromWStringWithSize(uint32_t aSize,
+                                               const char16_t* aValue);
 
   // Like SetFromWStringWithSize, but leaves the string uninitialized. It does
   // does write the null-terminator.
-  nsresult AllocateWStringWithSize(uint32_t aSize);
+  void AllocateWStringWithSize(uint32_t aSize);
 
-  nsresult SetToVoid();
-  nsresult SetToEmpty();
-  nsresult SetToEmptyArray();
+  void SetToVoid();
+  void SetToEmpty();
+  void SetToEmptyArray();
 
   void Traverse(nsCycleCollectionTraversalCallback& aCb) const;
 
 private:
-  nsresult ToManageableNumber(nsDiscriminatedUnion* aOutData) const;
+  MOZ_MUST_USE nsresult
+  ToManageableNumber(nsDiscriminatedUnion* aOutData) const;
   void FreeArray();
-  bool String2ID(nsID* aPid) const;
-  nsresult ToString(nsACString& aOutString) const;
+  MOZ_MUST_USE bool String2ID(nsID* aPid) const;
+  MOZ_MUST_USE nsresult ToString(nsACString& aOutString) const;
 
 public:
   union
   {
     int8_t         mInt8Value;
     int16_t        mInt16Value;
     int32_t        mInt32Value;
     int64_t        mInt64Value;