mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 07:15:46 +00:00
Bug 1469957: Move the error reporter into ParserContext. r=xidorn
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
95c7df13d3
commit
621ad1408b
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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<R>(
|
||||
pub fn parse_font_face_block(
|
||||
context: &ParserContext,
|
||||
error_context: &ParserErrorContext<R>,
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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:
|
||||
///
|
||||
/// <https://drafts.csswg.org/mediaqueries/#error-handling>
|
||||
pub fn parse<R>(
|
||||
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);
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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<R>(
|
||||
///
|
||||
/// 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<R>(
|
||||
#[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<R>(
|
||||
pub fn parse_property_declaration_list(
|
||||
context: &ParserContext,
|
||||
error_context: &ParserErrorContext<R>,
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1442,6 +1442,7 @@ impl UnparsedValue {
|
||||
None,
|
||||
ParsingMode::DEFAULT,
|
||||
quirks_mode,
|
||||
None,
|
||||
);
|
||||
|
||||
let mut input = ParserInput::new(&css);
|
||||
|
@ -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<R>(context: &ParserContext,
|
||||
error_context: &ParserErrorContext<R>,
|
||||
input: &mut Parser,
|
||||
family_names: Vec<FamilyName>,
|
||||
location: SourceLocation)
|
||||
-> FontFeatureValuesRule
|
||||
where R: ParseErrorReporter
|
||||
{
|
||||
pub fn parse(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser,
|
||||
family_names: Vec<FamilyName>,
|
||||
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 {
|
||||
/// }
|
||||
/// <feature-type> = @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);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -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.
|
||||
|
@ -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<Self, RulesMutateError> {
|
||||
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,
|
||||
|
@ -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<InsertRuleContext<'a>>,
|
||||
}
|
||||
|
||||
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<Prefix>, 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<Locked<CssRules>> {
|
||||
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)),
|
||||
|
@ -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,
|
||||
|
@ -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<R>,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>>
|
||||
where
|
||||
R: ParseErrorReporter,
|
||||
{
|
||||
let parser = ViewportRuleParser { context: context };
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
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);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@
|
||||
use cssparser::{CowRcStr, serialize_identifier, ToCss};
|
||||
use cssparser::{SourceLocation, ParseError, ParseErrorKind, Token, BasicParseErrorKind};
|
||||
use selectors::parser::SelectorParseErrorKind;
|
||||
use std::cell::Cell;
|
||||
use std::ffi::CStr;
|
||||
use std::ptr;
|
||||
use style::error_reporting::{ParseErrorReporter, ContextualParseError};
|
||||
@ -26,28 +25,31 @@ pub struct ErrorReporter {
|
||||
sheet: *const DomStyleSheet,
|
||||
loader: *const Loader,
|
||||
uri: *mut nsIURI,
|
||||
cached_error_reporting_enabled: Cell<Option<bool>>,
|
||||
}
|
||||
|
||||
impl ErrorReporter {
|
||||
/// Create a new instance of the Gecko error reporter.
|
||||
/// Create a new instance of the Gecko error reporter, if error reporting is
|
||||
/// enabled.
|
||||
pub fn new(
|
||||
sheet: *mut DomStyleSheet,
|
||||
loader: *mut Loader,
|
||||
extra_data: *mut RawUrlExtraData,
|
||||
) -> Self {
|
||||
) -> Option<Self> {
|
||||
if !Self::reporting_enabled(sheet, loader) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let uri = unsafe {
|
||||
extra_data.as_ref()
|
||||
.map(|d| d.mBaseURI.raw::<nsIURI>())
|
||||
.unwrap_or(ptr::null_mut())
|
||||
};
|
||||
|
||||
ErrorReporter {
|
||||
Some(ErrorReporter {
|
||||
sheet,
|
||||
loader,
|
||||
uri,
|
||||
cached_error_reporting_enabled: Cell::new(None),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -393,21 +395,15 @@ impl<'a> ErrorHelpers<'a> for ContextualParseError<'a> {
|
||||
}
|
||||
|
||||
impl ErrorReporter {
|
||||
fn reporting_enabled(&self) -> bool {
|
||||
if let Some(enabled) = self.cached_error_reporting_enabled.get() {
|
||||
return enabled;
|
||||
}
|
||||
let enabled = unsafe {
|
||||
bindings::Gecko_ErrorReportingEnabled(self.sheet, self.loader)
|
||||
};
|
||||
self.cached_error_reporting_enabled.set(Some(enabled));
|
||||
enabled
|
||||
fn reporting_enabled(
|
||||
sheet: *const DomStyleSheet,
|
||||
loader: *const Loader,
|
||||
) -> bool {
|
||||
unsafe { bindings::Gecko_ErrorReportingEnabled(sheet, loader) }
|
||||
}
|
||||
|
||||
pub fn report(&self, location: SourceLocation, error: ContextualParseError) {
|
||||
if !self.reporting_enabled() {
|
||||
return;
|
||||
}
|
||||
debug_assert!(Self::reporting_enabled(self.sheet, self.loader));
|
||||
|
||||
let (pre, name, action) = error.to_gecko_message();
|
||||
let suffix = match action {
|
||||
|
@ -26,7 +26,7 @@ use style::data::{ElementStyles, self};
|
||||
use style::dom::{ShowSubtreeData, TDocument, TElement, TNode};
|
||||
use style::driver;
|
||||
use style::element_state::{DocumentState, ElementState};
|
||||
use style::error_reporting::{ContextualParseError, NullReporter, ParseErrorReporter};
|
||||
use style::error_reporting::{ContextualParseError, ParseErrorReporter};
|
||||
use style::font_metrics::{FontMetricsProvider, get_metrics_provider_for_product};
|
||||
use style::gecko::data::{GeckoStyleSheet, PerDocumentStyleData, PerDocumentStyleDataImpl};
|
||||
use style::gecko::global_style_data::{GLOBAL_STYLE_DATA, GlobalStyleData, STYLE_THREAD_POOL};
|
||||
@ -1155,7 +1155,7 @@ pub extern "C" fn Servo_StyleSheet_Empty(mode: SheetParsingMode) -> RawServoStyl
|
||||
origin,
|
||||
shared_lock,
|
||||
/* loader = */ None,
|
||||
&NullReporter,
|
||||
None,
|
||||
QuirksMode::NoQuirks,
|
||||
0
|
||||
)
|
||||
@ -1196,10 +1196,15 @@ pub extern "C" fn Servo_StyleSheet_FromUTF8Bytes(
|
||||
|
||||
|
||||
Arc::new(StylesheetContents::from_str(
|
||||
input, url_data.clone(), mode_to_origin(mode),
|
||||
&global_style_data.shared_lock, loader, &reporter,
|
||||
quirks_mode.into(), line_number_offset)
|
||||
).into_strong()
|
||||
input,
|
||||
url_data.clone(),
|
||||
mode_to_origin(mode),
|
||||
&global_style_data.shared_lock,
|
||||
loader,
|
||||
reporter.as_ref().map(|r| r as &ParseErrorReporter),
|
||||
quirks_mode.into(),
|
||||
line_number_offset,
|
||||
)).into_strong()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@ -2515,6 +2520,7 @@ pub unsafe extern "C" fn Servo_FontFaceRule_SetDescriptor(
|
||||
Some(CssRuleType::FontFace),
|
||||
ParsingMode::DEFAULT,
|
||||
QuirksMode::NoQuirks,
|
||||
None,
|
||||
);
|
||||
|
||||
write_locked_arc(rule, |rule: &mut FontFaceRule| {
|
||||
@ -2724,6 +2730,7 @@ macro_rules! counter_style_descriptors {
|
||||
Some(CssRuleType::CounterStyle),
|
||||
ParsingMode::DEFAULT,
|
||||
QuirksMode::NoQuirks,
|
||||
None,
|
||||
);
|
||||
|
||||
write_locked_arc(rule, |rule: &mut CounterStyleRule| {
|
||||
@ -3206,18 +3213,15 @@ pub unsafe extern "C" fn Servo_StyleSet_CompatModeChanged(raw_data: RawServoStyl
|
||||
data.stylist.set_quirks_mode(QuirksMode::from(doc.mCompatMode));
|
||||
}
|
||||
|
||||
fn parse_property_into<R>(
|
||||
fn parse_property_into(
|
||||
declarations: &mut SourcePropertyDeclaration,
|
||||
property_id: PropertyId,
|
||||
value: *const nsACString,
|
||||
data: *mut URLExtraData,
|
||||
parsing_mode: structs::ParsingMode,
|
||||
quirks_mode: QuirksMode,
|
||||
reporter: &R
|
||||
) -> Result<(), ()>
|
||||
where
|
||||
R: ParseErrorReporter
|
||||
{
|
||||
reporter: Option<&ParseErrorReporter>,
|
||||
) -> Result<(), ()> {
|
||||
use style_traits::ParsingMode;
|
||||
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
|
||||
let url_data = unsafe { RefPtr::from_ptr_ref(&data) };
|
||||
@ -3246,8 +3250,17 @@ pub extern "C" fn Servo_ParseProperty(
|
||||
RawServoDeclarationBlockStrong::null());
|
||||
let mut declarations = SourcePropertyDeclaration::new();
|
||||
let reporter = ErrorReporter::new(ptr::null_mut(), loader, data);
|
||||
match parse_property_into(&mut declarations, id, value, data,
|
||||
parsing_mode, quirks_mode.into(), &reporter) {
|
||||
let result = parse_property_into(
|
||||
&mut declarations,
|
||||
id,
|
||||
value,
|
||||
data,
|
||||
parsing_mode,
|
||||
quirks_mode.into(),
|
||||
reporter.as_ref().map(|r| r as &ParseErrorReporter),
|
||||
);
|
||||
|
||||
match result {
|
||||
Ok(()) => {
|
||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||
let mut block = PropertyDeclarationBlock::new();
|
||||
@ -3278,6 +3291,7 @@ pub extern "C" fn Servo_ParseEasing(
|
||||
Some(CssRuleType::Style),
|
||||
ParsingMode::DEFAULT,
|
||||
QuirksMode::NoQuirks,
|
||||
None,
|
||||
);
|
||||
let easing = unsafe { (*easing).to_string() };
|
||||
let mut input = ParserInput::new(&easing);
|
||||
@ -3368,7 +3382,7 @@ pub extern "C" fn Servo_ParseStyleAttribute(
|
||||
parse_style_attribute(
|
||||
value,
|
||||
url_data,
|
||||
&reporter,
|
||||
reporter.as_ref().map(|r| r as &ParseErrorReporter),
|
||||
quirks_mode.into(),
|
||||
)
|
||||
)).into_strong()
|
||||
@ -3553,7 +3567,7 @@ fn set_property(
|
||||
data,
|
||||
parsing_mode,
|
||||
quirks_mode,
|
||||
&reporter,
|
||||
reporter.as_ref().map(|r| r as &ParseErrorReporter),
|
||||
);
|
||||
|
||||
if result.is_err() {
|
||||
@ -3757,14 +3771,12 @@ pub unsafe extern "C" fn Servo_MediaList_SetText(
|
||||
Some(CssRuleType::Media),
|
||||
ParsingMode::DEFAULT,
|
||||
QuirksMode::NoQuirks,
|
||||
// TODO(emilio): Looks like error reporting could be useful here?
|
||||
None,
|
||||
);
|
||||
|
||||
write_locked_arc(list, |list: &mut MediaList| {
|
||||
*list = MediaList::parse(
|
||||
&context,
|
||||
&mut parser,
|
||||
&NullReporter,
|
||||
);
|
||||
*list = MediaList::parse(&context, &mut parser);
|
||||
})
|
||||
}
|
||||
|
||||
@ -3801,6 +3813,7 @@ pub extern "C" fn Servo_MediaList_AppendMedium(
|
||||
Some(CssRuleType::Media),
|
||||
ParsingMode::DEFAULT,
|
||||
QuirksMode::NoQuirks,
|
||||
None,
|
||||
);
|
||||
write_locked_arc(list, |list: &mut MediaList| {
|
||||
list.append_medium(&context, new_medium);
|
||||
@ -3819,6 +3832,7 @@ pub extern "C" fn Servo_MediaList_DeleteMedium(
|
||||
Some(CssRuleType::Media),
|
||||
ParsingMode::DEFAULT,
|
||||
QuirksMode::NoQuirks,
|
||||
None,
|
||||
);
|
||||
write_locked_arc(list, |list: &mut MediaList| list.delete_medium(&context, old_medium))
|
||||
}
|
||||
@ -4210,6 +4224,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetBackgroundImage(
|
||||
Some(CssRuleType::Style),
|
||||
ParsingMode::DEFAULT,
|
||||
QuirksMode::NoQuirks,
|
||||
None,
|
||||
);
|
||||
let url = SpecifiedImageUrl::parse_from_string(string.into(), &context);
|
||||
let decl = PropertyDeclaration::BackgroundImage(BackgroundImage(
|
||||
@ -4250,7 +4265,7 @@ pub unsafe extern "C" fn Servo_CSSSupports2(
|
||||
DUMMY_URL_DATA,
|
||||
structs::ParsingMode_Default,
|
||||
QuirksMode::NoQuirks,
|
||||
&NullReporter,
|
||||
None,
|
||||
).is_ok()
|
||||
}
|
||||
|
||||
@ -4269,6 +4284,7 @@ pub extern "C" fn Servo_CSSSupports(cond: *const nsACString) -> bool {
|
||||
Some(CssRuleType::Style),
|
||||
ParsingMode::DEFAULT,
|
||||
QuirksMode::NoQuirks,
|
||||
None,
|
||||
);
|
||||
|
||||
cond.eval(&context)
|
||||
@ -5328,7 +5344,7 @@ pub unsafe extern "C" fn Servo_SelectorList_Drop(list: RawServoSelectorListOwned
|
||||
|
||||
fn parse_color(
|
||||
value: &str,
|
||||
error_reporter: Option<&ErrorReporter>,
|
||||
error_reporter: Option<&ParseErrorReporter>,
|
||||
) -> Result<specified::Color, ()> {
|
||||
let mut input = ParserInput::new(value);
|
||||
let mut parser = Parser::new(&mut input);
|
||||
@ -5339,11 +5355,12 @@ fn parse_color(
|
||||
Some(CssRuleType::Style),
|
||||
ParsingMode::DEFAULT,
|
||||
QuirksMode::NoQuirks,
|
||||
error_reporter,
|
||||
);
|
||||
|
||||
let start_position = parser.position();
|
||||
parser.parse_entirely(|i| specified::Color::parse(&context, i)).map_err(|err| {
|
||||
if let Some(error_reporter) = error_reporter {
|
||||
if error_reporter.is_some() {
|
||||
match err.kind {
|
||||
ParseErrorKind::Custom(StyleParseErrorKind::ValueError(..)) => {
|
||||
let location = err.location.clone();
|
||||
@ -5351,7 +5368,7 @@ fn parse_color(
|
||||
parser.slice_from(start_position),
|
||||
err,
|
||||
);
|
||||
error_reporter.report(location, error);
|
||||
context.log_css_error(location, error);
|
||||
}
|
||||
// Ignore other kinds of errors that might be reported, such as
|
||||
// ParseErrorKind::Basic(BasicParseErrorKind::UnexpectedToken),
|
||||
@ -5385,12 +5402,12 @@ pub extern "C" fn Servo_ComputeColor(
|
||||
let value = unsafe { (*value).to_string() };
|
||||
let result_color = unsafe { result_color.as_mut().unwrap() };
|
||||
|
||||
let reporter = unsafe { loader.as_mut() }.map(|loader| {
|
||||
let reporter = unsafe { loader.as_mut() }.and_then(|loader| {
|
||||
// Make an ErrorReporter that will report errors as being "from DOM".
|
||||
ErrorReporter::new(ptr::null_mut(), loader, ptr::null_mut())
|
||||
});
|
||||
|
||||
match parse_color(&value, reporter.as_ref()) {
|
||||
match parse_color(&value, reporter.as_ref().map(|r| r as &ParseErrorReporter)) {
|
||||
Ok(specified_color) => {
|
||||
let computed_color = match raw_data {
|
||||
Some(raw_data) => {
|
||||
@ -5442,6 +5459,7 @@ pub unsafe extern "C" fn Servo_IntersectionObserverRootMargin_Parse(
|
||||
Some(CssRuleType::Style),
|
||||
ParsingMode::DEFAULT,
|
||||
QuirksMode::NoQuirks,
|
||||
None,
|
||||
);
|
||||
|
||||
let margin = parser.parse_entirely(|p| {
|
||||
@ -5484,7 +5502,8 @@ pub extern "C" fn Servo_ParseTransformIntoMatrix(
|
||||
unsafe { dummy_url_data() },
|
||||
Some(CssRuleType::Style),
|
||||
ParsingMode::DEFAULT,
|
||||
QuirksMode::NoQuirks
|
||||
QuirksMode::NoQuirks,
|
||||
None,
|
||||
);
|
||||
|
||||
let transform = match parser.parse_entirely(|t| transform::parse(&context, t)) {
|
||||
@ -5527,6 +5546,7 @@ pub extern "C" fn Servo_ParseFontShorthandForMatching(
|
||||
Some(CssRuleType::FontFace),
|
||||
ParsingMode::DEFAULT,
|
||||
QuirksMode::NoQuirks,
|
||||
None,
|
||||
);
|
||||
|
||||
let font = match parser.parse_entirely(|f| font::parse_value(&context, f)) {
|
||||
@ -5584,6 +5604,7 @@ pub unsafe extern "C" fn Servo_SourceSizeList_Parse(
|
||||
Some(CssRuleType::Style),
|
||||
ParsingMode::DEFAULT,
|
||||
QuirksMode::NoQuirks,
|
||||
None,
|
||||
);
|
||||
|
||||
// NB: Intentionally not calling parse_entirely.
|
||||
|
@ -6,7 +6,6 @@ use cssparser::SourceLocation;
|
||||
use nsstring::nsCString;
|
||||
use servo_arc::Arc;
|
||||
use style::context::QuirksMode;
|
||||
use style::error_reporting::NullReporter;
|
||||
use style::gecko::data::GeckoStyleSheet;
|
||||
use style::gecko::global_style_data::GLOBAL_STYLE_DATA;
|
||||
use style::gecko_bindings::bindings;
|
||||
@ -104,10 +103,15 @@ impl AsyncStylesheetParser {
|
||||
// are being logged, Gecko prevents the parallel parsing path from
|
||||
// running.
|
||||
let sheet = Arc::new(StylesheetContents::from_str(
|
||||
input, self.extra_data.clone(), self.origin,
|
||||
&global_style_data.shared_lock, Some(&self), &NullReporter,
|
||||
self.quirks_mode.into(), self.line_number_offset)
|
||||
);
|
||||
input,
|
||||
self.extra_data.clone(),
|
||||
self.origin,
|
||||
&global_style_data.shared_lock,
|
||||
Some(&self),
|
||||
None,
|
||||
self.quirks_mode.into(),
|
||||
self.line_number_offset,
|
||||
));
|
||||
|
||||
unsafe {
|
||||
bindings::Gecko_StyleSheet_FinishAsyncParse(self.load_data.get(), sheet.into_strong());
|
||||
|
Loading…
Reference in New Issue
Block a user