tor-browser

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

commit f2439f05ebfa066c53f087425e3993f109e88f0d
parent 7ece905033de5cfa2b696c3af6983f7d110eee37
Author: Jens Stutte <jstutte@mozilla.com>
Date:   Tue, 25 Nov 2025 20:44:08 +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; }