diff --git a/components/style/restyle_hints.rs b/components/style/restyle_hints.rs index 091a7326df6..cc2549ee684 100644 --- a/components/style/restyle_hints.rs +++ b/components/style/restyle_hints.rs @@ -32,8 +32,7 @@ bitflags! { /// /// Note that the bit values here must be kept in sync with the Gecko /// nsRestyleHint values. If you add more bits with matching values, - /// please add assertions to assert_restyle_hints_match in - /// tests/unit/stylo/sanity_checks.rs. + /// please add assertions to assert_restyle_hints_match below. pub flags RestyleHint: u32 { /// Rerun selector matching on the element. const RESTYLE_SELF = 0x01, @@ -55,6 +54,39 @@ bitflags! { } } +/// Asserts that all RestyleHint flags have a matching nsRestyleHint value. +#[cfg(feature = "gecko")] +#[inline] +pub fn assert_restyle_hints_match() { + use gecko_bindings::structs; + + macro_rules! check_restyle_hints { + ( $( $a:ident => $b:ident ),*, ) => { + if cfg!(debug_assertions) { + let mut hints = RestyleHint::all(); + $( + assert_eq!(structs::$a.0 as usize, $b.bits() as usize, stringify!($b)); + hints.remove($b); + )* + assert_eq!(hints, RestyleHint::empty(), "all RestyleHint bits should have an assertion"); + } + } + } + + check_restyle_hints! { + nsRestyleHint_eRestyle_Self => RESTYLE_SELF, + // XXX This for Servo actually means something like an hypothetical + // Restyle_AllDescendants (but without running selector matching on the + // element). ServoRestyleManager interprets it like that, but in practice we + // should align the behavior with Gecko adding a new restyle hint, maybe? + // + // See https://bugzilla.mozilla.org/show_bug.cgi?id=1291786 + nsRestyleHint_eRestyle_SomeDescendants => RESTYLE_DESCENDANTS, + nsRestyleHint_eRestyle_LaterSiblings => RESTYLE_LATER_SIBLINGS, + nsRestyleHint_eRestyle_StyleAttribute => RESTYLE_STYLE_ATTRIBUTE, + } +} + impl RestyleHint { /// The subset hints that affect the styling of a single element during the /// traversal. diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 7a3fb5832ae..e8333b87adf 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -68,7 +68,7 @@ use style::properties::{ComputedValues, Importance, PropertyDeclaration}; use style::properties::{PropertyDeclarationParseResult, PropertyDeclarationBlock, PropertyId}; use style::properties::animated_properties::{AnimationValue, Interpolate, TransitionProperty}; use style::properties::parse_one_declaration; -use style::restyle_hints::RestyleHint; +use style::restyle_hints::{self, RestyleHint}; use style::selector_parser::PseudoElementCascadeType; use style::sequential; use style::string_cache::Atom; @@ -98,6 +98,9 @@ pub extern "C" fn Servo_Initialize() -> () { // Pretend that we're a Servo Layout thread, to make some assertions happy. thread_state::initialize(thread_state::LAYOUT); + + // Perform some debug-only runtime assertions. + restyle_hints::assert_restyle_hints_match(); } #[no_mangle] diff --git a/tests/unit/stylo/sanity_checks.rs b/tests/unit/stylo/sanity_checks.rs index 1f957e32847..ae3a105320d 100644 --- a/tests/unit/stylo/sanity_checks.rs +++ b/tests/unit/stylo/sanity_checks.rs @@ -27,38 +27,6 @@ macro_rules! check_enum_value_non_static { } } -#[test] -fn assert_restyle_hints_match() { - use style::restyle_hints::*; // For flags - use style::gecko_bindings::structs; - - macro_rules! check_restyle_hints { - ( $( $a:ident => $b:ident ),*, ) => { - { - let mut hints = RestyleHint::all(); - $( - check_enum_value_non_static!(structs::$a, $b.bits()); - hints.remove($b); - )* - assert_eq!(hints, RestyleHint::empty(), "all RestyleHint bits should have an assertion"); - } - } - } - - check_restyle_hints! { - nsRestyleHint_eRestyle_Self => RESTYLE_SELF, - // XXX This for Servo actually means something like an hypothetical - // Restyle_AllDescendants (but without running selector matching on the - // element). ServoRestyleManager interprets it like that, but in practice we - // should align the behavior with Gecko adding a new restyle hint, maybe? - // - // See https://bugzilla.mozilla.org/show_bug.cgi?id=1291786 - nsRestyleHint_eRestyle_SomeDescendants => RESTYLE_DESCENDANTS, - nsRestyleHint_eRestyle_LaterSiblings => RESTYLE_LATER_SIBLINGS, - nsRestyleHint_eRestyle_StyleAttribute => RESTYLE_STYLE_ATTRIBUTE, - } -} - // Note that we can't call each_pseudo_element, parse_pseudo_element, or // similar, because we'd need the foreign atom symbols to link. #[test]