tor-browser

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

commit 7f00ba9fac58965794eea098d93c16d13a99a4ca
parent b75b0abc10eaa46764969a84a71342aa02dfefdc
Author: Jan Varga <jan.varga@gmail.com>
Date:   Wed, 26 Nov 2025 13:50:46 +0000

Bug 1990419 - Use switch on result.tag and prepare for more TypedValue variants; r=emilio,firefox-style-system-reviewers

Refactor code to replace the if-chain with a switch on result.tag for clearer
control flow. An inner switch on StyleTypedValue::Tag is also added in
preparation for upcoming patches that will handle additional TypedValue
variants.

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

Diffstat:
Mlayout/style/typedom/StylePropertyMapReadOnly.cpp | 53++++++++++++++++++++++++++++-------------------------
1 file changed, 28 insertions(+), 25 deletions(-)

diff --git a/layout/style/typedom/StylePropertyMapReadOnly.cpp b/layout/style/typedom/StylePropertyMapReadOnly.cpp @@ -141,36 +141,39 @@ void StylePropertyMapReadOnly::Get(const nsACString& aProperty, return; } - // XXX Consider switch on result.tag - if (result.IsTyped()) { - auto typedValue = result.AsTyped(); - - MOZ_ASSERT(typedValue.IsKeyword()); - auto value = typedValue.AsKeyword(); + RefPtr<CSSStyleValue> styleValue; + + switch (result.tag) { + case StylePropertyTypedValueResult::Tag::Typed: { + const auto& typedValue = result.AsTyped(); + + switch (typedValue.tag) { + case StyleTypedValue::Tag::Keyword: + styleValue = + MakeRefPtr<CSSKeywordValue>(mParent, typedValue.AsKeyword()); + break; + } + break; + } - auto keywordValue = MakeRefPtr<CSSKeywordValue>(mParent, value); + case StylePropertyTypedValueResult::Tag::Unsupported: { + auto propertyId = CSSPropertyId::FromIdOrCustomProperty(id, aProperty); + auto rawBlock = result.AsUnsupported(); + auto block = MakeRefPtr<DeclarationBlock>(rawBlock.Consume()); + styleValue = MakeRefPtr<CSSUnsupportedValue>(mParent, propertyId, + std::move(block)); + break; + } - aRetVal.SetAsCSSStyleValue() = std::move(keywordValue); - return; + case StylePropertyTypedValueResult::Tag::None: + break; } - if (result.IsUnsupported()) { - auto propertyId = CSSPropertyId::FromIdOrCustomProperty(id, aProperty); - - auto rawBlock = result.AsUnsupported(); - - auto block = MakeRefPtr<DeclarationBlock>(rawBlock.Consume()); - - auto unsupportedValue = - MakeRefPtr<CSSUnsupportedValue>(mParent, propertyId, std::move(block)); - - aRetVal.SetAsCSSStyleValue() = std::move(unsupportedValue); - return; + if (styleValue) { + aRetVal.SetAsCSSStyleValue() = std::move(styleValue); + } else { + aRetVal.SetUndefined(); } - - MOZ_ASSERT(result.IsNone()); - - aRetVal.SetUndefined(); } // XXX This is not yet fully implemented and optimized!