commit f6e3ccb5853c46f917578697a488d48c3bc09ac8
parent cee3c57f447b65196d9eabfac7dd39b208e315cc
Author: Jan Varga <jan.varga@gmail.com>
Date: Thu, 27 Nov 2025 07:07:07 +0000
Bug 1990419 - Use switch for CSSStyleValue type checks; r=emilio,firefox-style-system-reviewers
Replace chained if-statements with a switch on CSSStyleValue::ValueType for
cleaner and more consistent control flow.
Differential Revision: https://phabricator.services.mozilla.com/D270136
Diffstat:
2 files changed, 21 insertions(+), 8 deletions(-)
diff --git a/layout/style/typedom/CSSStyleValue.h b/layout/style/typedom/CSSStyleValue.h
@@ -60,6 +60,8 @@ class CSSStyleValue : public nsISupports, public nsWrapperCache {
// end of CSSStyleValue Web IDL declarations
+ ValueType GetValueType() const { return mValueType; }
+
bool IsCSSUnsupportedValue() const;
// Defined in CSSUnsupportedValue.cpp
diff --git a/layout/style/typedom/StylePropertyMap.cpp b/layout/style/typedom/StylePropertyMap.cpp
@@ -75,16 +75,27 @@ void StylePropertyMap::Set(
nsAutoCString cssText;
- if (styleValue.IsCSSUnsupportedValue()) {
- CSSUnsupportedValue& unsupportedValue =
- styleValue.GetAsCSSUnsupportedValue();
+ switch (styleValue.GetValueType()) {
+ case CSSStyleValue::ValueType::Keyword: {
+ CSSKeywordValue& keywordValue = styleValue.GetAsCSSKeywordValue();
- unsupportedValue.ToCssTextWithProperty(propertyId, cssText);
- } else if (styleValue.IsCSSKeywordValue()) {
- CSSKeywordValue& keywordValue = styleValue.GetAsCSSKeywordValue();
+ keywordValue.ToCssTextWithProperty(propertyId, cssText);
+ break;
+ }
- keywordValue.ToCssTextWithProperty(propertyId, cssText);
- } else {
+ case CSSStyleValue::ValueType::Unsupported: {
+ CSSUnsupportedValue& unsupportedValue =
+ styleValue.GetAsCSSUnsupportedValue();
+
+ unsupportedValue.ToCssTextWithProperty(propertyId, cssText);
+ break;
+ }
+
+ case CSSStyleValue::ValueType::Uninitialized:
+ break;
+ }
+
+ if (cssText.IsEmpty()) {
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
return;
}