From 3be7ad8b6fc385721cab6b9777d84d742b809020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jim=C3=A9nez=20Moreno?= Date: Mon, 11 Sep 2017 18:47:12 +0200 Subject: [PATCH] stylo: Fix error reporting for invalid values in property alias --- .../style/properties/declaration_block.rs | 5 +++-- components/style/properties/properties.mako.rs | 17 +++++++++-------- components/style/stylesheets/keyframes_rule.rs | 4 ++-- components/style/stylesheets/supports_rule.rs | 2 +- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index 60849029527..a19449baa26 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -934,7 +934,8 @@ pub fn parse_one_declaration_into(declarations: &mut SourcePropertyDeclaratio let start_position = parser.position(); let start_location = parser.current_source_location(); parser.parse_entirely(|parser| { - PropertyDeclaration::parse_into(declarations, id, &context, parser) + let name = id.name().into(); + PropertyDeclaration::parse_into(declarations, id, name, &context, parser) .map_err(|e| e.into()) }).map_err(|err| { let error = ContextualParseError::UnsupportedPropertyDeclaration( @@ -983,7 +984,7 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for PropertyDeclarationParser<'a, 'b> { } }; input.parse_until_before(Delimiter::Bang, |input| { - PropertyDeclaration::parse_into(self.declarations, id, self.context, input) + PropertyDeclaration::parse_into(self.declarations, id, name, self.context, input) .map_err(|e| e.into()) })?; let importance = match input.try(parse_important) { diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 1a02a02fa31..cd127b4429d 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -18,7 +18,7 @@ use std::{fmt, mem, ops}; #[cfg(feature = "gecko")] use std::ptr; #[cfg(feature = "servo")] use cssparser::RGBA; -use cssparser::{Parser, TokenSerializationType, serialize_identifier}; +use cssparser::{CowRcStr, Parser, TokenSerializationType, serialize_identifier}; use cssparser::ParserInput; #[cfg(feature = "servo")] use euclid::SideOffsets2D; use computed_values; @@ -1527,12 +1527,13 @@ impl PropertyDeclaration { /// to Importance::Normal. Parsing Importance values is the job of PropertyDeclarationParser, /// we only set them here so that we don't have to reallocate pub fn parse_into<'i, 't>(declarations: &mut SourcePropertyDeclaration, - id: PropertyId, context: &ParserContext, input: &mut Parser<'i, 't>) + id: PropertyId, name: CowRcStr<'i>, + context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<(), PropertyDeclarationParseError<'i>> { assert!(declarations.is_empty()); let start = input.state(); match id { - PropertyId::Custom(name) => { + PropertyId::Custom(property_name) => { // FIXME: fully implement https://github.com/w3c/csswg-drafts/issues/774 // before adding skip_whitespace here. // This probably affects some test results. @@ -1544,7 +1545,7 @@ impl PropertyDeclaration { ValueParseError::from_parse_error(e))), } }; - declarations.push(PropertyDeclaration::Custom(name, value)); + declarations.push(PropertyDeclaration::Custom(property_name, value)); Ok(()) } PropertyId::Longhand(id) => { @@ -1560,7 +1561,7 @@ impl PropertyDeclaration { input.reset(&start); let (first_token_type, css) = ::custom_properties::parse_non_custom_with_var(input).map_err(|e| { - PropertyDeclarationParseError::InvalidValue(id.name().into(), + PropertyDeclarationParseError::InvalidValue(name, ValueParseError::from_parse_error(e)) })?; Ok(PropertyDeclaration::WithVariables(id, Arc::new(UnparsedValue { @@ -1570,7 +1571,7 @@ impl PropertyDeclaration { from_shorthand: None, }))) } else { - Err(PropertyDeclarationParseError::InvalidValue(id.name().into(), + Err(PropertyDeclarationParseError::InvalidValue(name, ValueParseError::from_parse_error(err))) } }) @@ -1599,7 +1600,7 @@ impl PropertyDeclaration { input.reset(&start); let (first_token_type, css) = ::custom_properties::parse_non_custom_with_var(input).map_err(|e| { - PropertyDeclarationParseError::InvalidValue(id.name().into(), + PropertyDeclarationParseError::InvalidValue(name, ValueParseError::from_parse_error(e)) })?; let unparsed = Arc::new(UnparsedValue { @@ -1619,7 +1620,7 @@ impl PropertyDeclaration { } Ok(()) } else { - Err(PropertyDeclarationParseError::InvalidValue(id.name().into(), + Err(PropertyDeclarationParseError::InvalidValue(name, ValueParseError::from_parse_error(err))) } }) diff --git a/components/style/stylesheets/keyframes_rule.rs b/components/style/stylesheets/keyframes_rule.rs index e9fffab9209..394deb37df2 100644 --- a/components/style/stylesheets/keyframes_rule.rs +++ b/components/style/stylesheets/keyframes_rule.rs @@ -583,8 +583,8 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for KeyframeDeclarationParser<'a, 'b> { let property_context = PropertyParserContext::new(self.context); let id = PropertyId::parse(&name, Some(&property_context)) - .map_err(|()| PropertyDeclarationParseError::UnknownProperty(name))?; - match PropertyDeclaration::parse_into(self.declarations, id, self.context, input) { + .map_err(|()| PropertyDeclarationParseError::UnknownProperty(name.clone()))?; + match PropertyDeclaration::parse_into(self.declarations, id, name, self.context, input) { Ok(()) => { // In case there is still unparsed text in the declaration, we should roll back. input.expect_exhausted().map_err(|e| e.into()) diff --git a/components/style/stylesheets/supports_rule.rs b/components/style/stylesheets/supports_rule.rs index ee5e7516642..2f21bd3b555 100644 --- a/components/style/stylesheets/supports_rule.rs +++ b/components/style/stylesheets/supports_rule.rs @@ -265,7 +265,7 @@ impl Declaration { let mut declarations = SourcePropertyDeclaration::new(); input.parse_until_before(Delimiter::Bang, |input| { - PropertyDeclaration::parse_into(&mut declarations, id, &context, input) + PropertyDeclaration::parse_into(&mut declarations, id, prop.into(), &context, input) .map_err(|e| StyleParseError::PropertyDeclaration(e).into()) })?; let _ = input.try(parse_important);