зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1149987 - Part 3: Give ErrorResult a move constructor and a move assignment operator; r=bzbarsky
This commit is contained in:
Родитель
1171444160
Коммит
61000b2825
|
@ -13,6 +13,7 @@
|
|||
#include "mozilla/FloatingPoint.h"
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/unused.h"
|
||||
|
||||
#include "AccessCheck.h"
|
||||
#include "jsfriendapi.h"
|
||||
|
@ -327,6 +328,37 @@ ErrorResult::ReportNotEnoughArgsError(JSContext* cx,
|
|||
ThrowErrorMessage(cx, dom::MSG_MISSING_ARGUMENTS, errorMessage.get());
|
||||
}
|
||||
|
||||
ErrorResult&
|
||||
ErrorResult::operator=(ErrorResult&& aRHS)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
mMightHaveUnreportedJSException = aRHS.mMightHaveUnreportedJSException;
|
||||
aRHS.mMightHaveUnreportedJSException = false;
|
||||
#endif
|
||||
if (aRHS.IsErrorWithMessage()) {
|
||||
mMessage = aRHS.mMessage;
|
||||
aRHS.mMessage = nullptr;
|
||||
} else if (aRHS.IsJSException()) {
|
||||
JSContext* cx = nsContentUtils::GetDefaultJSContextForThread();
|
||||
MOZ_ASSERT(cx);
|
||||
mJSException.setUndefined();
|
||||
if (!js::AddRawValueRoot(cx, &mJSException, "ErrorResult::mJSException")) {
|
||||
MOZ_CRASH("Could not root mJSException, we're about to OOM");
|
||||
}
|
||||
mJSException = aRHS.mJSException;
|
||||
aRHS.mJSException.setUndefined();
|
||||
js::RemoveRawValueRoot(cx, &aRHS.mJSException);
|
||||
} else {
|
||||
// Null out the union on both sides for hygiene purposes.
|
||||
mMessage = aRHS.mMessage = nullptr;
|
||||
}
|
||||
// Note: It's important to do this last, since this affects the condition
|
||||
// checks above!
|
||||
mResult = aRHS.mResult;
|
||||
aRHS.mResult = NS_OK;
|
||||
return *this;
|
||||
}
|
||||
|
||||
namespace dom {
|
||||
|
||||
bool
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "nscore.h"
|
||||
#include "nsStringGlue.h"
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/Move.h"
|
||||
|
||||
namespace IPC {
|
||||
class Message;
|
||||
|
@ -61,6 +62,12 @@ public:
|
|||
}
|
||||
#endif
|
||||
|
||||
ErrorResult(ErrorResult&& aRHS)
|
||||
{
|
||||
*this = Move(aRHS);
|
||||
}
|
||||
ErrorResult& operator=(ErrorResult&& aRHS);
|
||||
|
||||
void Throw(nsresult rv) {
|
||||
MOZ_ASSERT(NS_FAILED(rv), "Please don't try throwing success");
|
||||
MOZ_ASSERT(rv != NS_ERROR_TYPE_ERR, "Use ThrowTypeError()");
|
||||
|
|
Загрузка…
Ссылка в новой задаче