Skip to content

Commit

Permalink
stylo: Update rust-cssparser; extract more specific error types when …
Browse files Browse the repository at this point in the history
…reporting (bug 1352669).
  • Loading branch information
jdm committed Jul 11, 2017
1 parent a08371e commit 0b43d00
Show file tree
Hide file tree
Showing 21 changed files with 318 additions and 80 deletions.
26 changes: 13 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/canvas/Cargo.toml
Expand Up @@ -12,7 +12,7 @@ path = "lib.rs"
[dependencies]
azure = {git = "https://github.com/servo/rust-azure"}
canvas_traits = {path = "../canvas_traits"}
cssparser = "0.16.1"
cssparser = "0.17.0"
euclid = "0.15"
gleam = "0.4"
ipc-channel = "0.8"
Expand Down
2 changes: 1 addition & 1 deletion components/canvas_traits/Cargo.toml
Expand Up @@ -10,7 +10,7 @@ name = "canvas_traits"
path = "lib.rs"

[dependencies]
cssparser = "0.16.1"
cssparser = "0.17.0"
euclid = "0.15"
heapsize = "0.4"
heapsize_derive = "0.1"
Expand Down
2 changes: 1 addition & 1 deletion components/script/Cargo.toml
Expand Up @@ -35,7 +35,7 @@ byteorder = "1.0"
canvas_traits = {path = "../canvas_traits"}
caseless = "0.1.0"
cookie = "0.6"
cssparser = "0.16.1"
cssparser = "0.17.0"
deny_public_fields = {path = "../deny_public_fields"}
devtools_traits = {path = "../devtools_traits"}
dom_struct = {path = "../dom_struct"}
Expand Down
2 changes: 1 addition & 1 deletion components/script_layout_interface/Cargo.toml
Expand Up @@ -13,7 +13,7 @@ path = "lib.rs"
app_units = "0.5"
atomic_refcell = "0.1"
canvas_traits = {path = "../canvas_traits"}
cssparser = "0.16.1"
cssparser = "0.17.0"
euclid = "0.15"
gfx_traits = {path = "../gfx_traits"}
heapsize = "0.4"
Expand Down
2 changes: 1 addition & 1 deletion components/selectors/Cargo.toml
Expand Up @@ -25,7 +25,7 @@ unstable = []
[dependencies]
bitflags = "0.7"
matches = "0.1"
cssparser = "0.16.1"
cssparser = "0.17.0"
log = "0.3"
fnv = "1.0"
phf = "0.7.18"
Expand Down
7 changes: 4 additions & 3 deletions components/selectors/parser.rs
Expand Up @@ -59,7 +59,7 @@ pub enum SelectorParseError<'i, T> {
PseudoElementExpectedIdent,
UnsupportedPseudoClass,
UnexpectedIdent(CompactCowStr<'i>),
ExpectedNamespace,
ExpectedNamespace(CompactCowStr<'i>),
Custom(T),
}

Expand Down Expand Up @@ -1105,9 +1105,10 @@ fn parse_qualified_name<'i, 't, P, E, Impl>
let position = input.position();
match input.next_including_whitespace() {
Ok(Token::Delim('|')) => {
let prefix = from_cow_str(value.into());
let prefix = from_cow_str(value.clone().into());
let result = parser.namespace_for_prefix(&prefix);
let url = result.ok_or(ParseError::Custom(SelectorParseError::ExpectedNamespace))?;
let url = result.ok_or(ParseError::Custom(
SelectorParseError::ExpectedNamespace(value.into())))?;
explicit_namespace(input, QNamePrefix::ExplicitNamespace(prefix, url))
},
_ => {
Expand Down
2 changes: 1 addition & 1 deletion components/style/Cargo.toml
Expand Up @@ -38,7 +38,7 @@ bitflags = "0.7"
bit-vec = "0.4.3"
byteorder = "1.0"
cfg-if = "0.1.0"
cssparser = "0.16.1"
cssparser = "0.17.0"
encoding = {version = "0.2", optional = true}
euclid = "0.15"
fnv = "1.0"
Expand Down
8 changes: 4 additions & 4 deletions components/style/custom_properties.rs
Expand Up @@ -280,10 +280,10 @@ fn parse_declaration_value_block<'i, 't>
}
token.serialization_type()
}
Token::BadUrl =>
return Err(StyleParseError::BadUrlInDeclarationValueBlock.into()),
Token::BadString =>
return Err(StyleParseError::BadStringInDeclarationValueBlock.into()),
Token::BadUrl(u) =>
return Err(StyleParseError::BadUrlInDeclarationValueBlock(u).into()),
Token::BadString(s) =>
return Err(StyleParseError::BadStringInDeclarationValueBlock(s).into()),
Token::CloseParenthesis =>
return Err(StyleParseError::UnbalancedCloseParenthesisInDeclarationValueBlock.into()),
Token::CloseSquareBracket =>
Expand Down
10 changes: 5 additions & 5 deletions components/style/error_reporting.rs
Expand Up @@ -76,8 +76,8 @@ impl<'a> ContextualParseError<'a> {
Token::ParenthesisBlock => format!("parenthesis ("),
Token::SquareBracketBlock => format!("square bracket ["),
Token::CurlyBracketBlock => format!("curly bracket {{"),
Token::BadUrl => format!("bad url parse error"),
Token::BadString => format!("bad string parse error"),
Token::BadUrl(ref _u) => format!("bad url parse error"),
Token::BadString(ref _s) => format!("bad string parse error"),
Token::CloseParenthesis => format!("unmatched close parenthesis"),
Token::CloseSquareBracket => format!("unmatched close square bracket"),
Token::CloseCurlyBracket => format!("unmatched close curly bracket"),
Expand All @@ -88,11 +88,11 @@ impl<'a> ContextualParseError<'a> {
match *err {
CssParseError::Basic(BasicParseError::UnexpectedToken(ref t)) =>
format!("found unexpected {}", token_to_str(t)),
CssParseError::Basic(BasicParseError::ExpectedToken(ref t)) =>
format!("expected {}", token_to_str(t)),
CssParseError::Basic(BasicParseError::EndOfInput) =>
format!("unexpected end of input"),
CssParseError::Basic(BasicParseError::AtRuleInvalid) =>
CssParseError::Basic(BasicParseError::AtRuleInvalid(ref i)) =>
format!("@ rule invalid: {}", i),
CssParseError::Basic(BasicParseError::AtRuleBodyInvalid) =>
format!("@ rule invalid"),
CssParseError::Basic(BasicParseError::QualifiedRuleInvalid) =>
format!("qualified rule invalid"),
Expand Down
11 changes: 9 additions & 2 deletions components/style/properties/declaration_block.rs
Expand Up @@ -908,10 +908,17 @@ pub fn parse_one_declaration_into(declarations: &mut SourcePropertyDeclaration,
parsing_mode,
quirks_mode);
let mut input = ParserInput::new(input);
Parser::new(&mut input).parse_entirely(|parser| {
let mut parser = Parser::new(&mut input);
let start = parser.position();
parser.parse_entirely(|parser| {
PropertyDeclaration::parse_into(declarations, id, &context, parser)
.map_err(|e| e.into())
}).map_err(|_| ())
}).map_err(|err| {
let end = parser.position();
let error = ContextualParseError::UnsupportedPropertyDeclaration(
parser.slice(start..end), err);
log_css_error(&mut parser, start, error, &context);
})
}

/// A struct to parse property declarations.
Expand Down
11 changes: 6 additions & 5 deletions components/style/properties/properties.mako.rs
Expand Up @@ -37,7 +37,8 @@ use properties::animated_properties::AnimatableLonghand;
use selectors::parser::SelectorParseError;
#[cfg(feature = "servo")] use servo_config::prefs::PREFS;
use shared_lock::StylesheetGuards;
use style_traits::{PARSING_MODE_DEFAULT, HasViewportPercentage, ToCss, ParseError, PropertyDeclarationParseError};
use style_traits::{PARSING_MODE_DEFAULT, HasViewportPercentage, ToCss, ParseError};
use style_traits::{PropertyDeclarationParseError, StyleParseError};
use stylesheets::{CssRuleType, MallocSizeOf, MallocSizeOfFn, Origin, UrlExtraData};
#[cfg(feature = "servo")] use values::Either;
use values::generics::text::LineHeight;
Expand Down Expand Up @@ -1009,7 +1010,7 @@ impl PropertyId {
match static_id(&property_name) {
Some(&StaticId::Longhand(id)) => Ok(PropertyId::Longhand(id)),
Some(&StaticId::Shorthand(id)) => Ok(PropertyId::Shorthand(id)),
None => Err(SelectorParseError::UnexpectedIdent(property_name).into()),
None => Err(StyleParseError::UnknownProperty(property_name).into()),
}
}

Expand Down Expand Up @@ -1414,7 +1415,7 @@ impl PropertyDeclaration {
Ok(keyword) => DeclaredValueOwned::CSSWideKeyword(keyword),
Err(_) => match ::custom_properties::SpecifiedValue::parse(context, input) {
Ok(value) => DeclaredValueOwned::Value(value),
Err(_) => return Err(PropertyDeclarationParseError::InvalidValue),
Err(_) => return Err(PropertyDeclarationParseError::InvalidValue(name.to_string())),
}
};
declarations.push(PropertyDeclaration::Custom(name, value));
Expand Down Expand Up @@ -1442,7 +1443,7 @@ impl PropertyDeclaration {
declarations.push(value);
Ok(())
},
Err(_) => Err(PropertyDeclarationParseError::InvalidValue),
Err(_) => Err(PropertyDeclarationParseError::InvalidValue("${property.ident}".into())),
}
% else:
Err(PropertyDeclarationParseError::UnknownProperty)
Expand Down Expand Up @@ -1482,7 +1483,7 @@ impl PropertyDeclaration {
},
Err(_) => {
shorthands::${shorthand.ident}::parse_into(declarations, context, input)
.map_err(|_| PropertyDeclarationParseError::InvalidValue)
.map_err(|_| PropertyDeclarationParseError::InvalidValue("${shorthand.ident}".into()))
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions components/style/stylesheets/rule_parser.rs
Expand Up @@ -7,7 +7,7 @@
use {Namespace, Prefix};
use counter_style::{parse_counter_style_body, parse_counter_style_name};
use cssparser::{AtRuleParser, AtRuleType, Parser, QualifiedRuleParser, RuleListParser};
use cssparser::{CompactCowStr, SourceLocation};
use cssparser::{CompactCowStr, SourceLocation, BasicParseError};
use error_reporting::ContextualParseError;
use font_face::parse_font_face_block;
use media_queries::{parse_media_query_list, MediaList};
Expand Down Expand Up @@ -184,7 +184,13 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
self.state = State::Namespaces;

let prefix_result = input.try(|input| input.expect_ident());
let url = Namespace::from(Cow::from(input.expect_url_or_string()?));
let maybe_namespace = match input.expect_url_or_string() {
Ok(url_or_string) => url_or_string,
Err(BasicParseError::UnexpectedToken(t)) =>
return Err(StyleParseError::UnexpectedTokenWithinNamespace(t).into()),
Err(e) => return Err(e.into()),
};
let url = Namespace::from(Cow::from(maybe_namespace));

let id = register_namespace(&url)
.map_err(|()| StyleParseError::UnspecifiedError)?;
Expand Down Expand Up @@ -509,7 +515,7 @@ fn get_location_with_offset(
offset: u64
) -> SourceLocation {
SourceLocation {
line: location.line + offset as u32 - 1,
line: location.line + offset as u32,
column: location.column,
}
}
2 changes: 1 addition & 1 deletion components/style_traits/Cargo.toml
Expand Up @@ -16,7 +16,7 @@ gecko = []
[dependencies]
app_units = "0.5"
bitflags = "0.7"
cssparser = "0.16.1"
cssparser = "0.17.0"
euclid = "0.15"
heapsize = {version = "0.4", optional = true}
heapsize_derive = {version = "0.1", optional = true}
Expand Down
14 changes: 9 additions & 5 deletions components/style_traits/lib.rs
Expand Up @@ -22,7 +22,7 @@ extern crate euclid;
extern crate selectors;
#[cfg(feature = "servo")] #[macro_use] extern crate serde;

use cssparser::CompactCowStr;
use cssparser::{CompactCowStr, Token};
use selectors::parser::SelectorParseError;

/// Opaque type stored in type-unsafe work queues for parallel layout.
Expand Down Expand Up @@ -81,9 +81,9 @@ pub type ParseError<'i> = cssparser::ParseError<'i, SelectorParseError<'i, Style
/// Errors that can be encountered while parsing CSS values.
pub enum StyleParseError<'i> {
/// A bad URL token in a DVB.
BadUrlInDeclarationValueBlock,
BadUrlInDeclarationValueBlock(CompactCowStr<'i>),
/// A bad string token in a DVB.
BadStringInDeclarationValueBlock,
BadStringInDeclarationValueBlock(CompactCowStr<'i>),
/// Unexpected closing parenthesis in a DVB.
UnbalancedCloseParenthesisInDeclarationValueBlock,
/// Unexpected closing bracket in a DVB.
Expand All @@ -110,17 +110,21 @@ pub enum StyleParseError<'i> {
UnsupportedAtRule(CompactCowStr<'i>),
/// A placeholder for many sources of errors that require more specific variants.
UnspecifiedError,
/// An unexpected token was found within a namespace rule.
UnexpectedTokenWithinNamespace(Token<'i>),
/// An unknown CSS property was encountered.
UnknownProperty(CompactCowStr<'i>),
}

/// The result of parsing a property declaration.
#[derive(Eq, PartialEq, Copy, Clone, Debug)]
#[derive(Eq, PartialEq, Clone, Debug)]
pub enum PropertyDeclarationParseError {
/// The property declaration was for an unknown property.
UnknownProperty,
/// The property declaration was for a disabled experimental property.
ExperimentalProperty,
/// The property declaration contained an invalid value.
InvalidValue,
InvalidValue(String),
/// The declaration contained an animation property, and we were parsing
/// this as a keyframe block (so that property should be ignored).
///
Expand Down
2 changes: 1 addition & 1 deletion ports/geckolib/Cargo.toml
Expand Up @@ -16,7 +16,7 @@ gecko_debug = ["style/gecko_debug"]

[dependencies]
atomic_refcell = "0.1"
cssparser = "0.16.1"
cssparser = "0.17.0"
env_logger = {version = "0.4", default-features = false} # disable `regex` to reduce code size
libc = "0.2"
log = {version = "0.3.5", features = ["release_max_level_info"]}
Expand Down

0 comments on commit 0b43d00

Please sign in to comment.