зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1157754 part 1. Add a way to "catch" an ErrorResult, and a way to safely convert an ErrorResult to an nsresult. r=peterv
This commit is contained in:
Родитель
c1b1d10e7d
Коммит
e11db3193b
|
@ -378,6 +378,24 @@ ErrorResult::operator=(ErrorResult&& aRHS)
|
|||
return *this;
|
||||
}
|
||||
|
||||
void
|
||||
ErrorResult::SuppressException()
|
||||
{
|
||||
WouldReportJSException();
|
||||
if (IsErrorWithMessage()) {
|
||||
ClearMessage();
|
||||
} else if (IsJSException()) {
|
||||
JSContext* cx = nsContentUtils::GetDefaultJSContextForThread();
|
||||
// Just steal it into a stack value (unrooting it in the process)
|
||||
// that we then allow to die.
|
||||
JS::Rooted<JS::Value> temp(cx);
|
||||
StealJSException(cx, &temp);
|
||||
}
|
||||
// We don't use AssignErrorCode, because we want to override existing error
|
||||
// states, which AssignErrorCode is not allowed to do.
|
||||
mResult = NS_OK;
|
||||
}
|
||||
|
||||
namespace dom {
|
||||
|
||||
bool
|
||||
|
|
|
@ -77,6 +77,20 @@ public:
|
|||
AssignErrorCode(rv);
|
||||
}
|
||||
|
||||
// Use SuppressException when you want to suppress any exception that might be
|
||||
// on the ErrorResult. After this call, the ErrorResult will be back a "no
|
||||
// exception thrown" state.
|
||||
void SuppressException();
|
||||
|
||||
// Use StealNSResult() when you want to safely convert the ErrorResult to an
|
||||
// nsresult that you will then return to a caller. This will
|
||||
// SuppressException(), since there will no longer be a way to report it.
|
||||
nsresult StealNSResult() {
|
||||
nsresult rv = ErrorCode();
|
||||
SuppressException();
|
||||
return rv;
|
||||
}
|
||||
|
||||
void ThrowTypeError(const dom::ErrNum errorNumber, ...);
|
||||
void ThrowRangeError(const dom::ErrNum errorNumber, ...);
|
||||
void ReportErrorWithMessage(JSContext* cx);
|
||||
|
|
Загрузка…
Ссылка в новой задаче