From 409625bfdfb993c172ab13f438cee5265b0cf582 Mon Sep 17 00:00:00 2001 From: Andrew McCreight Date: Fri, 5 Apr 2013 10:03:56 -0700 Subject: [PATCH] Bug 852134 - simplify rooting and unrooting of SMS. r=smaug --- dom/mobilemessage/src/SmsRequest.cpp | 37 ++++------------------------ dom/mobilemessage/src/SmsRequest.h | 11 --------- 2 files changed, 5 insertions(+), 43 deletions(-) diff --git a/dom/mobilemessage/src/SmsRequest.cpp b/dom/mobilemessage/src/SmsRequest.cpp index f2e2f3274699..6711c4abcf6f 100644 --- a/dom/mobilemessage/src/SmsRequest.cpp +++ b/dom/mobilemessage/src/SmsRequest.cpp @@ -42,9 +42,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(SmsRequest, nsDOMEventTargetHelper) - if (tmp->mResultRooted) { - tmp->UnrootResult(); - } + tmp->mResult = JSVAL_VOID; NS_IMPL_CYCLE_COLLECTION_UNLINK(mCursor) NS_IMPL_CYCLE_COLLECTION_UNLINK(mError) NS_IMPL_CYCLE_COLLECTION_UNLINK_END @@ -90,7 +88,6 @@ SmsRequest::Create(SmsRequestParent* aRequestParent) SmsRequest::SmsRequest(SmsManager* aManager) : mResult(JSVAL_VOID) - , mResultRooted(false) , mDone(false) , mParentAlive(false) , mParent(nullptr) @@ -100,7 +97,6 @@ SmsRequest::SmsRequest(SmsManager* aManager) SmsRequest::SmsRequest(MobileMessageManager* aManager) : mResult(JSVAL_VOID) - , mResultRooted(false) , mDone(false) , mParentAlive(false) , mParent(nullptr) @@ -110,7 +106,6 @@ SmsRequest::SmsRequest(MobileMessageManager* aManager) SmsRequest::SmsRequest(SmsRequestParent* aRequestParent) : mResult(JSVAL_VOID) - , mResultRooted(false) , mDone(false) , mParentAlive(true) , mParent(aRequestParent) @@ -120,9 +115,8 @@ SmsRequest::SmsRequest(SmsRequestParent* aRequestParent) SmsRequest::~SmsRequest() { - if (mResultRooted) { - UnrootResult(); - } + mResult = JSVAL_VOID; + NS_DROP_JS_OBJECTS(this, SmsRequest); } void @@ -132,31 +126,10 @@ SmsRequest::Reset() NS_ASSERTION(mResult != JSVAL_VOID, "mResult should be set if we try to reset!"); NS_ASSERTION(!mError, "There should be no error if we try to reset!"); - if (mResultRooted) { - UnrootResult(); - } - mResult = JSVAL_VOID; mDone = false; } -void -SmsRequest::RootResult() -{ - NS_ASSERTION(!mResultRooted, "Don't call RootResult() if already rooted!"); - NS_HOLD_JS_OBJECTS(this, SmsRequest); - mResultRooted = true; -} - -void -SmsRequest::UnrootResult() -{ - NS_ASSERTION(mResultRooted, "Don't call UnrotResult() if not rooted!"); - mResult = JSVAL_VOID; - NS_DROP_JS_OBJECTS(this, SmsRequest); - mResultRooted = false; -} - void SmsRequest::SetSuccess(nsIDOMMozSmsMessage* aMessage) { @@ -218,10 +191,10 @@ SmsRequest::SetSuccessInternal(nsISupports* aObject) JSAutoRequest ar(cx); JSAutoCompartment ac(cx, global); - RootResult(); + NS_HOLD_JS_OBJECTS(this, SmsRequest); if (NS_FAILED(nsContentUtils::WrapNative(cx, global, aObject, &mResult))) { - UnrootResult(); + mResult = JSVAL_VOID; SetError(nsIMobileMessageCallback::INTERNAL_ERROR); return false; } diff --git a/dom/mobilemessage/src/SmsRequest.h b/dom/mobilemessage/src/SmsRequest.h index d75f56d1ba00..f2e6f0e7e00a 100644 --- a/dom/mobilemessage/src/SmsRequest.h +++ b/dom/mobilemessage/src/SmsRequest.h @@ -91,16 +91,6 @@ private: nsresult SendMessageReply(const mobilemessage::MessageReply& aReply); - /** - * Root mResult (JS::Value) to prevent garbage collection. - */ - void RootResult(); - - /** - * Unroot mResult (JS::Value) to allow garbage collection. - */ - void UnrootResult(); - /** * Set the object in a success state with the result being aMessage. */ @@ -140,7 +130,6 @@ private: nsresult NotifyError(int32_t aError); JS::Value mResult; - bool mResultRooted; bool mDone; bool mParentAlive; mobilemessage::SmsRequestParent* mParent;