tor-browser

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

commit bd0770a10424c19480d1a453af4d3efd6b04e56d
parent e53c78f304ec994084f02f0fe537116b63a83029
Author: Jan Varga <jan.varga@gmail.com>
Date:   Fri, 14 Nov 2025 08:51:48 +0000

Bug 1998365 - Switch NonCustomCSSPropertyId to uint16_t; r=emilio,firefox-style-system-reviewers

This patch changes NonCustomCSSPropertyId to use uint16_t as its underlying
type, matching the Rust representation.

Because the enum is now unsigned, the UNKNOWN sentinel can no longer be -1.
Keeping UNKNOWN as 0 would shift all property ids and complicate existing
mappings, so UNKNOWN is moved to the end of the enum instead.

The patch also updates the IPC serialization logic. Previously it assumed that
_COUNT covered almost every property, but over time additional entries (such
as aliases) were added after _COUNT and the IPC handling was not updated. This
patch corrects the serialization so that all variants of the enum are covered,
in line with the original intent of bug 783835.

No behavior changes intended beyond fixing the serialization gap.

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

Diffstat:
Mdom/html/nsGenericHTMLElement.h | 2+-
Mipc/glue/IPCMessageUtilsSpecializations.h | 2+-
Mlayout/style/GenerateCSSPropertyID.py | 1+
Mlayout/style/NonCustomCSSPropertyId.h.in | 13++++++++++---
Mlayout/style/nsCSSPropertyIDSet.h | 6+++---
Mlayout/style/nsCSSProps.cpp | 3++-
Mlayout/style/nsCSSProps.h | 21+++++++++++++--------
Mservo/components/style/properties/mod.rs | 8++++----
8 files changed, 35 insertions(+), 21 deletions(-)

diff --git a/dom/html/nsGenericHTMLElement.h b/dom/html/nsGenericHTMLElement.h @@ -28,7 +28,7 @@ class nsILayoutHistoryState; class nsIURI; struct nsSize; -enum NonCustomCSSPropertyId : int32_t; +enum NonCustomCSSPropertyId : uint16_t; namespace mozilla { class EditorBase; diff --git a/ipc/glue/IPCMessageUtilsSpecializations.h b/ipc/glue/IPCMessageUtilsSpecializations.h @@ -375,7 +375,7 @@ struct ParamTraits<float> { template <> struct ParamTraits<NonCustomCSSPropertyId> : public ContiguousEnumSerializer< - NonCustomCSSPropertyId, eCSSProperty_UNKNOWN, eCSSProperty_COUNT> {}; + NonCustomCSSPropertyId, eCSSProperty_FIRST, eCSSProperty_INVALID> {}; template <> struct ParamTraits<nsID> { diff --git a/layout/style/GenerateCSSPropertyID.py b/layout/style/GenerateCSSPropertyID.py @@ -33,6 +33,7 @@ def generate(output, template, dataFile): template.substitute( { "property_ids": "\n".join(" {},".format(p) for p in property_ids), + "longhand_first": property_ids[0], "longhand_count": property_ids[longhand_count], "shorthand_count": property_ids[longhand_count + shorthand_count], } diff --git a/layout/style/NonCustomCSSPropertyId.h.in b/layout/style/NonCustomCSSPropertyId.h.in @@ -18,9 +18,7 @@ To change the list of properties, see ServoCSSPropList.h */ -enum NonCustomCSSPropertyId : int32_t { - eCSSProperty_UNKNOWN = -1, - +enum NonCustomCSSPropertyId : uint16_t { $property_ids // Some of the values below could probably overlap with each other @@ -28,11 +26,20 @@ $property_ids // Extra value to represent custom properties (--*). eCSSPropertyExtra_variable, + + eCSSProperty_UNKNOWN, + + // Only needed for IPC serialization helper, should never be used in code. + eCSSProperty_INVALID, }; // MOZ_DBG support is defined in nsCSSProps.h since it depends on // nsCSSProps::GetStringValue +static_assert(static_cast<uint64_t>($longhand_first) == 0); + +const NonCustomCSSPropertyId + eCSSProperty_FIRST = NonCustomCSSPropertyId(0); const NonCustomCSSPropertyId eCSSProperty_COUNT_no_shorthands = $longhand_count; const NonCustomCSSPropertyId diff --git a/layout/style/nsCSSPropertyIDSet.h b/layout/style/nsCSSPropertyIDSet.h @@ -41,9 +41,9 @@ class nsCSSPropertyIDSet { } void AssertInSetRange(NonCustomCSSPropertyId aProperty) const { - MOZ_DIAGNOSTIC_ASSERT( - 0 <= aProperty && aProperty < eCSSProperty_COUNT_no_shorthands, - "out of bounds"); + MOZ_DIAGNOSTIC_ASSERT(aProperty != eCSSProperty_UNKNOWN && + aProperty < eCSSProperty_COUNT_no_shorthands, + "out of bounds"); } // Conversion of aProperty to |size_t| after AssertInSetRange diff --git a/layout/style/nsCSSProps.cpp b/layout/style/nsCSSProps.cpp @@ -174,7 +174,8 @@ const nsCString& nsCSSProps::GetStringValue(nsCSSCounterDesc aCounterDescID) { } CSSPropFlags nsCSSProps::PropFlags(NonCustomCSSPropertyId aProperty) { - MOZ_ASSERT(0 <= aProperty && aProperty < eCSSProperty_COUNT_with_aliases, + MOZ_ASSERT(aProperty != eCSSProperty_UNKNOWN && + aProperty < eCSSProperty_COUNT_with_aliases, "out of range"); return kFlagsTable[aProperty]; } diff --git a/layout/style/nsCSSProps.h b/layout/style/nsCSSProps.h @@ -72,8 +72,9 @@ class nsCSSProps { if (aProperty == eCSSPropertyExtra_variable) { return false; } - MOZ_ASSERT(0 <= aProperty && aProperty < eCSSProperty_COUNT, - "out of range"); + MOZ_ASSERT( + aProperty != eCSSProperty_UNKNOWN && aProperty < eCSSProperty_COUNT, + "out of range"); return aProperty >= eCSSProperty_COUNT_no_shorthands; } @@ -82,7 +83,8 @@ class nsCSSProps { // The relevant invariants are asserted in Document.cpp static mozilla::UseCounter UseCounterFor(NonCustomCSSPropertyId aProperty) { - MOZ_ASSERT(0 <= aProperty && aProperty < eCSSProperty_COUNT_with_aliases, + MOZ_ASSERT(aProperty != eCSSProperty_UNKNOWN && + aProperty < eCSSProperty_COUNT_with_aliases, "out of range"); return mozilla::UseCounter(size_t(mozilla::eUseCounter_FirstCSSProperty) + size_t(aProperty)); @@ -168,8 +170,9 @@ class nsCSSProps { * property. nullptr is returned for internal properties. */ static const char* PropertyIDLName(NonCustomCSSPropertyId aProperty) { - MOZ_ASSERT(0 <= aProperty && aProperty < eCSSProperty_COUNT, - "out of range"); + MOZ_ASSERT( + aProperty != eCSSProperty_UNKNOWN && aProperty < eCSSProperty_COUNT, + "out of range"); return kIDLNameTable[aProperty]; } @@ -178,14 +181,16 @@ class nsCSSProps { * properties sorted by their IDL name. */ static int32_t PropertyIDLNameSortPosition(NonCustomCSSPropertyId aProperty) { - MOZ_ASSERT(0 <= aProperty && aProperty < eCSSProperty_COUNT, - "out of range"); + MOZ_ASSERT( + aProperty != eCSSProperty_UNKNOWN && aProperty < eCSSProperty_COUNT, + "out of range"); return kIDLNameSortPositionTable[aProperty]; } static bool IsEnabled(NonCustomCSSPropertyId aProperty, EnabledState aEnabled) { - MOZ_ASSERT(0 <= aProperty && aProperty < eCSSProperty_COUNT_with_aliases, + MOZ_ASSERT(aProperty != eCSSProperty_UNKNOWN && + aProperty < eCSSProperty_COUNT_with_aliases, "out of range"); // In the child process, assert that we're not trying to parse stylesheets // before we've gotten all our prefs. diff --git a/servo/components/style/properties/mod.rs b/servo/components/style/properties/mod.rs @@ -223,19 +223,19 @@ impl NonCustomPropertyId { #[inline] pub fn to_noncustomcsspropertyid(self) -> NonCustomCSSPropertyId { // unsafe: guaranteed by static_assert_noncustomcsspropertyid. - unsafe { mem::transmute(self.0 as i32) } + unsafe { mem::transmute(self.0) } } /// Convert an `NonCustomCSSPropertyId` into a `NonCustomPropertyId`. #[cfg(feature = "gecko")] #[inline] pub fn from_noncustomcsspropertyid(prop: NonCustomCSSPropertyId) -> Option<Self> { - let prop = prop as i32; - if prop < 0 || prop >= property_counts::NON_CUSTOM as i32 { + let prop = prop as u16; + if prop >= property_counts::NON_CUSTOM as u16 { return None; } // guaranteed by static_assert_noncustomcsspropertyid above. - Some(NonCustomPropertyId(prop as u16)) + Some(NonCustomPropertyId(prop)) } /// Resolves the alias of a given property if needed.