Bug 1225219 Implement ErrorResult::CloneTo(). r=bz

This commit is contained in:
Ben Kelly 2015-11-18 11:07:58 -08:00
parent beb1adfcb0
commit 051c84e08a
2 changed files with 37 additions and 0 deletions

View File

@ -466,6 +466,38 @@ ErrorResult::operator=(ErrorResult&& aRHS)
return *this;
}
void
ErrorResult::CloneTo(ErrorResult& aRv) const
{
aRv.ClearUnionData();
aRv.mResult = mResult;
#ifdef DEBUG
aRv.mMightHaveUnreportedJSException = mMightHaveUnreportedJSException;
#endif
if (IsErrorWithMessage()) {
#ifdef DEBUG
aRv.mUnionState = HasMessage;
#endif
aRv.mMessage = new Message();
aRv.mMessage->mArgs = mMessage->mArgs;
aRv.mMessage->mErrorNumber = mMessage->mErrorNumber;
} else if (IsDOMException()) {
#ifdef DEBUG
aRv.mUnionState = HasDOMExceptionInfo;
#endif
aRv.mDOMExceptionInfo = new DOMExceptionInfo(mDOMExceptionInfo->mRv,
mDOMExceptionInfo->mMessage);
} else if (IsJSException()) {
#ifdef DEBUG
aRv.mUnionState = HasJSException;
#endif
JSContext* cx = nsContentUtils::RootingCxForThread();
JS::Rooted<JS::Value> exception(cx, mJSException);
aRv.ThrowJSException(cx, exception);
}
}
void
ErrorResult::SuppressException()
{

View File

@ -115,6 +115,11 @@ public:
AssignErrorCode(rv);
}
// Duplicate our current state on the given ErrorResult object. Any existing
// errors or messages on the target will be suppressed before cloning. Our
// own error state remains unchanged.
void CloneTo(ErrorResult& aRv) const;
// 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.