Bug 1110485 P0 Add an ErrorResult constructor that takes nsresult. r=bz

This commit is contained in:
Ben Kelly 2015-04-16 12:00:15 -07:00
parent 1217123bb4
commit 20c070b338

View File

@ -66,16 +66,15 @@ public:
} }
ErrorResult& operator=(ErrorResult&& aRHS); ErrorResult& operator=(ErrorResult&& aRHS);
explicit ErrorResult(nsresult aRv)
: ErrorResult()
{
AssignErrorCode(aRv);
}
void Throw(nsresult rv) { void Throw(nsresult rv) {
MOZ_ASSERT(NS_FAILED(rv), "Please don't try throwing success"); MOZ_ASSERT(NS_FAILED(rv), "Please don't try throwing success");
MOZ_ASSERT(rv != NS_ERROR_TYPE_ERR, "Use ThrowTypeError()"); AssignErrorCode(rv);
MOZ_ASSERT(rv != NS_ERROR_RANGE_ERR, "Use ThrowRangeError()");
MOZ_ASSERT(!IsErrorWithMessage(), "Don't overwrite errors with message");
MOZ_ASSERT(rv != NS_ERROR_DOM_JS_EXCEPTION, "Use ThrowJSException()");
MOZ_ASSERT(!IsJSException(), "Don't overwrite JS exceptions");
MOZ_ASSERT(rv != NS_ERROR_XPC_NOT_ENOUGH_ARGS, "Use ThrowNotEnoughArgsError()");
MOZ_ASSERT(!IsNotEnoughArgsError(), "Don't overwrite not enough args error");
mResult = rv;
} }
void ThrowTypeError(const dom::ErrNum errorNumber, ...); void ThrowTypeError(const dom::ErrNum errorNumber, ...);
@ -141,14 +140,7 @@ public:
// Throw() here because people can easily pass success codes to // Throw() here because people can easily pass success codes to
// this. // this.
void operator=(nsresult rv) { void operator=(nsresult rv) {
MOZ_ASSERT(rv != NS_ERROR_TYPE_ERR, "Use ThrowTypeError()"); AssignErrorCode(rv);
MOZ_ASSERT(rv != NS_ERROR_RANGE_ERR, "Use ThrowRangeError()");
MOZ_ASSERT(!IsErrorWithMessage(), "Don't overwrite errors with message");
MOZ_ASSERT(rv != NS_ERROR_DOM_JS_EXCEPTION, "Use ThrowJSException()");
MOZ_ASSERT(!IsJSException(), "Don't overwrite JS exceptions");
MOZ_ASSERT(rv != NS_ERROR_XPC_NOT_ENOUGH_ARGS, "Use ThrowNotEnoughArgsError()");
MOZ_ASSERT(!IsNotEnoughArgsError(), "Don't overwrite not enough args error");
mResult = rv;
} }
bool Failed() const { bool Failed() const {
@ -160,6 +152,24 @@ public:
} }
private: private:
friend struct IPC::ParamTraits<ErrorResult>;
void SerializeMessage(IPC::Message* aMsg) const;
bool DeserializeMessage(const IPC::Message* aMsg, void** aIter);
void ThrowErrorWithMessage(va_list ap, const dom::ErrNum errorNumber,
nsresult errorType);
void AssignErrorCode(nsresult aRv) {
MOZ_ASSERT(aRv != NS_ERROR_TYPE_ERR, "Use ThrowTypeError()");
MOZ_ASSERT(aRv != NS_ERROR_RANGE_ERR, "Use ThrowRangeError()");
MOZ_ASSERT(!IsErrorWithMessage(), "Don't overwrite errors with message");
MOZ_ASSERT(aRv != NS_ERROR_DOM_JS_EXCEPTION, "Use ThrowJSException()");
MOZ_ASSERT(!IsJSException(), "Don't overwrite JS exceptions");
MOZ_ASSERT(aRv != NS_ERROR_XPC_NOT_ENOUGH_ARGS, "Use ThrowNotEnoughArgsError()");
MOZ_ASSERT(!IsNotEnoughArgsError(), "Don't overwrite not enough args error");
mResult = aRv;
}
nsresult mResult; nsresult mResult;
struct Message; struct Message;
// mMessage is set by ThrowErrorWithMessage and cleared (and deallocated) by // mMessage is set by ThrowErrorWithMessage and cleared (and deallocated) by
@ -171,10 +181,6 @@ private:
JS::Value mJSException; // valid when IsJSException() JS::Value mJSException; // valid when IsJSException()
}; };
friend struct IPC::ParamTraits<ErrorResult>;
void SerializeMessage(IPC::Message* aMsg) const;
bool DeserializeMessage(const IPC::Message* aMsg, void** aIter);
#ifdef DEBUG #ifdef DEBUG
// Used to keep track of codepaths that might throw JS exceptions, // Used to keep track of codepaths that might throw JS exceptions,
// for assertion purposes. // for assertion purposes.
@ -189,8 +195,6 @@ private:
// reference, not by value. // reference, not by value.
ErrorResult(const ErrorResult&) = delete; ErrorResult(const ErrorResult&) = delete;
void operator=(const ErrorResult&) = delete; void operator=(const ErrorResult&) = delete;
void ThrowErrorWithMessage(va_list ap, const dom::ErrNum errorNumber,
nsresult errorType);
}; };
/****************************************************************************** /******************************************************************************