mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Do RestyleHint assertions at runtime so they use build-time bindgen.
This commit is contained in:
parent
d44bf6182f
commit
229eb93fa3
3 changed files with 38 additions and 35 deletions
|
@ -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.
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue