Bug 933378 part 4. Change the ErrorResult destructor to suppress the exception, after asserting that it's already suppressed. r=bkelly

This commit is contained in:
Boris Zbarsky 2016-07-15 22:35:13 -04:00
parent 61261a6a39
commit a522fa79b7
2 changed files with 20 additions and 9 deletions

View File

@ -579,6 +579,8 @@ TErrorResult<CleanupPolicy>::NoteJSContextException(JSContext* aCx)
}
template class TErrorResult<JustAssertCleanupPolicy>;
template class TErrorResult<AssertAndSuppressCleanupPolicy>;
template class TErrorResult<JustSuppressCleanupPolicy>;
} // namespace binding_danger

View File

@ -460,13 +460,24 @@ struct JustAssertCleanupPolicy {
static const bool suppress = false;
};
struct AssertAndSuppressCleanupPolicy {
static const bool assertHandled = true;
static const bool suppress = true;
};
struct JustSuppressCleanupPolicy {
static const bool assertHandled = false;
static const bool suppress = true;
};
} // namespace binding_danger
// A class people should normally use on the stack when they plan to actually
// do something with the exception.
class ErrorResult : public binding_danger::TErrorResult<binding_danger::JustAssertCleanupPolicy>
class ErrorResult :
public binding_danger::TErrorResult<binding_danger::AssertAndSuppressCleanupPolicy>
{
typedef binding_danger::TErrorResult<binding_danger::JustAssertCleanupPolicy> BaseErrorResult;
typedef binding_danger::TErrorResult<binding_danger::AssertAndSuppressCleanupPolicy> BaseErrorResult;
public:
ErrorResult()
@ -503,17 +514,15 @@ template<typename CleanupPolicy>
binding_danger::TErrorResult<CleanupPolicy>::operator ErrorResult&()
{
return *static_cast<ErrorResult*>(
reinterpret_cast<TErrorResult<JustAssertCleanupPolicy>*>(this));
reinterpret_cast<TErrorResult<AssertAndSuppressCleanupPolicy>*>(this));
}
// A class for use when an ErrorResult should just automatically be ignored.
class IgnoredErrorResult : public ErrorResult
// This doesn't inherit from ErrorResult so we don't make two separate calls to
// SuppressException.
class IgnoredErrorResult :
public binding_danger::TErrorResult<binding_danger::JustSuppressCleanupPolicy>
{
public:
~IgnoredErrorResult()
{
SuppressException();
}
};
/******************************************************************************