mirror of
https://github.com/servo/servo.git
synced 2025-08-11 08:25:32 +01:00
style: Move the error reporter into ParserContext.
Summary: This should make it easier to report errors, and also reduce codesize. The reason this was so generic is that error reporting was unconditionally enabled and was super-hot, but now that's no longer the case after bug 1452143, so we can afford the virtual call in the "error reporting enabled" case. This opens the possibility of simplifying a lot the error setup as well, though this patch doesn't do it. Test Plan: No behavior change, so no new tests. Reviewers: xidorn Bug #: 1469957 Differential Revision: https://phabricator.services.mozilla.com/D1734 MozReview-Commit-ID: F3wTdhX9MB5
This commit is contained in:
parent
bab7be63b2
commit
3a0c3224b9
13 changed files with 128 additions and 194 deletions
|
@ -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<Arc<Locked<Self>>, 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<R>(
|
||||
pub fn parse_keyframe_list(
|
||||
context: &ParserContext,
|
||||
error_context: &ParserErrorContext<R>,
|
||||
input: &mut Parser,
|
||||
shared_lock: &SharedRwLock,
|
||||
) -> Vec<Arc<Locked<Keyframe>>>
|
||||
where
|
||||
R: ParseErrorReporter,
|
||||
{
|
||||
) -> Vec<Arc<Locked<Keyframe>>> {
|
||||
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<Locked<Keyframe>>;
|
||||
|
@ -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<Locked<Keyframe>>;
|
||||
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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue