diff --git a/components/style/counter_style/mod.rs b/components/style/counter_style/mod.rs index 94b10aa0d33..2542dee3625 100644 --- a/components/style/counter_style/mod.rs +++ b/components/style/counter_style/mod.rs @@ -9,8 +9,8 @@ use Atom; use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser}; use cssparser::{CowRcStr, Parser, SourceLocation, Token}; -use error_reporting::{ContextualParseError, ParseErrorReporter}; -use parser::{Parse, ParserContext, ParserErrorContext}; +use error_reporting::ContextualParseError; +use parser::{Parse, ParserContext}; use selectors::parser::SelectorParseErrorKind; use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard}; use std::fmt::{self, Write}; @@ -73,16 +73,12 @@ pub fn parse_counter_style_name_definition<'i, 't>( } /// Parse the body (inside `{}`) of an @counter-style rule -pub fn parse_counter_style_body<'i, 't, R>( +pub fn parse_counter_style_body<'i, 't>( name: CustomIdent, context: &ParserContext, - error_context: &ParserErrorContext, input: &mut Parser<'i, 't>, location: SourceLocation, -) -> Result> -where - R: ParseErrorReporter, -{ +) -> Result> { let start = input.current_source_location(); let mut rule = CounterStyleRuleData::empty(name, location); { @@ -98,7 +94,7 @@ where slice, error, ); - context.log_css_error(error_context, location, error) + context.log_css_error(location, error) } } } @@ -134,7 +130,7 @@ where _ => None, }; if let Some(error) = error { - context.log_css_error(error_context, start, error); + context.log_css_error(start, error); Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)) } else { Ok(rule) diff --git a/components/style/error_reporting.rs b/components/style/error_reporting.rs index 2af76be87b9..af1e7ba5b86 100644 --- a/components/style/error_reporting.rs +++ b/components/style/error_reporting.rs @@ -249,17 +249,3 @@ impl ParseErrorReporter for RustLogReporter { } } } - -/// Error reporter which silently forgets errors -pub struct NullReporter; - -impl ParseErrorReporter for NullReporter { - fn report_error( - &self, - _url: &UrlExtraData, - _location: SourceLocation, - _error: ContextualParseError, - ) { - // do nothing - } -} diff --git a/components/style/font_face.rs b/components/style/font_face.rs index 57c0f3b0b77..d7501c1cca7 100644 --- a/components/style/font_face.rs +++ b/components/style/font_face.rs @@ -10,8 +10,8 @@ use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser}; use cssparser::{CowRcStr, SourceLocation}; #[cfg(feature = "gecko")] use cssparser::UnicodeRange; -use error_reporting::{ContextualParseError, ParseErrorReporter}; -use parser::{Parse, ParserContext, ParserErrorContext}; +use error_reporting::ContextualParseError; +use parser::{Parse, ParserContext}; #[cfg(feature = "gecko")] use properties::longhands::font_language_override; use selectors::parser::SelectorParseErrorKind; @@ -186,15 +186,11 @@ impl ToCss for FontStyle { /// Parse the block inside a `@font-face` rule. /// /// Note that the prelude parsing code lives in the `stylesheets` module. -pub fn parse_font_face_block( +pub fn parse_font_face_block( context: &ParserContext, - error_context: &ParserErrorContext, input: &mut Parser, location: SourceLocation, -) -> FontFaceRuleData -where - R: ParseErrorReporter, -{ +) -> FontFaceRuleData { let mut rule = FontFaceRuleData::empty(location); { let parser = FontFaceRuleParser { @@ -206,7 +202,7 @@ where if let Err((error, slice)) = declaration { let location = error.location; let error = ContextualParseError::UnsupportedFontFaceDescriptor(slice, error); - context.log_css_error(error_context, location, error) + context.log_css_error(location, error) } } } diff --git a/components/style/media_queries/media_list.rs b/components/style/media_queries/media_list.rs index 5243174e07f..122f18a0d5e 100644 --- a/components/style/media_queries/media_list.rs +++ b/components/style/media_queries/media_list.rs @@ -9,8 +9,8 @@ use context::QuirksMode; use cssparser::{Delimiter, Parser}; use cssparser::{ParserInput, Token}; -use error_reporting::{ContextualParseError, ParseErrorReporter}; -use parser::{ParserContext, ParserErrorContext}; +use error_reporting::ContextualParseError; +use parser::ParserContext; use super::{Device, MediaQuery, Qualifier}; /// A type that encapsulates a media query list. @@ -30,14 +30,10 @@ impl MediaList { /// "not all", see: /// /// - pub fn parse( + pub fn parse( context: &ParserContext, input: &mut Parser, - error_reporter: &R, - ) -> MediaList - where - R: ParseErrorReporter, - { + ) -> Self { if input.is_exhausted() { return Self::empty(); } @@ -54,8 +50,7 @@ impl MediaList { let location = err.location; let error = ContextualParseError::InvalidMediaRule(input.slice_from(start_position), err); - let error_context = ParserErrorContext { error_reporter }; - context.log_css_error(&error_context, location, error); + context.log_css_error(location, error); }, } diff --git a/components/style/parser.rs b/components/style/parser.rs index 6dbfe1cfa01..a4b7d816203 100644 --- a/components/style/parser.rs +++ b/components/style/parser.rs @@ -36,12 +36,6 @@ pub fn assert_parsing_mode_match() { } } -/// The context required to report a parse error. -pub struct ParserErrorContext<'a, R: 'a> { - /// An error reporter to report syntax errors. - pub error_reporter: &'a R, -} - /// The data that the parser needs from outside in order to parse a stylesheet. pub struct ParserContext<'a> { /// The `Origin` of the stylesheet, whether it's a user, author or @@ -55,6 +49,8 @@ pub struct ParserContext<'a> { pub parsing_mode: ParsingMode, /// The quirks mode of this stylesheet. pub quirks_mode: QuirksMode, + /// The active error reporter, or none if error reporting is disabled. + error_reporter: Option<&'a ParseErrorReporter>, /// The currently active namespaces. pub namespaces: Option<&'a Namespaces>, } @@ -68,6 +64,7 @@ impl<'a> ParserContext<'a> { rule_type: Option, parsing_mode: ParsingMode, quirks_mode: QuirksMode, + error_reporter: Option<&'a ParseErrorReporter>, ) -> Self { ParserContext { stylesheet_origin, @@ -75,6 +72,7 @@ impl<'a> ParserContext<'a> { rule_type, parsing_mode, quirks_mode, + error_reporter, namespaces: None, } } @@ -86,6 +84,7 @@ impl<'a> ParserContext<'a> { rule_type: Option, parsing_mode: ParsingMode, quirks_mode: QuirksMode, + error_reporter: Option<&'a ParseErrorReporter>, ) -> Self { Self::new( Origin::Author, @@ -93,6 +92,7 @@ impl<'a> ParserContext<'a> { rule_type, parsing_mode, quirks_mode, + error_reporter, ) } @@ -110,6 +110,7 @@ impl<'a> ParserContext<'a> { parsing_mode: context.parsing_mode, quirks_mode: context.quirks_mode, namespaces: Some(namespaces), + error_reporter: context.error_reporter, } } @@ -127,21 +128,17 @@ impl<'a> ParserContext<'a> { } /// Record a CSS parse error with this context’s error reporting. - pub fn log_css_error( + pub fn log_css_error( &self, - context: &ParserErrorContext, location: SourceLocation, error: ContextualParseError, - ) where - R: ParseErrorReporter, - { - let location = SourceLocation { - line: location.line, - column: location.column, + ) { + let error_reporter = match self.error_reporter { + Some(r) => r, + None => return, }; - context - .error_reporter - .report_error(self.url_data, location, error) + + error_reporter.report_error(self.url_data, location, error) } /// Returns whether chrome-only rules should be parsed. diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index cd89a4bbfbb..89c992f907d 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -11,7 +11,7 @@ use cssparser::{DeclarationListParser, parse_important, ParserInput, CowRcStr}; use cssparser::{Parser, AtRuleParser, DeclarationParser, Delimiter, ParseErrorKind}; use custom_properties::CustomPropertiesBuilder; use error_reporting::{ParseErrorReporter, ContextualParseError}; -use parser::{ParserContext, ParserErrorContext}; +use parser::ParserContext; use properties::animated_properties::AnimationValue; use shared_lock::Locked; use smallbitvec::{self, SmallBitVec}; @@ -1077,50 +1077,49 @@ where /// A helper to parse the style attribute of an element, in order for this to be /// shared between Servo and Gecko. -pub fn parse_style_attribute( +/// +/// Inline because we call this cross-crate. +#[inline] +pub fn parse_style_attribute( input: &str, url_data: &UrlExtraData, - error_reporter: &R, + error_reporter: Option<&ParseErrorReporter>, quirks_mode: QuirksMode, -) -> PropertyDeclarationBlock -where - R: ParseErrorReporter -{ +) -> PropertyDeclarationBlock { let context = ParserContext::new( Origin::Author, url_data, Some(CssRuleType::Style), ParsingMode::DEFAULT, quirks_mode, + error_reporter, ); - let error_context = ParserErrorContext { error_reporter: error_reporter }; let mut input = ParserInput::new(input); - parse_property_declaration_list(&context, &error_context, &mut Parser::new(&mut input)) + parse_property_declaration_list(&context, &mut Parser::new(&mut input)) } /// Parse a given property declaration. Can result in multiple /// `PropertyDeclaration`s when expanding a shorthand, for example. /// /// This does not attempt to parse !important at all. -pub fn parse_one_declaration_into( +#[inline] +pub fn parse_one_declaration_into( declarations: &mut SourcePropertyDeclaration, id: PropertyId, input: &str, url_data: &UrlExtraData, - error_reporter: &R, + error_reporter: Option<&ParseErrorReporter>, parsing_mode: ParsingMode, quirks_mode: QuirksMode -) -> Result<(), ()> -where - R: ParseErrorReporter -{ +) -> Result<(), ()> { let context = ParserContext::new( Origin::Author, url_data, Some(CssRuleType::Style), parsing_mode, quirks_mode, + error_reporter, ); let mut input = ParserInput::new(input); @@ -1131,9 +1130,10 @@ where }).map_err(|err| { let location = err.location; let error = ContextualParseError::UnsupportedPropertyDeclaration( - parser.slice_from(start_position), err); - let error_context = ParserErrorContext { error_reporter: error_reporter }; - context.log_css_error(&error_context, location, error); + parser.slice_from(start_position), + err, + ); + context.log_css_error(location, error); }) } @@ -1193,14 +1193,10 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for PropertyDeclarationParser<'a, 'b> { /// Parse a list of property declarations and return a property declaration /// block. -pub fn parse_property_declaration_list( +pub fn parse_property_declaration_list( context: &ParserContext, - error_context: &ParserErrorContext, input: &mut Parser, -) -> PropertyDeclarationBlock -where - R: ParseErrorReporter -{ +) -> PropertyDeclarationBlock { let mut declarations = SourcePropertyDeclaration::new(); let mut block = PropertyDeclarationBlock::new(); let parser = PropertyDeclarationParser { @@ -1228,7 +1224,7 @@ where let location = error.location; let error = ContextualParseError::UnsupportedPropertyDeclaration(slice, error); - context.log_css_error(error_context, location, error); + context.log_css_error(location, error); } } } diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 2ed1a4498b1..b6a8879e106 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1442,6 +1442,7 @@ impl UnparsedValue { None, ParsingMode::DEFAULT, quirks_mode, + None, ); let mut input = ParserInput::new(&css); diff --git a/components/style/stylesheets/font_feature_values_rule.rs b/components/style/stylesheets/font_feature_values_rule.rs index 71fa8227928..8ce16e2ccf9 100644 --- a/components/style/stylesheets/font_feature_values_rule.rs +++ b/components/style/stylesheets/font_feature_values_rule.rs @@ -10,12 +10,12 @@ use Atom; use cssparser::{AtRuleParser, AtRuleType, BasicParseErrorKind, CowRcStr}; use cssparser::{DeclarationListParser, DeclarationParser, Parser}; use cssparser::{QualifiedRuleParser, RuleListParser, SourceLocation, Token}; -use error_reporting::{ContextualParseError, ParseErrorReporter}; +use error_reporting::ContextualParseError; #[cfg(feature = "gecko")] use gecko_bindings::bindings::Gecko_AppendFeatureValueHashEntry; #[cfg(feature = "gecko")] use gecko_bindings::structs::{self, gfxFontFeatureValueSet, nsTArray}; -use parser::{Parse, ParserContext, ParserErrorContext}; +use parser::{Parse, ParserContext}; use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard}; use std::fmt::{self, Write}; use str::CssStringWriter; @@ -267,27 +267,24 @@ macro_rules! font_feature_values_blocks { } /// Parses a `FontFeatureValuesRule`. - pub fn parse(context: &ParserContext, - error_context: &ParserErrorContext, - input: &mut Parser, - family_names: Vec, - location: SourceLocation) - -> FontFeatureValuesRule - where R: ParseErrorReporter - { + pub fn parse( + context: &ParserContext, + input: &mut Parser, + family_names: Vec, + location: SourceLocation, + ) -> Self { let mut rule = FontFeatureValuesRule::new(family_names, location); { let mut iter = RuleListParser::new_for_nested_rule(input, FontFeatureValuesRuleParser { context: context, - error_context: error_context, rule: &mut rule, }); while let Some(result) = iter.next() { if let Err((error, slice)) = result { let location = error.location; let error = ContextualParseError::UnsupportedRule(slice, error); - context.log_css_error(error_context, location, error); + context.log_css_error(location, error); } } } @@ -398,20 +395,19 @@ macro_rules! font_feature_values_blocks { /// } /// = @stylistic | @historical-forms | @styleset | /// @character-variant | @swash | @ornaments | @annotation - struct FontFeatureValuesRuleParser<'a, R: 'a> { + struct FontFeatureValuesRuleParser<'a> { context: &'a ParserContext<'a>, - error_context: &'a ParserErrorContext<'a, R>, rule: &'a mut FontFeatureValuesRule, } /// Default methods reject all qualified rules. - impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for FontFeatureValuesRuleParser<'a, R> { + impl<'a, 'i> QualifiedRuleParser<'i> for FontFeatureValuesRuleParser<'a> { type Prelude = (); type QualifiedRule = (); type Error = StyleParseErrorKind<'i>; } - impl<'a, 'i, R: ParseErrorReporter> AtRuleParser<'i> for FontFeatureValuesRuleParser<'a, R> { + impl<'a, 'i> AtRuleParser<'i> for FontFeatureValuesRuleParser<'a> { type PreludeNoBlock = (); type PreludeBlock = BlockType; type AtRule = (); @@ -450,7 +446,7 @@ macro_rules! font_feature_values_blocks { let error = ContextualParseError::UnsupportedKeyframePropertyDeclaration( slice, error ); - self.context.log_css_error(self.error_context, location, error); + self.context.log_css_error(location, error); } } }, diff --git a/components/style/stylesheets/keyframes_rule.rs b/components/style/stylesheets/keyframes_rule.rs index 5f39267ac7b..a0cb5fa0b1d 100644 --- a/components/style/stylesheets/keyframes_rule.rs +++ b/components/style/stylesheets/keyframes_rule.rs @@ -6,8 +6,8 @@ use cssparser::{AtRuleParser, CowRcStr, Parser, ParserInput, QualifiedRuleParser, RuleListParser}; use cssparser::{parse_one_rule, DeclarationListParser, DeclarationParser, SourceLocation, Token}; -use error_reporting::{ContextualParseError, NullReporter, ParseErrorReporter}; -use parser::{ParserContext, ParserErrorContext}; +use error_reporting::ContextualParseError; +use parser::ParserContext; use properties::{DeclarationSource, Importance, PropertyDeclaration}; use properties::{LonghandId, PropertyDeclarationBlock, PropertyId}; use properties::{PropertyDeclarationId, SourcePropertyDeclaration}; @@ -211,7 +211,6 @@ impl Keyframe { lock: &SharedRwLock, ) -> Result>, ParseError<'i>> { let url_data = parent_stylesheet_contents.url_data.read(); - let error_reporter = NullReporter; let namespaces = parent_stylesheet_contents.namespaces.read(); let mut context = ParserContext::new( parent_stylesheet_contents.origin, @@ -219,10 +218,8 @@ impl Keyframe { Some(CssRuleType::Keyframe), ParsingMode::DEFAULT, parent_stylesheet_contents.quirks_mode, + None, ); - let error_context = ParserErrorContext { - error_reporter: &error_reporter, - }; context.namespaces = Some(&*namespaces); let mut input = ParserInput::new(css); let mut input = Parser::new(&mut input); @@ -230,7 +227,6 @@ impl Keyframe { let mut declarations = SourcePropertyDeclaration::new(); let mut rule_parser = KeyframeListParser { context: &context, - error_context: &error_context, shared_lock: &lock, declarations: &mut declarations, }; @@ -477,23 +473,18 @@ impl KeyframesAnimation { /// 40%, 60%, 100% { /// width: 100%; /// } -struct KeyframeListParser<'a, R: 'a> { +struct KeyframeListParser<'a> { context: &'a ParserContext<'a>, - error_context: &'a ParserErrorContext<'a, R>, shared_lock: &'a SharedRwLock, declarations: &'a mut SourcePropertyDeclaration, } /// Parses a keyframe list from CSS input. -pub fn parse_keyframe_list( +pub fn parse_keyframe_list( context: &ParserContext, - error_context: &ParserErrorContext, input: &mut Parser, shared_lock: &SharedRwLock, -) -> Vec>> -where - R: ParseErrorReporter, -{ +) -> Vec>> { debug_assert!( context.namespaces.is_some(), "Parsing a keyframe list from a context without namespaces?" @@ -504,7 +495,6 @@ where input, KeyframeListParser { context: context, - error_context: error_context, shared_lock: shared_lock, declarations: &mut declarations, }, @@ -512,7 +502,7 @@ where .collect() } -impl<'a, 'i, R> AtRuleParser<'i> for KeyframeListParser<'a, R> { +impl<'a, 'i> AtRuleParser<'i> for KeyframeListParser<'a> { type PreludeNoBlock = (); type PreludeBlock = (); type AtRule = Arc>; @@ -525,7 +515,7 @@ struct KeyframeSelectorParserPrelude { source_location: SourceLocation, } -impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for KeyframeListParser<'a, R> { +impl<'a, 'i> QualifiedRuleParser<'i> for KeyframeListParser<'a> { type Prelude = KeyframeSelectorParserPrelude; type QualifiedRule = Arc>; type Error = StyleParseErrorKind<'i>; @@ -547,8 +537,7 @@ impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for KeyframeListPars input.slice_from(start_position), e.clone(), ); - self.context - .log_css_error(self.error_context, location, error); + self.context.log_css_error(location, error); Err(e) }, } @@ -585,7 +574,7 @@ impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for KeyframeListPars let location = error.location; let error = ContextualParseError::UnsupportedKeyframePropertyDeclaration(slice, error); - context.log_css_error(self.error_context, location, error); + context.log_css_error(location, error); }, } // `parse_important` is not called here, `!important` is not allowed in keyframe blocks. diff --git a/components/style/stylesheets/mod.rs b/components/style/stylesheets/mod.rs index 2d6539c08b4..0a9e5fdb9e2 100644 --- a/components/style/stylesheets/mod.rs +++ b/components/style/stylesheets/mod.rs @@ -24,10 +24,9 @@ pub mod supports_rule; pub mod viewport_rule; use cssparser::{parse_one_rule, Parser, ParserInput}; -use error_reporting::NullReporter; #[cfg(feature = "gecko")] use malloc_size_of::{MallocSizeOfOps, MallocUnconditionalShallowSizeOf}; -use parser::{ParserContext, ParserErrorContext}; +use parser::ParserContext; use servo_arc::Arc; use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked}; use shared_lock::{SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard}; @@ -228,13 +227,13 @@ impl CssRule { loader: Option<&StylesheetLoader>, ) -> Result { let url_data = parent_stylesheet_contents.url_data.read(); - let error_reporter = NullReporter; let context = ParserContext::new( parent_stylesheet_contents.origin, &url_data, None, ParsingMode::DEFAULT, parent_stylesheet_contents.quirks_mode, + None, ); let mut input = ParserInput::new(css); @@ -246,9 +245,6 @@ impl CssRule { let mut rule_parser = TopLevelRuleParser { stylesheet_origin: parent_stylesheet_contents.origin, context, - error_context: ParserErrorContext { - error_reporter: &error_reporter, - }, shared_lock: &shared_lock, loader, state, diff --git a/components/style/stylesheets/rule_parser.rs b/components/style/stylesheets/rule_parser.rs index 259130dd89b..41d87aa07a4 100644 --- a/components/style/stylesheets/rule_parser.rs +++ b/components/style/stylesheets/rule_parser.rs @@ -8,10 +8,10 @@ use {Namespace, Prefix}; use counter_style::{parse_counter_style_body, parse_counter_style_name_definition}; use cssparser::{AtRuleParser, AtRuleType, Parser, QualifiedRuleParser, RuleListParser}; use cssparser::{BasicParseError, BasicParseErrorKind, CowRcStr, SourceLocation}; -use error_reporting::{ContextualParseError, ParseErrorReporter}; +use error_reporting::ContextualParseError; use font_face::parse_font_face_block; use media_queries::MediaList; -use parser::{Parse, ParserContext, ParserErrorContext}; +use parser::{Parse, ParserContext}; use properties::parse_property_declaration_list; use selector_parser::{SelectorImpl, SelectorParser}; use selectors::SelectorList; @@ -40,7 +40,7 @@ pub struct InsertRuleContext<'a> { } /// The parser for the top-level rules in a stylesheet. -pub struct TopLevelRuleParser<'a, R: 'a> { +pub struct TopLevelRuleParser<'a> { /// The origin of the stylesheet we're parsing. pub stylesheet_origin: Origin, /// A reference to the lock we need to use to create rules. @@ -52,8 +52,6 @@ pub struct TopLevelRuleParser<'a, R: 'a> { /// This won't contain any namespaces, and only nested parsers created with /// `ParserContext::new_with_rule_type` will. pub context: ParserContext<'a>, - /// The context required for reporting parse errors. - pub error_context: ParserErrorContext<'a, R>, /// The current state of the parser. pub state: State, /// Whether we have tried to parse was invalid due to being in the wrong @@ -68,13 +66,12 @@ pub struct TopLevelRuleParser<'a, R: 'a> { pub insert_rule_context: Option>, } -impl<'b, R> TopLevelRuleParser<'b, R> { - fn nested<'a: 'b>(&'a self) -> NestedRuleParser<'a, 'b, R> { +impl<'b> TopLevelRuleParser<'b> { + fn nested<'a: 'b>(&'a self) -> NestedRuleParser<'a, 'b> { NestedRuleParser { stylesheet_origin: self.stylesheet_origin, shared_lock: self.shared_lock, context: &self.context, - error_context: &self.error_context, namespaces: &self.namespaces, } } @@ -176,7 +173,7 @@ pub enum AtRuleNonBlockPrelude { Namespace(Option, Namespace, SourceLocation), } -impl<'a, 'i, R: ParseErrorReporter> AtRuleParser<'i> for TopLevelRuleParser<'a, R> { +impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> { type PreludeNoBlock = AtRuleNonBlockPrelude; type PreludeBlock = AtRuleBlockPrelude; type AtRule = CssRule; @@ -197,11 +194,7 @@ impl<'a, 'i, R: ParseErrorReporter> AtRuleParser<'i> for TopLevelRuleParser<'a, let url_string = input.expect_url_or_string()?.as_ref().to_owned(); let url = CssUrl::parse_from_string(url_string, &self.context); - let media = MediaList::parse( - &self.context, - input, - self.error_context.error_reporter, - ); + let media = MediaList::parse(&self.context, input); let media = Arc::new(self.shared_lock.wrap(media)); let prelude = AtRuleNonBlockPrelude::Import(url, media, location); @@ -296,7 +289,7 @@ pub struct QualifiedRuleParserPrelude { source_location: SourceLocation, } -impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for TopLevelRuleParser<'a, R> { +impl<'a, 'i> QualifiedRuleParser<'i> for TopLevelRuleParser<'a> { type Prelude = QualifiedRuleParserPrelude; type QualifiedRule = CssRule; type Error = StyleParseErrorKind<'i>; @@ -327,27 +320,29 @@ impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for TopLevelRulePars } #[derive(Clone)] // shallow, relatively cheap .clone -struct NestedRuleParser<'a, 'b: 'a, R: 'b> { +struct NestedRuleParser<'a, 'b: 'a> { stylesheet_origin: Origin, shared_lock: &'a SharedRwLock, context: &'a ParserContext<'b>, - error_context: &'a ParserErrorContext<'b, R>, namespaces: &'a Namespaces, } -impl<'a, 'b, R: ParseErrorReporter> NestedRuleParser<'a, 'b, R> { +impl<'a, 'b> NestedRuleParser<'a, 'b> { fn parse_nested_rules( &mut self, input: &mut Parser, rule_type: CssRuleType, ) -> Arc> { - let context = ParserContext::new_with_rule_type(self.context, rule_type, self.namespaces); + let context = ParserContext::new_with_rule_type( + self.context, + rule_type, + self.namespaces, + ); let nested_parser = NestedRuleParser { stylesheet_origin: self.stylesheet_origin, shared_lock: self.shared_lock, context: &context, - error_context: &self.error_context, namespaces: self.namespaces, }; @@ -359,8 +354,7 @@ impl<'a, 'b, R: ParseErrorReporter> NestedRuleParser<'a, 'b, R> { Err((error, slice)) => { let location = error.location; let error = ContextualParseError::InvalidRule(slice, error); - self.context - .log_css_error(self.error_context, location, error); + self.context.log_css_error(location, error); }, } } @@ -368,7 +362,7 @@ impl<'a, 'b, R: ParseErrorReporter> NestedRuleParser<'a, 'b, R> { } } -impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a, 'b, R> { +impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> { type PreludeNoBlock = AtRuleNonBlockPrelude; type PreludeBlock = AtRuleBlockPrelude; type AtRule = CssRule; @@ -383,11 +377,7 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a match_ignore_ascii_case! { &*name, "media" => { - let media_queries = MediaList::parse( - self.context, - input, - self.error_context.error_reporter, - ); + let media_queries = MediaList::parse(self.context, input); let arc = Arc::new(self.shared_lock.wrap(media_queries)); Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::Media(arc, location))) }, @@ -473,7 +463,7 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a ); Ok(CssRule::FontFace(Arc::new(self.shared_lock.wrap( - parse_font_face_block(&context, self.error_context, input, location).into(), + parse_font_face_block(&context, input, location).into(), )))) }, AtRuleBlockPrelude::FontFeatureValues(family_names, location) => { @@ -486,7 +476,6 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a Ok(CssRule::FontFeatureValues(Arc::new(self.shared_lock.wrap( FontFeatureValuesRule::parse( &context, - self.error_context, input, family_names, location, @@ -505,7 +494,6 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a parse_counter_style_body( name, &context, - self.error_context, input, location, )?.into(), @@ -544,7 +532,7 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a ); Ok(CssRule::Viewport(Arc::new(self.shared_lock.wrap( - ViewportRule::parse(&context, self.error_context, input)?, + ViewportRule::parse(&context, input)?, )))) }, AtRuleBlockPrelude::Keyframes(name, vendor_prefix, source_location) => { @@ -559,7 +547,6 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a name, keyframes: parse_keyframe_list( &context, - self.error_context, input, self.shared_lock, ), @@ -576,7 +563,7 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a ); let declarations = - parse_property_declaration_list(&context, self.error_context, input); + parse_property_declaration_list(&context, input); Ok(CssRule::Page(Arc::new(self.shared_lock.wrap(PageRule { block: Arc::new(self.shared_lock.wrap(declarations)), source_location, @@ -598,7 +585,7 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a } } -impl<'a, 'b, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for NestedRuleParser<'a, 'b, R> { +impl<'a, 'b, 'i> QualifiedRuleParser<'i> for NestedRuleParser<'a, 'b> { type Prelude = QualifiedRuleParserPrelude; type QualifiedRule = CssRule; type Error = StyleParseErrorKind<'i>; @@ -627,7 +614,7 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for NestedRulePa let context = ParserContext::new_with_rule_type(self.context, CssRuleType::Style, self.namespaces); - let declarations = parse_property_declaration_list(&context, self.error_context, input); + let declarations = parse_property_declaration_list(&context, input); Ok(CssRule::Style(Arc::new(self.shared_lock.wrap(StyleRule { selectors: prelude.selectors, block: Arc::new(self.shared_lock.wrap(declarations)), diff --git a/components/style/stylesheets/stylesheet.rs b/components/style/stylesheets/stylesheet.rs index b33875a149c..5312826bd29 100644 --- a/components/style/stylesheets/stylesheet.rs +++ b/components/style/stylesheets/stylesheet.rs @@ -13,7 +13,7 @@ use invalidation::media_queries::{MediaListKey, ToMediaListKey}; use malloc_size_of::{MallocSizeOfOps, MallocUnconditionalShallowSizeOf}; use media_queries::{Device, MediaList}; use parking_lot::RwLock; -use parser::{ParserContext, ParserErrorContext}; +use parser::ParserContext; use servo_arc::Arc; use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard}; use std::mem; @@ -69,13 +69,13 @@ pub struct StylesheetContents { impl StylesheetContents { /// Parse a given CSS string, with a given url-data, origin, and /// quirks mode. - pub fn from_str( + pub fn from_str( css: &str, url_data: UrlExtraData, origin: Origin, shared_lock: &SharedRwLock, stylesheet_loader: Option<&StylesheetLoader>, - error_reporter: &R, + error_reporter: Option<&ParseErrorReporter>, quirks_mode: QuirksMode, line_number_offset: u32, ) -> Self { @@ -306,18 +306,16 @@ impl StylesheetInDocument for DocumentStyleSheet { impl Stylesheet { /// Updates an empty stylesheet from a given string of text. - pub fn update_from_str( + pub fn update_from_str( existing: &Stylesheet, css: &str, url_data: UrlExtraData, stylesheet_loader: Option<&StylesheetLoader>, - error_reporter: &R, + error_reporter: Option<&ParseErrorReporter>, line_number_offset: u32, - ) where - R: ParseErrorReporter, - { + ) { let namespaces = RwLock::new(Namespaces::default()); - let (rules, source_map_url, source_url) = Stylesheet::parse_rules( + let (rules, source_map_url, source_url) = Self::parse_rules( css, &url_data, existing.contents.origin, @@ -342,14 +340,14 @@ impl Stylesheet { *existing.contents.source_url.write() = source_url; } - fn parse_rules( + fn parse_rules( css: &str, url_data: &UrlExtraData, origin: Origin, namespaces: &mut Namespaces, shared_lock: &SharedRwLock, stylesheet_loader: Option<&StylesheetLoader>, - error_reporter: &R, + error_reporter: Option<&ParseErrorReporter>, quirks_mode: QuirksMode, line_number_offset: u32, ) -> (Vec, Option, Option) { @@ -357,16 +355,20 @@ impl Stylesheet { let mut input = ParserInput::new_with_line_number_offset(css, line_number_offset); let mut input = Parser::new(&mut input); - let context = ParserContext::new(origin, url_data, None, ParsingMode::DEFAULT, quirks_mode); - - let error_context = ParserErrorContext { error_reporter }; + let context = ParserContext::new( + origin, + url_data, + None, + ParsingMode::DEFAULT, + quirks_mode, + error_reporter, + ); let rule_parser = TopLevelRuleParser { stylesheet_origin: origin, shared_lock, loader: stylesheet_loader, context, - error_context, state: State::Start, dom_error: None, insert_rule_context: None, @@ -390,7 +392,6 @@ impl Stylesheet { let location = error.location; let error = ContextualParseError::InvalidRule(slice, error); iter.parser.context.log_css_error( - &iter.parser.error_context, location, error, ); @@ -409,17 +410,17 @@ impl Stylesheet { /// /// Effectively creates a new stylesheet and forwards the hard work to /// `Stylesheet::update_from_str`. - pub fn from_str( + pub fn from_str( css: &str, url_data: UrlExtraData, origin: Origin, media: Arc>, shared_lock: SharedRwLock, stylesheet_loader: Option<&StylesheetLoader>, - error_reporter: &R, + error_reporter: Option<&ParseErrorReporter>, quirks_mode: QuirksMode, line_number_offset: u32, - ) -> Stylesheet { + ) -> Self { let contents = StylesheetContents::from_str( css, url_data, diff --git a/components/style/stylesheets/viewport_rule.rs b/components/style/stylesheets/viewport_rule.rs index b159b65d35b..1fc6a988c7c 100644 --- a/components/style/stylesheets/viewport_rule.rs +++ b/components/style/stylesheets/viewport_rule.rs @@ -11,11 +11,11 @@ use app_units::Au; use context::QuirksMode; use cssparser::{parse_important, AtRuleParser, DeclarationListParser, DeclarationParser, Parser}; use cssparser::CowRcStr; -use error_reporting::{ContextualParseError, ParseErrorReporter}; +use error_reporting::ContextualParseError; use euclid::TypedSize2D; use font_metrics::get_metrics_provider_for_product; use media_queries::Device; -use parser::{ParserContext, ParserErrorContext}; +use parser::ParserContext; use properties::StyleBuilder; use rule_cache::RuleCacheConditions; use selectors::parser::SelectorParseErrorKind; @@ -355,15 +355,13 @@ fn is_whitespace_separator_or_equals(c: &char) -> bool { impl ViewportRule { /// Parse a single @viewport rule. - pub fn parse<'i, 't, R>( + /// + /// TODO(emilio): This could use the `Parse` trait now. + pub fn parse<'i, 't>( context: &ParserContext, - error_context: &ParserErrorContext, input: &mut Parser<'i, 't>, - ) -> Result> - where - R: ParseErrorReporter, - { - let parser = ViewportRuleParser { context: context }; + ) -> Result> { + let parser = ViewportRuleParser { context }; let mut cascade = Cascade::new(); let mut parser = DeclarationListParser::new(input, parser); @@ -380,7 +378,7 @@ impl ViewportRule { slice, error, ); - context.log_css_error(error_context, location, error); + context.log_css_error(location, error); }, } }