tor-browser

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

commit a1480dd174581dddbf8ec222ba63daef5635338c
parent 93f72e0a9eb52e48c50b3d24bdf5b8944c746dfa
Author: serge-sans-paille <sguelton@mozilla.com>
Date:   Fri,  7 Nov 2025 06:25:08 +0000

Bug 1997862 - Make nsCOMPtr default constructor constinit-compatible r=emilio,geckoview-reviewers,places-reviewers,layout-reviewers,valentin,m_kato

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

Diffstat:
Mdom/quota/test/gtest/QuotaManagerDependencyFixture.cpp | 2+-
Mdom/security/featurepolicy/fuzztest/fp_fuzzer.cpp | 4++--
Mtoolkit/components/places/tests/gtest/test_IHistory.cpp | 2+-
Mtoolkit/xre/nsAppRunner.cpp | 2+-
Mtoolkit/xre/nsXREDirProvider.cpp | 4++--
Mwidget/android/nsAppShell.cpp | 2+-
Mxpcom/base/nsCOMPtr.h | 13++++++-------
7 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/dom/quota/test/gtest/QuotaManagerDependencyFixture.cpp b/dom/quota/test/gtest/QuotaManagerDependencyFixture.cpp @@ -594,7 +594,7 @@ void QuotaManagerDependencyFixture::EnsureQuotaManager() { [&resolver]() { return resolver->IsDone(); }); } -MOZ_RUNINIT nsCOMPtr<nsISerialEventTarget> +MOZ_CONSTINIT nsCOMPtr<nsISerialEventTarget> QuotaManagerDependencyFixture::sBackgroundTarget; } // namespace mozilla::dom::quota::test diff --git a/dom/security/featurepolicy/fuzztest/fp_fuzzer.cpp b/dom/security/featurepolicy/fuzztest/fp_fuzzer.cpp @@ -15,8 +15,8 @@ using namespace mozilla; using namespace mozilla::dom; -MOZ_RUNINIT static nsCOMPtr<nsIPrincipal> selfURIPrincipal; -MOZ_RUNINIT static nsCOMPtr<nsIURI> selfURI; +MOZ_CONSTINIT static nsCOMPtr<nsIPrincipal> selfURIPrincipal; +MOZ_CONSTINIT static nsCOMPtr<nsIURI> selfURI; static int LVVMFuzzerInitTest(int* argc, char*** argv) { nsresult ret; diff --git a/toolkit/components/places/tests/gtest/test_IHistory.cpp b/toolkit/components/places/tests/gtest/test_IHistory.cpp @@ -121,7 +121,7 @@ void test_wait_checkpoint() { // These variables are shared between part 1 and part 2 of the test. Part 2 // sets the nsCOMPtr's to nullptr, freeing the reference. namespace test_unvisited_does_not_notify { -MOZ_RUNINIT nsCOMPtr<nsIURI> testURI; +MOZ_CONSTINIT nsCOMPtr<nsIURI> testURI; MOZ_CONSTINIT RefPtr<mock_Link> testLink; } // namespace test_unvisited_does_not_notify void test_unvisited_does_not_notify_part1() { diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp @@ -3028,7 +3028,7 @@ static ReturnAbortOnError ShowProfileSelector( static bool gDoMigration = false; static bool gDoProfileReset = false; -MOZ_RUNINIT static nsCOMPtr<nsIToolkitProfile> gResetOldProfile; +MOZ_CONSTINIT static nsCOMPtr<nsIToolkitProfile> gResetOldProfile; static nsresult LockProfile(nsINativeAppSupport* aNative, nsIFile* aRootDir, nsIFile* aLocalDir, nsIToolkitProfile* aProfile, diff --git a/toolkit/xre/nsXREDirProvider.cpp b/toolkit/xre/nsXREDirProvider.cpp @@ -96,8 +96,8 @@ nsXREDirProvider* gDirServiceProvider = nullptr; nsIFile* gDataDirHomeLocal = nullptr; nsIFile* gDataDirHome = nullptr; -MOZ_RUNINIT nsCOMPtr<nsIFile> gDataDirProfileLocal = nullptr; -MOZ_RUNINIT nsCOMPtr<nsIFile> gDataDirProfile = nullptr; +MOZ_CONSTINIT nsCOMPtr<nsIFile> gDataDirProfileLocal{}; +MOZ_CONSTINIT nsCOMPtr<nsIFile> gDataDirProfile{}; // These are required to allow nsXREDirProvider to be usable in xpcshell tests. // where gAppData is null. diff --git a/widget/android/nsAppShell.cpp b/widget/android/nsAppShell.cpp @@ -112,7 +112,7 @@ class WakeLockListener final : public nsIDOMMozWakeLockListener { }; NS_IMPL_ISUPPORTS(WakeLockListener, nsIDOMMozWakeLockListener) -MOZ_RUNINIT nsCOMPtr<nsIPowerManagerService> sPowerManagerService = nullptr; +MOZ_CONSTINIT nsCOMPtr<nsIPowerManagerService> sPowerManagerService{}; StaticRefPtr<WakeLockListener> sWakeLockListener; class GeckoThreadSupport final diff --git a/xpcom/base/nsCOMPtr.h b/xpcom/base/nsCOMPtr.h @@ -290,9 +290,9 @@ class MOZ_STACK_CLASS nsQueryReferent final { // Helper for assert_validity method template <class T> -char (&TestForIID(decltype(&NS_GET_IID(T))))[2]; +constexpr std::true_type TestForIID(decltype(&NS_GET_IID(T))); template <class T> -char TestForIID(...); +constexpr std::false_type TestForIID(...); template <class T> class MOZ_IS_REFPTR nsCOMPtr final { @@ -326,8 +326,8 @@ class MOZ_IS_REFPTR nsCOMPtr final { private: T* MOZ_OWNING_REF mRawPtr; - void assert_validity() { - static_assert(1 < sizeof(TestForIID<T>(nullptr)), + constexpr void assert_validity() { + static_assert(decltype(TestForIID<T>(nullptr))::value, "nsCOMPtr only works " "for types with IIDs. Either use RefPtr; add an IID to " "your type with NS_INLINE_DECL_STATIC_IID/ ;" @@ -371,12 +371,11 @@ class MOZ_IS_REFPTR nsCOMPtr final { // Constructors - nsCOMPtr() : mRawPtr(nullptr) { - assert_validity(); + constexpr nsCOMPtr() : mRawPtr(nullptr) { NSCAP_LOG_ASSIGNMENT(this, nullptr); } - MOZ_IMPLICIT nsCOMPtr(decltype(nullptr)) : mRawPtr(nullptr) { + MOZ_IMPLICIT nsCOMPtr(std::nullptr_t) : mRawPtr(nullptr) { assert_validity(); NSCAP_LOG_ASSIGNMENT(this, nullptr); }