mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-31 15:10:06 +00:00
Add a way to "catch" an ErrorResult, and a way to safely convert an ErrorResult to an nsresult.
This commit is contained in:
@@ -331,6 +331,24 @@ ErrorResult::ReportNotEnoughArgsError(JSContext* cx,
|
||||
ThrowErrorMessage(cx, dom::MSG_MISSING_ARGUMENTS, errorMessage.get());
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -64,6 +64,20 @@ public:
|
||||
mResult = 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);
|
||||
|
||||
Reference in New Issue
Block a user