mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-17 22:32:51 +00:00
![Andrew McCreight](/assets/img/avatar_default.png)
Using forget() to extract mMessage from MessageElement ends up going from nsCOMPtr<T> to already_AddRefed<T> to nsCOMPtr<T>. For the second step, the compiler can't tell that the already_AddRefed<T> came from a canonical nsCOMPtr, so it calls Assert_NoQueryNeeded() in debug builds. This in turn causes a QI, which does an AddRef. That is bad because we're not on the main thread, and mMessage is main-thread-only, so we get an assertion. This patch works around that by using swap directly between two nsCOMPtr<>, which avoids the Assert_NoQueryNeeded(). I called the method "swapMessage" rather than "swap" to emphasize that we are not swapping the whole MessageElement, but just one part of it. I find the existing forget() name to be confusing.