mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
style: Move property allowance tests to PropertyId::parse_into.
It's not only more consistent (since we have a proper ParserContext there), but also fixes a bunch of bugs where Gecko accidentally exposes and allows setting internal state because of conversions from nsCSSPropertyID to PropertyId. This adds the extra complexity of caring about aliases for longer, but that's probably not a big deal in practice, since we also have PropertyDeclarationId. MozReview-Commit-ID: C2Js8PfloxQ
This commit is contained in:
parent
5905f8d3ea
commit
8de554f334
9 changed files with 137 additions and 135 deletions
|
@ -560,7 +560,8 @@ impl PropertyDeclarationBlock {
|
|||
///
|
||||
/// Returns whether any declaration was actually removed.
|
||||
pub fn remove_property(&mut self, property: &PropertyId) -> bool {
|
||||
if let PropertyId::Longhand(id) = *property {
|
||||
let longhand_id = property.longhand_id();
|
||||
if let Some(id) = longhand_id {
|
||||
if !self.longhands.contains(id) {
|
||||
return false
|
||||
}
|
||||
|
@ -584,7 +585,7 @@ impl PropertyDeclarationBlock {
|
|||
!remove
|
||||
});
|
||||
|
||||
if let PropertyId::Longhand(_) = *property {
|
||||
if longhand_id.is_some() {
|
||||
debug_assert!(removed_at_least_one);
|
||||
}
|
||||
removed_at_least_one
|
||||
|
@ -681,7 +682,7 @@ impl PropertyDeclarationBlock {
|
|||
/// property.
|
||||
#[cfg(feature = "gecko")]
|
||||
pub fn has_css_wide_keyword(&self, property: &PropertyId) -> bool {
|
||||
if let PropertyId::Longhand(id) = *property {
|
||||
if let Some(id) = property.longhand_id() {
|
||||
if !self.longhands.contains(id) {
|
||||
return false
|
||||
}
|
||||
|
@ -1092,12 +1093,14 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for PropertyDeclarationParser<'a, 'b> {
|
|||
type Declaration = Importance;
|
||||
type Error = StyleParseErrorKind<'i>;
|
||||
|
||||
fn parse_value<'t>(&mut self, name: CowRcStr<'i>, input: &mut Parser<'i, 't>)
|
||||
-> Result<Importance, ParseError<'i>> {
|
||||
let prop_context = PropertyParserContext::new(self.context);
|
||||
let id = match PropertyId::parse(&name, Some(&prop_context)) {
|
||||
fn parse_value<'t>(
|
||||
&mut self,
|
||||
name: CowRcStr<'i>,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Importance, ParseError<'i>> {
|
||||
let id = match PropertyId::parse(&name) {
|
||||
Ok(id) => id,
|
||||
Err(()) => {
|
||||
Err(..) => {
|
||||
return Err(input.new_custom_error(if is_non_mozilla_vendor_identifier(&name) {
|
||||
StyleParseErrorKind::UnknownVendorProperty
|
||||
} else {
|
||||
|
@ -1107,7 +1110,6 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for PropertyDeclarationParser<'a, 'b> {
|
|||
};
|
||||
input.parse_until_before(Delimiter::Bang, |input| {
|
||||
PropertyDeclaration::parse_into(self.declarations, id, name, self.context, input)
|
||||
.map_err(|e| e.into())
|
||||
})?;
|
||||
let importance = match input.try(parse_important) {
|
||||
Ok(()) => Importance::Important,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue