Fire assertions when guard objects are used as temporaries. (Bug 531460) r=jst

This commit is contained in:
L. David Baron 2010-04-04 11:15:18 -07:00
parent e4e7561b67
commit 50a17ea3e3
2 changed files with 23 additions and 9 deletions

View file

@ -67,6 +67,7 @@
#include "nsTextFragment.h" #include "nsTextFragment.h"
#include "nsReadableUtils.h" #include "nsReadableUtils.h"
#include "nsIPrefBranch2.h" #include "nsIPrefBranch2.h"
#include "mozilla/AutoRestore.h"
#include "jsapi.h" #include "jsapi.h"
@ -1700,26 +1701,32 @@ private:
#endif #endif
}; };
class nsAutoGCRoot { class NS_STACK_CLASS nsAutoGCRoot {
public: public:
// aPtr should be the pointer to the jsval we want to protect // aPtr should be the pointer to the jsval we want to protect
nsAutoGCRoot(jsval* aPtr, nsresult* aResult) : nsAutoGCRoot(jsval* aPtr, nsresult* aResult
MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM) :
mPtr(aPtr) mPtr(aPtr)
{ {
MOZILLA_GUARD_OBJECT_NOTIFIER_INIT;
mResult = *aResult = AddJSGCRoot(aPtr, "nsAutoGCRoot"); mResult = *aResult = AddJSGCRoot(aPtr, "nsAutoGCRoot");
} }
// aPtr should be the pointer to the JSObject* we want to protect // aPtr should be the pointer to the JSObject* we want to protect
nsAutoGCRoot(JSObject** aPtr, nsresult* aResult) : nsAutoGCRoot(JSObject** aPtr, nsresult* aResult
MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM) :
mPtr(aPtr) mPtr(aPtr)
{ {
MOZILLA_GUARD_OBJECT_NOTIFIER_INIT;
mResult = *aResult = AddJSGCRoot(aPtr, "nsAutoGCRoot"); mResult = *aResult = AddJSGCRoot(aPtr, "nsAutoGCRoot");
} }
// aPtr should be the pointer to the thing we want to protect // aPtr should be the pointer to the thing we want to protect
nsAutoGCRoot(void* aPtr, nsresult* aResult) : nsAutoGCRoot(void* aPtr, nsresult* aResult
MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM) :
mPtr(aPtr) mPtr(aPtr)
{ {
MOZILLA_GUARD_OBJECT_NOTIFIER_INIT;
mResult = *aResult = AddJSGCRoot(aPtr, "nsAutoGCRoot"); mResult = *aResult = AddJSGCRoot(aPtr, "nsAutoGCRoot");
} }
@ -1740,28 +1747,34 @@ private:
void* mPtr; void* mPtr;
nsresult mResult; nsresult mResult;
MOZILLA_DECL_USE_GUARD_OBJECT_NOTIFIER
}; };
class nsAutoScriptBlocker { class NS_STACK_CLASS nsAutoScriptBlocker {
public: public:
nsAutoScriptBlocker() { nsAutoScriptBlocker(MOZILLA_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) {
MOZILLA_GUARD_OBJECT_NOTIFIER_INIT;
nsContentUtils::AddScriptBlocker(); nsContentUtils::AddScriptBlocker();
} }
~nsAutoScriptBlocker() { ~nsAutoScriptBlocker() {
nsContentUtils::RemoveScriptBlocker(); nsContentUtils::RemoveScriptBlocker();
} }
private:
MOZILLA_DECL_USE_GUARD_OBJECT_NOTIFIER
}; };
class mozAutoRemovableBlockerRemover class NS_STACK_CLASS mozAutoRemovableBlockerRemover
{ {
public: public:
mozAutoRemovableBlockerRemover(nsIDocument* aDocument); mozAutoRemovableBlockerRemover(nsIDocument* aDocument
MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM);
~mozAutoRemovableBlockerRemover(); ~mozAutoRemovableBlockerRemover();
private: private:
PRUint32 mNestingLevel; PRUint32 mNestingLevel;
nsCOMPtr<nsIDocument> mDocument; nsCOMPtr<nsIDocument> mDocument;
nsCOMPtr<nsIDocumentObserver> mObserver; nsCOMPtr<nsIDocumentObserver> mObserver;
MOZILLA_DECL_USE_GUARD_OBJECT_NOTIFIER
}; };
#define NS_AUTO_GCROOT_PASTE2(tok,line) tok##line #define NS_AUTO_GCROOT_PASTE2(tok,line) tok##line

View file

@ -5903,8 +5903,9 @@ nsContentUtils::CheckCCWrapperTraversal(nsISupports* aScriptObjectHolder,
} }
#endif #endif
mozAutoRemovableBlockerRemover::mozAutoRemovableBlockerRemover(nsIDocument* aDocument) mozAutoRemovableBlockerRemover::mozAutoRemovableBlockerRemover(nsIDocument* aDocument MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
{ {
MOZILLA_GUARD_OBJECT_NOTIFIER_INIT;
mNestingLevel = nsContentUtils::GetRemovableScriptBlockerLevel(); mNestingLevel = nsContentUtils::GetRemovableScriptBlockerLevel();
mDocument = aDocument; mDocument = aDocument;
nsISupports* sink = aDocument ? aDocument->GetCurrentContentSink() : nsnull; nsISupports* sink = aDocument ? aDocument->GetCurrentContentSink() : nsnull;