aboutsummaryrefslogtreecommitdiffstats
path: root/components/style/parser.rs
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2018-06-20 21:07:45 +0200
committerEmilio Cobos Álvarez <emilio@crisal.io>2018-06-23 20:36:23 +0200
commit3a0c3224b96b578f4e577c905c38e06ed1c11e52 (patch)
tree147cf50d92f2dd9383c69666e1f3e93cd496db02 /components/style/parser.rs
parentbab7be63b2ed72165435cd125a6b7d92f71f316c (diff)
downloadservo-3a0c3224b96b578f4e577c905c38e06ed1c11e52.tar.gz
servo-3a0c3224b96b578f4e577c905c38e06ed1c11e52.zip
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
Diffstat (limited to 'components/style/parser.rs')
-rw-r--r--components/style/parser.rs31
1 files changed, 14 insertions, 17 deletions
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<CssRuleType>,
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<CssRuleType>,
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<R>(
+ pub fn log_css_error(
&self,
- context: &ParserErrorContext<R>,
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.