tor-browser

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

commit 2ac3eb983df638a13bd5dbd27fe160aab7baa203
parent a74ba85d3bf8b572de02f154e3dfe6e89a969a65
Author: Andrew McCreight <continuation@gmail.com>
Date:   Tue,  7 Oct 2025 22:22:09 +0000

Bug 1992422 - part 5: Use nsTArray for HTMLFrameSetElement::mRowSpecs and ::mColSpecs. r=layout-reviewers,emilio

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

Diffstat:
Mdom/html/HTMLFrameSetElement.cpp | 54++++++++++++++++++++++++------------------------------
Mdom/html/HTMLFrameSetElement.h | 20+++++---------------
2 files changed, 29 insertions(+), 45 deletions(-)

diff --git a/dom/html/HTMLFrameSetElement.cpp b/dom/html/HTMLFrameSetElement.cpp @@ -7,7 +7,6 @@ #include "HTMLFrameSetElement.h" #include "mozilla/Try.h" -#include "mozilla/UniquePtrExtensions.h" #include "mozilla/dom/Document.h" #include "mozilla/dom/EventHandlerBinding.h" #include "mozilla/dom/HTMLFrameSetElementBinding.h" @@ -45,17 +44,17 @@ void HTMLFrameSetElement::BeforeSetAttr(int32_t aNamespaceID, nsAtom* aName, if (aNamespaceID == kNameSpaceID_None) { if (aName == nsGkAtoms::rows) { if (aValue) { - int32_t oldRows = mNumRows; - ParseRowCol(*aValue, mNumRows, &mRowSpecs); - if (mNumRows != oldRows) { + size_t oldNumRows = mRowSpecs.Length(); + ParseRowCol(*aValue, mRowSpecs); + if (mRowSpecs.Length() != oldNumRows) { mCurrentRowColHint = nsChangeHint_ReconstructFrame; } } } else if (aName == nsGkAtoms::cols) { if (aValue) { - int32_t oldCols = mNumCols; - ParseRowCol(*aValue, mNumCols, &mColSpecs); - if (mNumCols != oldCols) { + size_t oldNumCols = mColSpecs.Length(); + ParseRowCol(*aValue, mColSpecs); + if (mColSpecs.Length() != oldNumCols) { mCurrentRowColHint = nsChangeHint_ReconstructFrame; } } @@ -67,41 +66,41 @@ void HTMLFrameSetElement::BeforeSetAttr(int32_t aNamespaceID, nsAtom* aName, } Span<const nsFramesetSpec> HTMLFrameSetElement::GetRowSpec() { - if (!mRowSpecs) { + if (mRowSpecs.IsEmpty()) { if (const nsAttrValue* value = GetParsedAttr(nsGkAtoms::rows)) { - if (NS_FAILED(ParseRowCol(*value, mNumRows, &mRowSpecs))) { + if (NS_FAILED(ParseRowCol(*value, mRowSpecs))) { return {}; } } - if (!mRowSpecs) { // we may not have had an attr or had an empty attr - mRowSpecs = MakeUnique<nsFramesetSpec[]>(1); - mNumRows = 1; + if (mRowSpecs.IsEmpty()) { + // We may not have had an attr or had an empty attr. + mRowSpecs.SetLength(1); mRowSpecs[0].mUnit = eFramesetUnit_Relative; mRowSpecs[0].mValue = 1; } } - return Span(mRowSpecs.get(), mNumRows); + return Span(mRowSpecs); } Span<const nsFramesetSpec> HTMLFrameSetElement::GetColSpec() { - if (!mColSpecs) { + if (mColSpecs.IsEmpty()) { if (const nsAttrValue* value = GetParsedAttr(nsGkAtoms::cols)) { - if (NS_FAILED(ParseRowCol(*value, mNumCols, &mColSpecs))) { + if (NS_FAILED(ParseRowCol(*value, mColSpecs))) { return {}; } } - if (!mColSpecs) { // we may not have had an attr or had an empty attr - mColSpecs = MakeUnique<nsFramesetSpec[]>(1); - mNumCols = 1; + if (mColSpecs.IsEmpty()) { + // We may not have had an attr or had an empty attr. + mColSpecs.SetLength(1); mColSpecs[0].mUnit = eFramesetUnit_Relative; mColSpecs[0].mValue = 1; } } - return Span(mColSpecs.get(), mNumCols); + return Span(mColSpecs); } bool HTMLFrameSetElement::ParseAttribute(int32_t aNamespaceID, @@ -139,11 +138,9 @@ nsChangeHint HTMLFrameSetElement::GetAttributeChangeHint( * Translate a "rows" or "cols" spec into an array of nsFramesetSpecs */ nsresult HTMLFrameSetElement::ParseRowCol(const nsAttrValue& aValue, - int32_t& aNumSpecs, - UniquePtr<nsFramesetSpec[]>* aSpecs) { + nsTArray<nsFramesetSpec>& aSpecs) { if (aValue.IsEmptyString()) { - aNumSpecs = 0; - *aSpecs = nullptr; + aSpecs.Clear(); return NS_OK; } @@ -169,10 +166,9 @@ nsresult HTMLFrameSetElement::ParseRowCol(const nsAttrValue& aValue, commaX = spec.FindChar(sComma, commaX + 1); } - auto specs = MakeUniqueFallible<nsFramesetSpec[]>(count); - if (!specs) { - *aSpecs = nullptr; - aNumSpecs = 0; + nsTArray<nsFramesetSpec> specs; + if (!specs.SetLength(count, fallible)) { + aSpecs.Clear(); return NS_ERROR_OUT_OF_MEMORY; } @@ -247,9 +243,7 @@ nsresult HTMLFrameSetElement::ParseRowCol(const nsAttrValue& aValue, } } - aNumSpecs = static_cast<int32_t>(count); - // Transfer ownership to caller here - *aSpecs = std::move(specs); + aSpecs = std::move(specs); return NS_OK; } diff --git a/dom/html/HTMLFrameSetElement.h b/dom/html/HTMLFrameSetElement.h @@ -9,8 +9,8 @@ #include "mozilla/Attributes.h" #include "mozilla/Span.h" -#include "mozilla/UniquePtr.h" #include "nsGenericHTMLElement.h" +#include "nsTArray.h" /** * The nsFramesetUnit enum is used to denote the type of each entry @@ -48,8 +48,6 @@ class HTMLFrameSetElement final : public nsGenericHTMLElement { explicit HTMLFrameSetElement( already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo) : nsGenericHTMLElement(std::move(aNodeInfo)), - mNumRows(0), - mNumCols(0), mCurrentRowColHint(NS_STYLE_HINT_REFLOW) { SetHasWeirdParserInsertionMode(); } @@ -119,18 +117,10 @@ class HTMLFrameSetElement final : public nsGenericHTMLElement { const nsAttrValue* aValue, bool aNotify) override; private: - nsresult ParseRowCol(const nsAttrValue& aValue, int32_t& aNumSpecs, - UniquePtr<nsFramesetSpec[]>* aSpecs); + nsresult ParseRowCol(const nsAttrValue& aValue, + nsTArray<nsFramesetSpec>& aSpecs); /** - * The number of size specs in our "rows" attr - */ - int32_t mNumRows; - /** - * The number of size specs in our "cols" attr - */ - int32_t mNumCols; - /** * The style hint to return for the rows/cols attrs in * GetAttributeChangeHint */ @@ -138,11 +128,11 @@ class HTMLFrameSetElement final : public nsGenericHTMLElement { /** * The parsed representation of the "rows" attribute */ - UniquePtr<nsFramesetSpec[]> mRowSpecs; // parsed, non-computed dimensions + nsTArray<nsFramesetSpec> mRowSpecs; // parsed, non-computed dimensions /** * The parsed representation of the "cols" attribute */ - UniquePtr<nsFramesetSpec[]> mColSpecs; // parsed, non-computed dimensions + nsTArray<nsFramesetSpec> mColSpecs; // parsed, non-computed dimensions }; } // namespace mozilla::dom