mirror of
https://github.com/servo/servo.git
synced 2025-10-04 02:29:12 +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
|
@ -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<R: ParseErrorReporter>(
|
||||
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<R>(
|
||||
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<R: ParseErrorReporter>(
|
||||
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<CssRule>, Option<String>, Option<String>) {
|
||||
|
@ -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<R: ParseErrorReporter>(
|
||||
pub fn from_str(
|
||||
css: &str,
|
||||
url_data: UrlExtraData,
|
||||
origin: Origin,
|
||||
media: Arc<Locked<MediaList>>,
|
||||
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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue