diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index 0263de83fef..a66058caf1e 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -1158,7 +1158,7 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for PropertyDeclarationParser<'a, 'b> { name: CowRcStr<'i>, input: &mut Parser<'i, 't>, ) -> Result> { - let id = match PropertyId::parse(&name) { + let id = match PropertyId::parse(&name, self.context) { Ok(id) => id, Err(..) => { return Err(input.new_custom_error(if is_non_mozilla_vendor_identifier(&name) { diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 7696f15c8b8..9ce7d3dfc38 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1595,7 +1595,7 @@ impl PropertyId { /// Returns a given property from the string `s`. /// /// Returns Err(()) for unknown non-custom properties. - pub fn parse(property_name: &str) -> Result { + fn parse_unchecked(property_name: &str) -> Result { // FIXME(https://github.com/rust-lang/rust/issues/33156): remove this // enum and use PropertyId when stable Rust allows destructors in // statics. @@ -1639,13 +1639,39 @@ impl PropertyId { PropertyId::ShorthandAlias(id, alias) }, None => { - return ::custom_properties::parse_name(property_name).map(|name| { - PropertyId::Custom(::custom_properties::Name::from(name)) - }) + let name = ::custom_properties::parse_name(property_name)?; + PropertyId::Custom(::custom_properties::Name::from(name)) }, }) } + /// Parses a property name, and returns an error if it's unknown or isn't + /// enabled for all content. + #[inline] + pub fn parse_enabled_for_all_content(name: &str) -> Result { + let id = Self::parse_unchecked(name)?; + + if !id.enabled_for_all_content() { + return Err(()); + } + + Ok(id) + } + + + /// Parses a property name, and returns an error if it's unknown or isn't + /// allowed in this context. + #[inline] + pub fn parse(name: &str, context: &ParserContext) -> Result { + let id = Self::parse_unchecked(name)?; + + if !id.allowed_in(context) { + return Err(()); + } + + Ok(id) + } + /// Returns a property id from Gecko's nsCSSPropertyID. #[cfg(feature = "gecko")] #[allow(non_upper_case_globals)] @@ -1715,8 +1741,7 @@ impl PropertyId { } } - /// Returns the non-custom property id for this property. - pub fn non_custom_id(&self) -> Option { + fn non_custom_id(&self) -> Option { Some(match *self { PropertyId::Custom(_) => return None, PropertyId::Shorthand(shorthand_id) => shorthand_id.into(), @@ -1751,8 +1776,7 @@ impl PropertyId { id.enabled_for_all_content() } - /// Returns whether the property is allowed in a given context. - pub fn allowed_in(&self, context: &ParserContext) -> bool { + fn allowed_in(&self, context: &ParserContext) -> bool { let id = match self.non_custom_id() { // Custom properties are allowed everywhere None => return true, @@ -1974,12 +1998,7 @@ impl PropertyDeclaration { input: &mut Parser<'i, 't>, ) -> Result<(), ParseError<'i>> { assert!(declarations.is_empty()); - - if !id.allowed_in(context) { - return Err(input.new_custom_error( - StyleParseErrorKind::UnknownProperty(name) - )); - } + debug_assert!(id.allowed_in(context), "{:?}", id); let start = input.state(); match id { diff --git a/components/style/stylesheets/keyframes_rule.rs b/components/style/stylesheets/keyframes_rule.rs index 4de3acbaff5..afe797c12ff 100644 --- a/components/style/stylesheets/keyframes_rule.rs +++ b/components/style/stylesheets/keyframes_rule.rs @@ -620,9 +620,12 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for KeyframeDeclarationParser<'a, 'b> { name: CowRcStr<'i>, input: &mut Parser<'i, 't>, ) -> Result<(), ParseError<'i>> { - let id = PropertyId::parse(&name).map_err(|()| { - input.new_custom_error(StyleParseErrorKind::UnknownProperty(name.clone())) - })?; + let id = match PropertyId::parse(&name, self.context) { + Ok(id) => id, + Err(()) => return Err(input.new_custom_error( + StyleParseErrorKind::UnknownProperty(name.clone()) + )), + }; // TODO(emilio): Shouldn't this use parse_entirely? PropertyDeclaration::parse_into(self.declarations, id, name, self.context, input)?; diff --git a/components/style/stylesheets/supports_rule.rs b/components/style/stylesheets/supports_rule.rs index d94a9a0202a..5e2739d153d 100644 --- a/components/style/stylesheets/supports_rule.rs +++ b/components/style/stylesheets/supports_rule.rs @@ -315,12 +315,12 @@ impl Declaration { let mut input = ParserInput::new(&self.0); let mut input = Parser::new(&mut input); - input - .parse_entirely(|input| -> Result<(), CssParseError<()>> { + input.parse_entirely(|input| -> Result<(), CssParseError<()>> { let prop = input.expect_ident_cloned().unwrap(); input.expect_colon().unwrap(); - let id = PropertyId::parse(&prop).map_err(|_| input.new_custom_error(()))?; + let id = PropertyId::parse(&prop, context) + .map_err(|_| input.new_custom_error(()))?; let mut declarations = SourcePropertyDeclaration::new(); input.parse_until_before(Delimiter::Bang, |input| { diff --git a/components/style/values/specified/box.rs b/components/style/values/specified/box.rs index ed118acc74b..dcce3d592ab 100644 --- a/components/style/values/specified/box.rs +++ b/components/style/values/specified/box.rs @@ -444,15 +444,11 @@ fn change_bits_for_longhand(longhand: LonghandId) -> WillChangeBits { } fn change_bits_for_maybe_property(ident: &str, context: &ParserContext) -> WillChangeBits { - let id = match PropertyId::parse(ident) { + let id = match PropertyId::parse(ident, context) { Ok(id) => id, Err(..) => return WillChangeBits::empty(), }; - if !id.allowed_in(context) { - return WillChangeBits::empty(); - } - match id.as_shorthand() { Ok(shorthand) => { shorthand.longhands().fold(WillChangeBits::empty(), |flags, p| {