diff --git a/dom/bindings/ErrorResult.h b/dom/bindings/ErrorResult.h index dfeb3bc1f49cc..a0335166917c7 100644 --- a/dom/bindings/ErrorResult.h +++ b/dom/bindings/ErrorResult.h @@ -165,11 +165,48 @@ class TErrorResult { operator ErrorResult&(); operator OOMReporter&(); - void Throw(nsresult rv) { + void MOZ_MUST_RETURN_FROM_CALLER Throw(nsresult rv) { MOZ_ASSERT(NS_FAILED(rv), "Please don't try throwing success"); AssignErrorCode(rv); } + // This method acts identically to the `Throw` method, however, it does not + // have the MOZ_MUST_RETURN_FROM_CALLER static analysis annotation. It is + // intended to be used in situations when additional work needs to be + // performed in the calling function after the Throw method is called. + // + // In general you should prefer using `Throw`, and returning after an error, + // for example: + // + // if (condition) { + // aRv.Throw(NS_ERROR_FAILURE); + // return; + // } + // + // or + // + // if (condition) { + // aRv.Throw(NS_ERROR_FAILURE); + // } + // return; + // + // However, if you need to do some other work after throwing, such as: + // + // if (condition) { + // aRv.ThrowWithCustomCleanup(NS_ERROR_FAILURE); + // } + // // Do some important clean-up work which couldn't happen earlier. + // // We want to do this clean-up work in both the success and failure cases. + // CleanUpImportantState(); + // return; + // + // Then you'll need to use ThrowWithCustomCleanup to get around the static + // analysis, which would complain that you are doing work after the call to + // `Throw()`. + void ThrowWithCustomCleanup(nsresult rv) { + Throw(rv); + } + // Duplicate our current state on the given TErrorResult object. Any // existing errors or messages on the target will be suppressed before // cloning. Our own error state remains unchanged. @@ -307,7 +344,7 @@ class TErrorResult { } // Support for uncatchable exceptions. - void ThrowUncatchableException() { + void MOZ_MUST_RETURN_FROM_CALLER ThrowUncatchableException() { Throw(NS_ERROR_UNCATCHABLE_EXCEPTION); } bool IsUncatchableException() const { diff --git a/js/public/Value.h b/js/public/Value.h index 0874a76f7c2e4..8bf1d4973cc99 100644 --- a/js/public/Value.h +++ b/js/public/Value.h @@ -966,7 +966,7 @@ ExposeValueToActiveJS(const Value& v) /************************************************************************/ -static inline Value +static inline MOZ_MAY_CALL_AFTER_MUST_RETURN Value NullValue() { Value v; diff --git a/mfbt/RefPtr.h b/mfbt/RefPtr.h index 2de5a74c3b462..749d45a626c14 100644 --- a/mfbt/RefPtr.h +++ b/mfbt/RefPtr.h @@ -251,6 +251,7 @@ class RefPtr } already_AddRefed + MOZ_MAY_CALL_AFTER_MUST_RETURN forget() // return the value of mRawPtr and null out mRawPtr. Useful for // already_AddRefed return values. diff --git a/xpcom/base/nsCOMPtr.h b/xpcom/base/nsCOMPtr.h index 7505550d8ae9c..82e9b5e499937 100644 --- a/xpcom/base/nsCOMPtr.h +++ b/xpcom/base/nsCOMPtr.h @@ -717,7 +717,7 @@ class nsCOMPtr final // Return the value of mRawPtr and null out mRawPtr. Useful for // already_AddRefed return values. - already_AddRefed forget() + already_AddRefed MOZ_MAY_CALL_AFTER_MUST_RETURN forget() { T* temp = nullptr; swap(temp);