commit 467aeff5c9a6fe0e3f9bcab7ac42fac1c8f71eb6
parent e7316136b5c279c1a13ea28cdd206b68a193e2f1
Author: Jan Varga <jan.varga@gmail.com>
Date: Wed, 12 Nov 2025 19:00:07 +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:
5 files changed, 17 insertions(+), 9 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/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.