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:
Emilio Cobos Álvarez 2018-06-20 21:07:45 +02:00
parent bab7be63b2
commit 3a0c3224b9
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
13 changed files with 128 additions and 194 deletions

View file

@ -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<R>,
input: &mut Parser<'i, 't>,
location: SourceLocation,
) -> Result<CounterStyleRuleData, ParseError<'i>>
where
R: ParseErrorReporter,
{
) -> Result<CounterStyleRuleData, ParseError<'i>> {
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)