Skip to content

Commit

Permalink
style: Add a new CSS error type for lone value parsing errors.
Browse files Browse the repository at this point in the history
This allows us to report errors in functions that want to just parse a
single CSS value, rather than a value for a particular property declaration.

The one value type that we need to support for now is <color> value parsing
errors, so just add formatting/support for that.
  • Loading branch information
heycam committed Dec 5, 2017
1 parent 7940061 commit 7015d5b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions components/style/error_reporting.rs
Expand Up @@ -46,6 +46,8 @@ pub enum ContextualParseError<'a> {
InvalidCounterStyleExtendsWithAdditiveSymbols,
/// A media rule was invalid for some reason.
InvalidMediaRule(&'a str, ParseError<'a>),
/// A value was not recognized.
UnsupportedValue(&'a str, ParseError<'a>),
}

impl<'a> fmt::Display for ContextualParseError<'a> {
Expand Down Expand Up @@ -173,6 +175,9 @@ impl<'a> fmt::Display for ContextualParseError<'a> {
write!(f, "Invalid media rule: {}, ", media_rule)?;
parse_error_to_str(err, f)
}
ContextualParseError::UnsupportedValue(_value, ref err) => {
parse_error_to_str(err, f)
}
}
}
}
Expand Down
25 changes: 23 additions & 2 deletions ports/geckolib/error_reporter.rs
Expand Up @@ -17,7 +17,7 @@ use style::gecko_bindings::structs::{Loader, ServoStyleSheet, nsIURI};
use style::gecko_bindings::structs::ErrorReporter as GeckoErrorReporter;
use style::gecko_bindings::structs::URLExtraData as RawUrlExtraData;
use style::stylesheets::UrlExtraData;
use style_traits::StyleParseErrorKind;
use style_traits::{StyleParseErrorKind, ValueParseErrorKind};

pub type ErrorKind<'i> = ParseErrorKind<'i, StyleParseErrorKind<'i>>;

Expand Down Expand Up @@ -139,6 +139,9 @@ fn extract_error_params<'a>(err: ErrorKind<'a>) -> Option<ErrorParams<'a>> {

ParseErrorKind::Custom(
StyleParseErrorKind::ExpectedIdentifier(token)
) |
ParseErrorKind::Custom(
StyleParseErrorKind::ValueError(ValueParseErrorKind::InvalidColor(token))
) => {
(Some(ErrorString::UnexpectedToken(token)), None)
}
Expand Down Expand Up @@ -198,7 +201,8 @@ impl<'a> ErrorHelpers<'a> for ContextualParseError<'a> {
ContextualParseError::UnsupportedRule(s, err) |
ContextualParseError::UnsupportedViewportDescriptorDeclaration(s, err) |
ContextualParseError::UnsupportedCounterStyleDescriptorDeclaration(s, err) |
ContextualParseError::InvalidMediaRule(s, err) => {
ContextualParseError::InvalidMediaRule(s, err) |
ContextualParseError::UnsupportedValue(s, err) => {
(s.into(), err.kind)
}
ContextualParseError::InvalidCounterStyleWithoutSymbols(s) |
Expand Down Expand Up @@ -360,6 +364,23 @@ impl<'a> ErrorHelpers<'a> for ContextualParseError<'a> {
ContextualParseError::UnsupportedFontFeatureValuesDescriptor(..) |
ContextualParseError::InvalidFontFeatureValuesRule(..) =>
(b"PEUnknownAtRule\0", Action::Skip),
ContextualParseError::UnsupportedValue(_, ParseError { ref kind, .. }) => {
match *kind {
ParseErrorKind::Custom(
StyleParseErrorKind::ValueError(
ValueParseErrorKind::InvalidColor(..)
)
) => (b"PEColorNotColor", Action::Nothing),
_ => {
// Not the best error message, since we weren't parsing
// a declaration, just a value. But we don't produce
// UnsupportedValue errors other than InvalidColors
// currently.
debug_assert!(false, "should use a more specific error message");
(b"PEDeclDropped", Action::Nothing)
}
}
}
};
(None, msg, action)
}
Expand Down

0 comments on commit 7015d5b

Please sign in to comment.