servo: Merge #17859 - Add message suffixes to stylo error reports (from jdm:geckodecl); r=heycam
authorJosh Matthews <josh@joshmatthews.net>
Wed, 26 Jul 2017 06:46:13 -0500
changeset 371166 e6bf9d2afc7d0cd3f7dc35fcdfeeec5e22d27ef9
parent 371165 0886a662636dd8ed8fceb7fbb139f35332c4dd87
child 371167 5a8e2014949047ed5daf62f2636ef3e0ab3dda38
push id93039
push userkwierso@gmail.com
push dateThu, 27 Jul 2017 01:33:28 +0000
treeherdermozilla-inbound@35b0bdaacb0d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
servo: Merge #17859 - Add message suffixes to stylo error reports (from jdm:geckodecl); r=heycam This is the Servo-side part of https://bugzilla.mozilla.org/show_bug.cgi?id=1381137. This allows us to add the "Declaration dropped" or "Skipped to next declaration" messages after relevant CSS errors that are reported. --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors Source-Repo: https://github.com/servo/servo Source-Revision: f59bd8e2b2b245e76a587ce548af3975797f46e8
servo/components/style/gecko/generated/bindings.rs
servo/ports/geckolib/error_reporter.rs
--- a/servo/components/style/gecko/generated/bindings.rs
+++ b/servo/components/style/gecko/generated/bindings.rs
@@ -2840,10 +2840,11 @@ extern "C" {
                                           message:
                                               *const ::std::os::raw::c_char,
                                           param:
                                               *const ::std::os::raw::c_char,
                                           paramLen: u32,
                                           source:
                                               *const ::std::os::raw::c_char,
                                           sourceLen: u32, lineNumber: u32,
-                                          colNumber: u32, aURI: *mut nsIURI);
-}
+                                          colNumber: u32, aURI: *mut nsIURI,
+                                          followup: *const ::std::os::raw::c_char);
+}
--- a/servo/ports/geckolib/error_reporter.rs
+++ b/servo/ports/geckolib/error_reporter.rs
@@ -4,16 +4,17 @@
 
 //! Wrapper around Gecko's CSS error reporting mechanism.
 
 #![allow(unsafe_code)]
 
 use cssparser::{Parser, SourcePosition, ParseError as CssParseError, Token, BasicParseError};
 use cssparser::CowRcStr;
 use selectors::parser::SelectorParseError;
+use std::ptr;
 use style::error_reporting::{ParseErrorReporter, ContextualParseError};
 use style::gecko_bindings::bindings::{Gecko_CreateCSSErrorReporter, Gecko_DestroyCSSErrorReporter};
 use style::gecko_bindings::bindings::Gecko_ReportUnexpectedCSSError;
 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::gecko_bindings::sugar::refptr::RefPtr;
 use style::stylesheets::UrlExtraData;
@@ -180,20 +181,26 @@ fn token_to_str<'a>(t: Token<'a>) -> Str
         Token::BadUrl(url) => format!("url('{}", escape_css_string(&url)).into(),
         Token::BadString(s) => format!("'{}", escape_css_string(&s)).into(),
         Token::CloseParenthesis => "unmatched close parenthesis".into(),
         Token::CloseSquareBracket => "unmatched close square bracket".into(),
         Token::CloseCurlyBracket => "unmatched close curly bracket".into(),
     }
 }
 
+enum Action {
+    Nothing,
+    Skip,
+    Drop,
+}
+
 trait ErrorHelpers<'a> {
     fn error_data(self) -> (CowRcStr<'a>, ParseError<'a>);
     fn error_param(self) -> ErrorString<'a>;
-    fn to_gecko_message(&self) -> &'static [u8];
+    fn to_gecko_message(&self) -> (&'static [u8], Action);
 }
 
 impl<'a> ErrorHelpers<'a> for ContextualParseError<'a> {
     fn error_data(self) -> (CowRcStr<'a>, ParseError<'a>) {
         match self {
             ContextualParseError::UnsupportedPropertyDeclaration(s, err) |
             ContextualParseError::UnsupportedFontFaceDescriptor(s, err) |
             ContextualParseError::InvalidKeyframeRule(s, err) |
@@ -240,78 +247,84 @@ impl<'a> ErrorHelpers<'a> for Contextual
             (_, CssParseError::Custom(SelectorParseError::Custom(
                 StyleParseError::UnexpectedTokenWithinNamespace(token)))) =>
                 ErrorString::UnexpectedToken(token),
 
             (s, _)  => ErrorString::Snippet(s)
         }
     }
 
-    fn to_gecko_message(&self) -> &'static [u8] {
+    fn to_gecko_message(&self) -> (&'static [u8], Action) {
         match *self {
             ContextualParseError::UnsupportedPropertyDeclaration(
                 _, CssParseError::Basic(BasicParseError::UnexpectedToken(_))) |
             ContextualParseError::UnsupportedPropertyDeclaration(
                 _, CssParseError::Basic(BasicParseError::AtRuleInvalid(_))) =>
-                b"PEParseDeclarationDeclExpected\0",
+                (b"PEParseDeclarationDeclExpected\0", Action::Skip),
             ContextualParseError::UnsupportedPropertyDeclaration(
                 _, CssParseError::Custom(SelectorParseError::Custom(
                     StyleParseError::PropertyDeclaration(
                         PropertyDeclarationParseError::InvalidValue(_))))) =>
-                b"PEValueParsingError\0",
+                (b"PEValueParsingError\0", Action::Drop),
             ContextualParseError::UnsupportedPropertyDeclaration(..) =>
-                b"PEUnknownProperty\0",
+                (b"PEUnknownProperty\0", Action::Drop),
             ContextualParseError::UnsupportedFontFaceDescriptor(..) =>
-                b"PEUnknwnFontDesc\0",
+                (b"PEUnknwnFontDesc\0", Action::Skip),
             ContextualParseError::InvalidKeyframeRule(..) =>
-                b"PEKeyframeBadName\0",
+                (b"PEKeyframeBadName\0", Action::Nothing),
             ContextualParseError::UnsupportedKeyframePropertyDeclaration(..) =>
-                b"PEBadSelectorKeyframeRuleIgnored\0",
+                (b"PEBadSelectorKeyframeRuleIgnored\0", Action::Nothing),
             ContextualParseError::InvalidRule(
                 _, CssParseError::Custom(SelectorParseError::ExpectedNamespace(_))) =>
-                b"PEUnknownNamespacePrefix\0",
+                (b"PEUnknownNamespacePrefix\0", Action::Nothing),
             ContextualParseError::InvalidRule(
                 _, CssParseError::Custom(SelectorParseError::Custom(
                 StyleParseError::UnexpectedTokenWithinNamespace(_)))) =>
-                b"PEAtNSUnexpected\0",
+                (b"PEAtNSUnexpected\0", Action::Nothing),
             ContextualParseError::InvalidRule(..) =>
-                b"PEBadSelectorRSIgnored\0",
+                (b"PEBadSelectorRSIgnored\0", Action::Nothing),
             ContextualParseError::UnsupportedRule(..) =>
-                b"PEDeclDropped\0",
+                (b"PEDeclDropped\0", Action::Nothing),
             ContextualParseError::UnsupportedViewportDescriptorDeclaration(..) |
             ContextualParseError::UnsupportedCounterStyleDescriptorDeclaration(..) |
             ContextualParseError::InvalidCounterStyleWithoutSymbols(..) |
             ContextualParseError::InvalidCounterStyleNotEnoughSymbols(..) |
             ContextualParseError::InvalidCounterStyleWithoutAdditiveSymbols |
             ContextualParseError::InvalidCounterStyleExtendsWithSymbols |
             ContextualParseError::InvalidCounterStyleExtendsWithAdditiveSymbols =>
-                b"PEUnknownAtRule\0",
+                (b"PEUnknownAtRule\0", Action::Skip),
         }
     }
 }
 
 impl ParseErrorReporter for ErrorReporter {
     fn report_error<'a>(&self,
                         input: &mut Parser,
                         position: SourcePosition,
                         error: ContextualParseError<'a>,
                         url: &UrlExtraData,
                         line_number_offset: u64) {
         let location = input.source_location(position);
         let line_number = location.line + line_number_offset as u32;
 
-        let name = error.to_gecko_message();
+        let (name, action) = error.to_gecko_message();
+        let followup = match action {
+            Action::Nothing => ptr::null(),
+            Action::Skip => b"PEDeclSkipped\0".as_ptr(),
+            Action::Drop => b"PEDeclDropped\0".as_ptr(),
+        };
         let param = error.error_param().into_str();
         // The CSS source text is unused and will be removed in bug 1381188.
         let source = "";
         unsafe {
             Gecko_ReportUnexpectedCSSError(self.0,
                                            name.as_ptr() as *const _,
                                            param.as_ptr() as *const _,
                                            param.len() as u32,
                                            source.as_ptr() as *const _,
                                            source.len() as u32,
                                            line_number as u32,
                                            location.column as u32,
-                                           url.mBaseURI.raw::<nsIURI>());
+                                           url.mBaseURI.raw::<nsIURI>(),
+                                           followup as *const _);
         }
     }
 }