Skip to content

Instantly share code, notes, and snippets.

@wanderview
Created July 15, 2016 14:21
Show Gist options
  • Save wanderview/04b0515136bbca7f2b07ef15c7af2493 to your computer and use it in GitHub Desktop.
Save wanderview/04b0515136bbca7f2b07ef15c7af2493 to your computer and use it in GitHub Desktop.
void
AssertAndSuppressCleanupFunc(ErrorResult* aRv)
{
aRv->AssertReportedOrSuppressed();
aRv->SuppressException();
}
template <typename CleanupFunc = AssertAndSuppressCleanupFunc>
class ErrorResult
{
~ErrorResult()
{
CleanupFunc(this);
}
ErrorResult<AssertAndSuppressCleanupFunc>& operator()
{
return *reinterpret_cast<ErrorResult<AssertAndSuppressCleanupFunc>*>(this);
}
};
function SuppressCleanupFunc(ErrorResult* aRv)
{
aRv->SuppressException();
}
typedef ErrorResult<SuppressCleanupFunc> IgnoredErrorResult;
function EmptyCleanupFunc(ErrorResult* aRv)
{
}
typedef ErrorResult<EmptyCleanupFunc> FastErrorResult;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment