tor-browser

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

commit 30d7eab1713f0ef21a2b9021c01b1c7ff787f668
parent dab8a944f21021d563ddf418f5a6db9a647e836f
Author: serge-sans-paille <sguelton@mozilla.com>
Date:   Wed, 10 Dec 2025 14:30:40 +0000

Bug 2004702 - improve const-corectness of DoublyLinkedList r=emilio

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

Diffstat:
Mjs/src/debugger/Debugger.h | 6++++++
Mjs/src/vm/Runtime.h | 6++++++
Mmemory/build/mozjemalloc.cpp | 15+++++++++++++++
Mmfbt/DoublyLinkedList.h | 13++++++++-----
Mmfbt/tests/TestDoublyLinkedList.cpp | 8++++++++
5 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/js/src/debugger/Debugger.h b/js/src/debugger/Debugger.h @@ -669,6 +669,9 @@ class Debugger : private mozilla::LinkedListElement<Debugger> { static mozilla::DoublyLinkedListElement<T>& Get(T* aThis) { return aThis->debuggerLink; } + static const mozilla::DoublyLinkedListElement<T>& Get(const T* aThis) { + return aThis->debuggerLink; + } }; // List of all js::Breakpoints in this debugger. @@ -1474,6 +1477,9 @@ class BreakpointSite { static mozilla::DoublyLinkedListElement<T>& Get(T* aThis) { return aThis->siteLink; } + static const mozilla::DoublyLinkedListElement<T>& Get(const T* aThis) { + return aThis->siteLink; + } }; // List of all js::Breakpoints at this instruction. diff --git a/js/src/vm/Runtime.h b/js/src/vm/Runtime.h @@ -607,6 +607,9 @@ struct JSRuntime { template <typename T> struct GlobalObjectWatchersLinkAccess { + static const mozilla::DoublyLinkedListElement<T>& Get(const T* aThis) { + return aThis->onNewGlobalObjectWatchersLink; + } static mozilla::DoublyLinkedListElement<T>& Get(T* aThis) { return aThis->onNewGlobalObjectWatchersLink; } @@ -614,6 +617,9 @@ struct JSRuntime { template <typename T> struct GarbageCollectionWatchersLinkAccess { + static const mozilla::DoublyLinkedListElement<T>& Get(const T* aThis) { + return aThis->onGarbageCollectionWatchersLink; + } static mozilla::DoublyLinkedListElement<T>& Get(T* aThis) { return aThis->onGarbageCollectionWatchersLink; } diff --git a/memory/build/mozjemalloc.cpp b/memory/build/mozjemalloc.cpp @@ -305,6 +305,10 @@ struct DirtyChunkListTrait { static DoublyLinkedListElement<arena_chunk_t>& Get(arena_chunk_t* aThis) { return aThis->mChunksDirtyElim; } + static const DoublyLinkedListElement<arena_chunk_t>& Get( + const arena_chunk_t* aThis) { + return aThis->mChunksDirtyElim; + } }; #ifdef MALLOC_DOUBLE_PURGE @@ -312,6 +316,10 @@ struct MadvisedChunkListTrait { static DoublyLinkedListElement<arena_chunk_t>& Get(arena_chunk_t* aThis) { return aThis->mChunksMavisedElim; } + static const DoublyLinkedListElement<arena_chunk_t>& Get( + const arena_chunk_t* aThis) { + return aThis->mChunksMavisedElim; + } }; #endif } // namespace mozilla @@ -365,6 +373,10 @@ struct GetDoublyLinkedListElement<arena_run_t> { static DoublyLinkedListElement<arena_run_t>& Get(arena_run_t* aThis) { return aThis->mRunListElem; } + static const DoublyLinkedListElement<arena_run_t>& Get( + const arena_run_t* aThis) { + return aThis->mRunListElem; + } }; } // namespace mozilla @@ -884,6 +896,9 @@ struct GetDoublyLinkedListElement<arena_t> { static DoublyLinkedListElement<arena_t>& Get(arena_t* aThis) { return aThis->mPurgeListElem; } + static const DoublyLinkedListElement<arena_t>& Get(const arena_t* aThis) { + return aThis->mPurgeListElem; + } }; } // namespace mozilla diff --git a/mfbt/DoublyLinkedList.h b/mfbt/DoublyLinkedList.h @@ -97,6 +97,9 @@ struct GetDoublyLinkedListElement { static_assert(std::is_base_of<DoublyLinkedListElement<T>, T>::value, "You need your own specialization of GetDoublyLinkedListElement" " or use a separate Trait."); + static const DoublyLinkedListElement<T>& Get(const T* aThis) { + return *aThis; + } static DoublyLinkedListElement<T>& Get(T* aThis) { return *aThis; } }; @@ -117,7 +120,7 @@ class DoublyLinkedList final { */ bool isStateValid() const { return (mHead != nullptr) == (mTail != nullptr); } - bool ElementNotInList(T* aElm) { + bool ElementNotInList(const T* aElm) const { if (!ElementAccess::Get(aElm).mNext && !ElementAccess::Get(aElm).mPrev) { // Both mNext and mPrev being NULL can mean two things: // - the element is not in the list. @@ -347,13 +350,13 @@ class DoublyLinkedList final { * Returns an iterator referencing the first found element whose value matches * the given element according to operator==. */ - Iterator find(const T& aElm) { return std::find(begin(), end(), aElm); } + Iterator find(const T& aElm) const { return std::find(begin(), end(), aElm); } /** * Returns whether the given element is in the list. Note that this uses * T::operator==, not pointer comparison. */ - bool contains(const T& aElm) { return find(aElm) != Iterator(); } + bool contains(const T& aElm) const { return find(aElm) != Iterator(); } /** * Returns whether the given element might be in the list. Note that this @@ -361,7 +364,7 @@ class DoublyLinkedList final { * the case where the element might be in another list in order to make the * check fast. */ - bool ElementProbablyInList(T* aElm) { + bool ElementProbablyInList(const T* aElm) const { if (isEmpty()) { return false; } @@ -372,7 +375,7 @@ class DoublyLinkedList final { * Returns whether an element is linked correctly to its predecessor and/or * successor, if any. Used for internal sanity checks. */ - bool ElementIsLinkedWell(T* aElm) { + bool ElementIsLinkedWell(const T* aElm) const { MOZ_ASSERT(aElm); if (!ElementProbablyInList(aElm)) { return false; diff --git a/mfbt/tests/TestDoublyLinkedList.cpp b/mfbt/tests/TestDoublyLinkedList.cpp @@ -174,6 +174,10 @@ struct InTwoLists { static DoublyLinkedListElement<InTwoLists>& Get(InTwoLists* aThis) { return aThis->mListOne; } + static const DoublyLinkedListElement<InTwoLists>& Get( + const InTwoLists* aThis) { + return aThis->mListOne; + } }; }; @@ -184,6 +188,10 @@ struct GetDoublyLinkedListElement<InTwoLists> { static DoublyLinkedListElement<InTwoLists>& Get(InTwoLists* aThis) { return aThis->mListTwo; } + static const DoublyLinkedListElement<InTwoLists>& Get( + const InTwoLists* aThis) { + return aThis->mListTwo; + } }; } // namespace mozilla