tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit fcd571291907b53e85d5e4ba1234be2ecf5b8e1e
parent 87ed6cbae92236b4e4bd09ffbbec24fb870982d8
Author: Jens Stutte <jstutte@mozilla.com>
Date:   Tue,  9 Dec 2025 07:32:13 +0000

Bug 1991834 - Add a diagnostic error to nsMaybeWeakPtrArray::AppendWeakElement to avoid double adding. r=xpcom-reviewers,mccr8,Gijs

Differential Revision: https://phabricator.services.mozilla.com/D267527

Diffstat:
Mxpcom/base/nsMaybeWeakPtr.h | 10++++++++++
1 file changed, 10 insertions(+), 0 deletions(-)

diff --git a/xpcom/base/nsMaybeWeakPtr.h b/xpcom/base/nsMaybeWeakPtr.h @@ -11,6 +11,7 @@ #include "nsIWeakReferenceUtils.h" #include "nsTArray.h" #include "nsCycleCollectionNoteChild.h" +#include "xpcpublic.h" // nsMaybeWeakPtr is a helper object to hold a strong-or-weak reference // to the template class. It's pretty minimal, but sufficient. @@ -81,6 +82,15 @@ class nsMaybeWeakPtrArray : public CopyableTArray<nsMaybeWeakPtr<T>> { nsMaybeWeakPtr<T> ref; MOZ_TRY(SetMaybeWeakPtr(ref, aElement, aOwnsWeak)); +#if (defined(MOZ_DIAGNOSTIC_ASSERT_ENABLED) && !defined(MOZ_THUNDERBIRD)) + // Checking for duplicates is expensive, so we enforce callers to avoid + // this with a diagnostic assertion. See bug 2000788 for Thunderbird. + if (MaybeWeakArray::Contains(aElement)) { + xpc_DumpJSStack(true, true, false); + MOZ_DIAGNOSTIC_ASSERT(false, "Element already in array."); + } +#endif + MaybeWeakArray::AppendElement(ref); return NS_OK; }