Bug 735778 - Call MOZ_ASSERT if RemoveObserver is called with an observer that is not present. r=jlebar

This commit is contained in:
Mounir Lamouri 2012-03-16 19:32:11 +01:00
parent 675be045de
commit 6ea2bd057f
2 changed files with 15 additions and 8 deletions

View File

@ -179,13 +179,16 @@ public:
}
void RemoveObserver(Observer<InfoType>* aObserver) {
// If mObservers is null, that means there are no observers, so removing one
// must be a no-op.
if (!mObservers) {
return;
}
// If mObservers is null, that means there are no observers.
// In addition, if RemoveObserver() returns false, that means we didn't
// find the observer.
// In both cases, that is a logical error we want to make sure the developer
// notices.
mObservers->RemoveObserver(aObserver);
MOZ_ASSERT(mObservers);
DebugOnly<bool> removed = mObservers->RemoveObserver(aObserver);
MOZ_ASSERT(removed);
if (mObservers->Length() == 0) {
DisableNotifications();

View File

@ -81,8 +81,12 @@ public:
mObservers.AppendElement(aObserver);
}
void RemoveObserver(Observer<T>* aObserver) {
mObservers.RemoveElement(aObserver);
/**
* Remove the observer from the observer list.
* @return Whether the observer has been found in the list.
*/
bool RemoveObserver(Observer<T>* aObserver) {
return mObservers.RemoveElement(aObserver);
}
PRUint32 Length() {