Devirtualize CSS error reporting.

This commit is contained in:
Josh Matthews 2017-08-23 17:50:13 -07:00
parent 2e775abfa4
commit 1297c0ff51
28 changed files with 255 additions and 211 deletions

View file

@ -38,7 +38,6 @@ impl CSS {
let url = win.Document().url(); let url = win.Document().url();
let context = ParserContext::new_for_cssom( let context = ParserContext::new_for_cssom(
&url, &url,
win.css_error_reporter(),
Some(CssRuleType::Style), Some(CssRuleType::Style),
PARSING_MODE_DEFAULT, PARSING_MODE_DEFAULT,
QuirksMode::NoQuirks QuirksMode::NoQuirks
@ -55,7 +54,6 @@ impl CSS {
let url = win.Document().url(); let url = win.Document().url();
let context = ParserContext::new_for_cssom( let context = ParserContext::new_for_cssom(
&url, &url,
win.css_error_reporter(),
Some(CssRuleType::Style), Some(CssRuleType::Style),
PARSING_MODE_DEFAULT, PARSING_MODE_DEFAULT,
QuirksMode::NoQuirks QuirksMode::NoQuirks

View file

@ -75,7 +75,7 @@ impl CSSMediaRule {
let win = global.as_window(); let win = global.as_window();
let url = win.get_url(); let url = win.get_url();
let quirks_mode = win.Document().quirks_mode(); let quirks_mode = win.Document().quirks_mode();
let context = ParserContext::new_for_cssom(&url, win.css_error_reporter(), Some(CssRuleType::Media), let context = ParserContext::new_for_cssom(&url, Some(CssRuleType::Media),
PARSING_MODE_DEFAULT, PARSING_MODE_DEFAULT,
quirks_mode); quirks_mode);
let new_medialist = parse_media_query_list(&context, &mut input); let new_medialist = parse_media_query_list(&context, &mut input);

View file

@ -63,7 +63,7 @@ impl CSSSupportsRule {
let win = global.as_window(); let win = global.as_window();
let url = win.Document().url(); let url = win.Document().url();
let quirks_mode = win.Document().quirks_mode(); let quirks_mode = win.Document().quirks_mode();
let context = ParserContext::new_for_cssom(&url, win.css_error_reporter(), Some(CssRuleType::Supports), let context = ParserContext::new_for_cssom(&url, Some(CssRuleType::Supports),
PARSING_MODE_DEFAULT, PARSING_MODE_DEFAULT,
quirks_mode); quirks_mode);
let enabled = cond.eval(&context); let enabled = cond.eval(&context);

View file

@ -285,9 +285,8 @@ impl HTMLLinkElement {
let mut input = ParserInput::new(&mq_str); let mut input = ParserInput::new(&mq_str);
let mut css_parser = CssParser::new(&mut input); let mut css_parser = CssParser::new(&mut input);
let win = document.window();
let doc_url = document.url(); let doc_url = document.url();
let context = CssParserContext::new_for_cssom(&doc_url, win.css_error_reporter(), Some(CssRuleType::Media), let context = CssParserContext::new_for_cssom(&doc_url, Some(CssRuleType::Media),
PARSING_MODE_DEFAULT, PARSING_MODE_DEFAULT,
document.quirks_mode()); document.quirks_mode());
let media = parse_media_query_list(&context, &mut css_parser); let media = parse_media_query_list(&context, &mut css_parser);

View file

@ -86,7 +86,6 @@ impl HTMLStyleElement {
let data = node.GetTextContent().expect("Element.textContent must be a string"); let data = node.GetTextContent().expect("Element.textContent must be a string");
let url = win.get_url(); let url = win.get_url();
let context = CssParserContext::new_for_cssom(&url, let context = CssParserContext::new_for_cssom(&url,
win.css_error_reporter(),
Some(CssRuleType::Media), Some(CssRuleType::Media),
PARSING_MODE_DEFAULT, PARSING_MODE_DEFAULT,
doc.quirks_mode()); doc.quirks_mode());

View file

@ -77,7 +77,7 @@ impl MediaListMethods for MediaList {
let win = global.as_window(); let win = global.as_window();
let url = win.get_url(); let url = win.get_url();
let quirks_mode = win.Document().quirks_mode(); let quirks_mode = win.Document().quirks_mode();
let context = ParserContext::new_for_cssom(&url, win.css_error_reporter(), Some(CssRuleType::Media), let context = ParserContext::new_for_cssom(&url, Some(CssRuleType::Media),
PARSING_MODE_DEFAULT, PARSING_MODE_DEFAULT,
quirks_mode); quirks_mode);
*media_queries = parse_media_query_list(&context, &mut parser); *media_queries = parse_media_query_list(&context, &mut parser);
@ -114,7 +114,7 @@ impl MediaListMethods for MediaList {
let win = global.as_window(); let win = global.as_window();
let url = win.get_url(); let url = win.get_url();
let quirks_mode = win.Document().quirks_mode(); let quirks_mode = win.Document().quirks_mode();
let context = ParserContext::new_for_cssom(&url, win.css_error_reporter(), Some(CssRuleType::Media), let context = ParserContext::new_for_cssom(&url, Some(CssRuleType::Media),
PARSING_MODE_DEFAULT, PARSING_MODE_DEFAULT,
quirks_mode); quirks_mode);
let m = MediaQuery::parse(&context, &mut parser); let m = MediaQuery::parse(&context, &mut parser);
@ -143,7 +143,7 @@ impl MediaListMethods for MediaList {
let win = global.as_window(); let win = global.as_window();
let url = win.get_url(); let url = win.get_url();
let quirks_mode = win.Document().quirks_mode(); let quirks_mode = win.Document().quirks_mode();
let context = ParserContext::new_for_cssom(&url, win.css_error_reporter(), Some(CssRuleType::Media), let context = ParserContext::new_for_cssom(&url, Some(CssRuleType::Media),
PARSING_MODE_DEFAULT, PARSING_MODE_DEFAULT,
quirks_mode); quirks_mode);
let m = MediaQuery::parse(&context, &mut parser); let m = MediaQuery::parse(&context, &mut parser);

View file

@ -105,7 +105,6 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::{Sender, channel}; use std::sync::mpsc::{Sender, channel};
use std::sync::mpsc::TryRecvError::{Disconnected, Empty}; use std::sync::mpsc::TryRecvError::{Disconnected, Empty};
use style::context::ReflowGoal; use style::context::ReflowGoal;
use style::error_reporting::ParseErrorReporter;
use style::media_queries; use style::media_queries;
use style::parser::ParserContext as CssParserContext; use style::parser::ParserContext as CssParserContext;
use style::properties::PropertyId; use style::properties::PropertyId;
@ -377,7 +376,7 @@ impl Window {
&self.bluetooth_extra_permission_data &self.bluetooth_extra_permission_data
} }
pub fn css_error_reporter(&self) -> &ParseErrorReporter { pub fn css_error_reporter(&self) -> &CSSErrorReporter {
&self.error_reporter &self.error_reporter
} }
@ -1012,7 +1011,7 @@ impl WindowMethods for Window {
let mut parser = Parser::new(&mut input); let mut parser = Parser::new(&mut input);
let url = self.get_url(); let url = self.get_url();
let quirks_mode = self.Document().quirks_mode(); let quirks_mode = self.Document().quirks_mode();
let context = CssParserContext::new_for_cssom(&url, self.css_error_reporter(), Some(CssRuleType::Media), let context = CssParserContext::new_for_cssom(&url, Some(CssRuleType::Media),
PARSING_MODE_DEFAULT, PARSING_MODE_DEFAULT,
quirks_mode); quirks_mode);
let media_query_list = media_queries::parse_media_query_list(&context, &mut parser); let media_query_list = media_queries::parse_media_query_list(&context, &mut parser);

View file

@ -9,10 +9,10 @@
use Atom; use Atom;
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser}; use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser};
use cssparser::{Parser, Token, serialize_identifier, BasicParseError, CowRcStr}; use cssparser::{Parser, Token, serialize_identifier, BasicParseError, CowRcStr};
use error_reporting::ContextualParseError; use error_reporting::{ContextualParseError, ParseErrorReporter};
#[cfg(feature = "gecko")] use gecko::rules::CounterStyleDescriptors; #[cfg(feature = "gecko")] use gecko::rules::CounterStyleDescriptors;
#[cfg(feature = "gecko")] use gecko_bindings::structs::nsCSSCounterDesc; #[cfg(feature = "gecko")] use gecko_bindings::structs::nsCSSCounterDesc;
use parser::{ParserContext, Parse}; use parser::{ParserContext, ParserErrorContext, Parse};
use selectors::parser::SelectorParseError; use selectors::parser::SelectorParseError;
use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard}; use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard};
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
@ -50,8 +50,13 @@ pub fn parse_counter_style_name<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Cu
} }
/// Parse the body (inside `{}`) of an @counter-style rule /// Parse the body (inside `{}`) of an @counter-style rule
pub fn parse_counter_style_body<'i, 't>(name: CustomIdent, context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_counter_style_body<'i, 't, R>(name: CustomIdent,
-> Result<CounterStyleRuleData, ParseError<'i>> { context: &ParserContext,
error_context: &ParserErrorContext<R>,
input: &mut Parser<'i, 't>)
-> Result<CounterStyleRuleData, ParseError<'i>>
where R: ParseErrorReporter
{
let start = input.current_source_location(); let start = input.current_source_location();
let mut rule = CounterStyleRuleData::empty(name); let mut rule = CounterStyleRuleData::empty(name);
{ {
@ -63,7 +68,7 @@ pub fn parse_counter_style_body<'i, 't>(name: CustomIdent, context: &ParserConte
while let Some(declaration) = iter.next() { while let Some(declaration) = iter.next() {
if let Err(err) = declaration { if let Err(err) = declaration {
let error = ContextualParseError::UnsupportedCounterStyleDescriptorDeclaration(err.slice, err.error); let error = ContextualParseError::UnsupportedCounterStyleDescriptorDeclaration(err.slice, err.error);
context.log_css_error(err.location, error) context.log_css_error(error_context, err.location, error)
} }
} }
} }
@ -95,7 +100,7 @@ pub fn parse_counter_style_body<'i, 't>(name: CustomIdent, context: &ParserConte
_ => None _ => None
}; };
if let Some(error) = error { if let Some(error) = error {
context.log_css_error(start, error); context.log_css_error(error_context, start, error);
Err(StyleParseError::UnspecifiedError.into()) Err(StyleParseError::UnspecifiedError.into())
} else { } else {
Ok(rule) Ok(rule)

View file

@ -49,17 +49,19 @@ impl Stylesheet {
/// ///
/// Takes care of decoding the network bytes and forwards the resulting /// Takes care of decoding the network bytes and forwards the resulting
/// string to `Stylesheet::from_str`. /// string to `Stylesheet::from_str`.
pub fn from_bytes(bytes: &[u8], pub fn from_bytes<R>(bytes: &[u8],
url_data: UrlExtraData, url_data: UrlExtraData,
protocol_encoding_label: Option<&str>, protocol_encoding_label: Option<&str>,
environment_encoding: Option<EncodingRef>, environment_encoding: Option<EncodingRef>,
origin: Origin, origin: Origin,
media: MediaList, media: MediaList,
shared_lock: SharedRwLock, shared_lock: SharedRwLock,
stylesheet_loader: Option<&StylesheetLoader>, stylesheet_loader: Option<&StylesheetLoader>,
error_reporter: &ParseErrorReporter, error_reporter: &R,
quirks_mode: QuirksMode) quirks_mode: QuirksMode)
-> Stylesheet { -> Stylesheet
where R: ParseErrorReporter
{
let (string, _) = decode_stylesheet_bytes( let (string, _) = decode_stylesheet_bytes(
bytes, protocol_encoding_label, environment_encoding); bytes, protocol_encoding_label, environment_encoding);
Stylesheet::from_str(&string, Stylesheet::from_str(&string,
@ -75,13 +77,15 @@ impl Stylesheet {
/// Updates an empty stylesheet with a set of bytes that reached over the /// Updates an empty stylesheet with a set of bytes that reached over the
/// network. /// network.
pub fn update_from_bytes(existing: &Stylesheet, pub fn update_from_bytes<R>(existing: &Stylesheet,
bytes: &[u8], bytes: &[u8],
protocol_encoding_label: Option<&str>, protocol_encoding_label: Option<&str>,
environment_encoding: Option<EncodingRef>, environment_encoding: Option<EncodingRef>,
url_data: UrlExtraData, url_data: UrlExtraData,
stylesheet_loader: Option<&StylesheetLoader>, stylesheet_loader: Option<&StylesheetLoader>,
error_reporter: &ParseErrorReporter) { error_reporter: &R)
where R: ParseErrorReporter
{
let (string, _) = decode_stylesheet_bytes( let (string, _) = decode_stylesheet_bytes(
bytes, protocol_encoding_label, environment_encoding); bytes, protocol_encoding_label, environment_encoding);
Self::update_from_str(existing, Self::update_from_str(existing,

View file

@ -13,10 +13,10 @@ use computed_values::{font_feature_settings, font_stretch, font_style, font_weig
use computed_values::font_family::FamilyName; use computed_values::font_family::FamilyName;
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser}; use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser};
use cssparser::{SourceLocation, CowRcStr}; use cssparser::{SourceLocation, CowRcStr};
use error_reporting::ContextualParseError; use error_reporting::{ContextualParseError, ParseErrorReporter};
#[cfg(feature = "gecko")] use gecko_bindings::structs::CSSFontFaceDescriptors; #[cfg(feature = "gecko")] use gecko_bindings::structs::CSSFontFaceDescriptors;
#[cfg(feature = "gecko")] use cssparser::UnicodeRange; #[cfg(feature = "gecko")] use cssparser::UnicodeRange;
use parser::{ParserContext, Parse}; use parser::{ParserContext, ParserErrorContext, Parse};
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
use properties::longhands::font_language_override; use properties::longhands::font_language_override;
use selectors::parser::SelectorParseError; use selectors::parser::SelectorParseError;
@ -108,8 +108,13 @@ impl Parse for FontWeight {
/// Parse the block inside a `@font-face` rule. /// Parse the block inside a `@font-face` rule.
/// ///
/// Note that the prelude parsing code lives in the `stylesheets` module. /// Note that the prelude parsing code lives in the `stylesheets` module.
pub fn parse_font_face_block(context: &ParserContext, input: &mut Parser, location: SourceLocation) pub fn parse_font_face_block<R>(context: &ParserContext,
-> FontFaceRuleData { error_context: &ParserErrorContext<R>,
input: &mut Parser,
location: SourceLocation)
-> FontFaceRuleData
where R: ParseErrorReporter
{
let mut rule = FontFaceRuleData::empty(location); let mut rule = FontFaceRuleData::empty(location);
{ {
let parser = FontFaceRuleParser { let parser = FontFaceRuleParser {
@ -120,7 +125,7 @@ pub fn parse_font_face_block(context: &ParserContext, input: &mut Parser, locati
while let Some(declaration) = iter.next() { while let Some(declaration) = iter.next() {
if let Err(err) = declaration { if let Err(err) = declaration {
let error = ContextualParseError::UnsupportedFontFaceDescriptor(err.slice, err.error); let error = ContextualParseError::UnsupportedFontFaceDescriptor(err.slice, err.error);
context.log_css_error(err.location, error) context.log_css_error(error_context, err.location, error)
} }
} }
} }

View file

@ -467,10 +467,13 @@ impl<'le> fmt::Debug for GeckoElement<'le> {
impl<'le> GeckoElement<'le> { impl<'le> GeckoElement<'le> {
/// Parse the style attribute of an element. /// Parse the style attribute of an element.
pub fn parse_style_attribute(value: &str, pub fn parse_style_attribute<R>(value: &str,
url_data: &UrlExtraData, url_data: &UrlExtraData,
quirks_mode: QuirksMode, quirks_mode: QuirksMode,
reporter: &ParseErrorReporter) -> PropertyDeclarationBlock { reporter: &R)
-> PropertyDeclarationBlock
where R: ParseErrorReporter
{
parse_style_attribute(value, url_data, reporter, quirks_mode) parse_style_attribute(value, url_data, reporter, quirks_mode)
} }

View file

@ -38,6 +38,12 @@ 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. /// The data that the parser needs from outside in order to parse a stylesheet.
pub struct ParserContext<'a> { pub struct ParserContext<'a> {
/// The `Origin` of the stylesheet, whether it's a user, author or /// The `Origin` of the stylesheet, whether it's a user, author or
@ -45,8 +51,6 @@ pub struct ParserContext<'a> {
pub stylesheet_origin: Origin, pub stylesheet_origin: Origin,
/// The extra data we need for resolving url values. /// The extra data we need for resolving url values.
pub url_data: &'a UrlExtraData, pub url_data: &'a UrlExtraData,
/// An error reporter to report syntax errors.
pub error_reporter: &'a ParseErrorReporter,
/// The current rule type, if any. /// The current rule type, if any.
pub rule_type: Option<CssRuleType>, pub rule_type: Option<CssRuleType>,
/// Line number offsets for inline stylesheets /// Line number offsets for inline stylesheets
@ -64,7 +68,6 @@ impl<'a> ParserContext<'a> {
pub fn new( pub fn new(
stylesheet_origin: Origin, stylesheet_origin: Origin,
url_data: &'a UrlExtraData, url_data: &'a UrlExtraData,
error_reporter: &'a ParseErrorReporter,
rule_type: Option<CssRuleType>, rule_type: Option<CssRuleType>,
parsing_mode: ParsingMode, parsing_mode: ParsingMode,
quirks_mode: QuirksMode, quirks_mode: QuirksMode,
@ -72,7 +75,6 @@ impl<'a> ParserContext<'a> {
ParserContext { ParserContext {
stylesheet_origin: stylesheet_origin, stylesheet_origin: stylesheet_origin,
url_data: url_data, url_data: url_data,
error_reporter: error_reporter,
rule_type: rule_type, rule_type: rule_type,
line_number_offset: 0u64, line_number_offset: 0u64,
parsing_mode: parsing_mode, parsing_mode: parsing_mode,
@ -84,7 +86,6 @@ impl<'a> ParserContext<'a> {
/// Create a parser context for on-the-fly parsing in CSSOM /// Create a parser context for on-the-fly parsing in CSSOM
pub fn new_for_cssom( pub fn new_for_cssom(
url_data: &'a UrlExtraData, url_data: &'a UrlExtraData,
error_reporter: &'a ParseErrorReporter,
rule_type: Option<CssRuleType>, rule_type: Option<CssRuleType>,
parsing_mode: ParsingMode, parsing_mode: ParsingMode,
quirks_mode: QuirksMode quirks_mode: QuirksMode
@ -92,7 +93,6 @@ impl<'a> ParserContext<'a> {
Self::new( Self::new(
Origin::Author, Origin::Author,
url_data, url_data,
error_reporter,
rule_type, rule_type,
parsing_mode, parsing_mode,
quirks_mode, quirks_mode,
@ -108,7 +108,6 @@ impl<'a> ParserContext<'a> {
ParserContext { ParserContext {
stylesheet_origin: context.stylesheet_origin, stylesheet_origin: context.stylesheet_origin,
url_data: context.url_data, url_data: context.url_data,
error_reporter: context.error_reporter,
rule_type: Some(rule_type), rule_type: Some(rule_type),
line_number_offset: context.line_number_offset, line_number_offset: context.line_number_offset,
parsing_mode: context.parsing_mode, parsing_mode: context.parsing_mode,
@ -121,7 +120,6 @@ impl<'a> ParserContext<'a> {
pub fn new_with_line_number_offset( pub fn new_with_line_number_offset(
stylesheet_origin: Origin, stylesheet_origin: Origin,
url_data: &'a UrlExtraData, url_data: &'a UrlExtraData,
error_reporter: &'a ParseErrorReporter,
line_number_offset: u64, line_number_offset: u64,
parsing_mode: ParsingMode, parsing_mode: ParsingMode,
quirks_mode: QuirksMode, quirks_mode: QuirksMode,
@ -129,7 +127,6 @@ impl<'a> ParserContext<'a> {
ParserContext { ParserContext {
stylesheet_origin: stylesheet_origin, stylesheet_origin: stylesheet_origin,
url_data: url_data, url_data: url_data,
error_reporter: error_reporter,
rule_type: None, rule_type: None,
line_number_offset: line_number_offset, line_number_offset: line_number_offset,
parsing_mode: parsing_mode, parsing_mode: parsing_mode,
@ -144,12 +141,17 @@ impl<'a> ParserContext<'a> {
} }
/// Record a CSS parse error with this contexts error reporting. /// Record a CSS parse error with this contexts error reporting.
pub fn log_css_error(&self, location: SourceLocation, error: ContextualParseError) { pub fn log_css_error<R>(&self,
context: &ParserErrorContext<R>,
location: SourceLocation,
error: ContextualParseError)
where R: ParseErrorReporter
{
let location = SourceLocation { let location = SourceLocation {
line: location.line + self.line_number_offset as u32, line: location.line + self.line_number_offset as u32,
column: location.column, column: location.column,
}; };
self.error_reporter.report_error(self.url_data, location, error) context.error_reporter.report_error(self.url_data, location, error)
} }
} }

View file

@ -10,7 +10,7 @@ use context::QuirksMode;
use cssparser::{DeclarationListParser, parse_important, ParserInput, CowRcStr}; use cssparser::{DeclarationListParser, parse_important, ParserInput, CowRcStr};
use cssparser::{Parser, AtRuleParser, DeclarationParser, Delimiter, ParseError as CssParseError}; use cssparser::{Parser, AtRuleParser, DeclarationParser, Delimiter, ParseError as CssParseError};
use error_reporting::{ParseErrorReporter, ContextualParseError}; use error_reporting::{ParseErrorReporter, ContextualParseError};
use parser::ParserContext; use parser::{ParserContext, ParserErrorContext};
use properties::animated_properties::AnimationValue; use properties::animated_properties::AnimationValue;
use selectors::parser::SelectorParseError; use selectors::parser::SelectorParseError;
use shared_lock::Locked; use shared_lock::Locked;
@ -896,36 +896,39 @@ pub fn append_serialization<'a, W, I, N>(dest: &mut W,
/// A helper to parse the style attribute of an element, in order for this to be /// A helper to parse the style attribute of an element, in order for this to be
/// shared between Servo and Gecko. /// shared between Servo and Gecko.
pub fn parse_style_attribute(input: &str, pub fn parse_style_attribute<R>(input: &str,
url_data: &UrlExtraData, url_data: &UrlExtraData,
error_reporter: &ParseErrorReporter, error_reporter: &R,
quirks_mode: QuirksMode) quirks_mode: QuirksMode)
-> PropertyDeclarationBlock { -> PropertyDeclarationBlock
where R: ParseErrorReporter
{
let context = ParserContext::new(Origin::Author, let context = ParserContext::new(Origin::Author,
url_data, url_data,
error_reporter,
Some(CssRuleType::Style), Some(CssRuleType::Style),
PARSING_MODE_DEFAULT, PARSING_MODE_DEFAULT,
quirks_mode); quirks_mode);
let error_context = ParserErrorContext { error_reporter: error_reporter };
let mut input = ParserInput::new(input); let mut input = ParserInput::new(input);
parse_property_declaration_list(&context, &mut Parser::new(&mut input)) parse_property_declaration_list(&context, &error_context, &mut Parser::new(&mut input))
} }
/// Parse a given property declaration. Can result in multiple /// Parse a given property declaration. Can result in multiple
/// `PropertyDeclaration`s when expanding a shorthand, for example. /// `PropertyDeclaration`s when expanding a shorthand, for example.
/// ///
/// This does not attempt to parse !important at all. /// This does not attempt to parse !important at all.
pub fn parse_one_declaration_into(declarations: &mut SourcePropertyDeclaration, pub fn parse_one_declaration_into<R>(declarations: &mut SourcePropertyDeclaration,
id: PropertyId, id: PropertyId,
input: &str, input: &str,
url_data: &UrlExtraData, url_data: &UrlExtraData,
error_reporter: &ParseErrorReporter, error_reporter: &R,
parsing_mode: ParsingMode, parsing_mode: ParsingMode,
quirks_mode: QuirksMode) quirks_mode: QuirksMode)
-> Result<(), ()> { -> Result<(), ()>
where R: ParseErrorReporter
{
let context = ParserContext::new(Origin::Author, let context = ParserContext::new(Origin::Author,
url_data, url_data,
error_reporter,
Some(CssRuleType::Style), Some(CssRuleType::Style),
parsing_mode, parsing_mode,
quirks_mode); quirks_mode);
@ -939,7 +942,8 @@ pub fn parse_one_declaration_into(declarations: &mut SourcePropertyDeclaration,
}).map_err(|err| { }).map_err(|err| {
let error = ContextualParseError::UnsupportedPropertyDeclaration( let error = ContextualParseError::UnsupportedPropertyDeclaration(
parser.slice_from(start_position), err); parser.slice_from(start_position), err);
context.log_css_error(start_location, error); let error_context = ParserErrorContext { error_reporter: error_reporter };
context.log_css_error(&error_context, start_location, error);
}) })
} }
@ -997,9 +1001,12 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for PropertyDeclarationParser<'a, 'b> {
/// Parse a list of property declarations and return a property declaration /// Parse a list of property declarations and return a property declaration
/// block. /// block.
pub fn parse_property_declaration_list(context: &ParserContext, pub fn parse_property_declaration_list<R>(context: &ParserContext,
input: &mut Parser) error_context: &ParserErrorContext<R>,
-> PropertyDeclarationBlock { input: &mut Parser)
-> PropertyDeclarationBlock
where R: ParseErrorReporter
{
let mut declarations = SourcePropertyDeclaration::new(); let mut declarations = SourcePropertyDeclaration::new();
let mut block = PropertyDeclarationBlock::new(); let mut block = PropertyDeclarationBlock::new();
let parser = PropertyDeclarationParser { let parser = PropertyDeclarationParser {
@ -1024,7 +1031,7 @@ pub fn parse_property_declaration_list(context: &ParserContext,
} }
let error = ContextualParseError::UnsupportedPropertyDeclaration(err.slice, err.error); let error = ContextualParseError::UnsupportedPropertyDeclaration(err.slice, err.error);
context.log_css_error(err.location, error); context.log_css_error(error_context, err.location, error);
} }
} }
} }

View file

@ -23,7 +23,6 @@ use cssparser::ParserInput;
#[cfg(feature = "servo")] use euclid::SideOffsets2D; #[cfg(feature = "servo")] use euclid::SideOffsets2D;
use computed_values; use computed_values;
use context::QuirksMode; use context::QuirksMode;
use error_reporting::NullReporter;
use font_metrics::FontMetricsProvider; use font_metrics::FontMetricsProvider;
#[cfg(feature = "gecko")] use gecko_bindings::bindings; #[cfg(feature = "gecko")] use gecko_bindings::bindings;
#[cfg(feature = "gecko")] use gecko_bindings::structs::{self, nsCSSPropertyID}; #[cfg(feature = "gecko")] use gecko_bindings::structs::{self, nsCSSPropertyID};
@ -828,10 +827,8 @@ impl UnparsedValue {
.ok() .ok()
.and_then(|css| { .and_then(|css| {
// As of this writing, only the base URL is used for property values: // As of this writing, only the base URL is used for property values:
let reporter = NullReporter;
let context = ParserContext::new(Origin::Author, let context = ParserContext::new(Origin::Author,
&self.url_data, &self.url_data,
&reporter,
None, None,
PARSING_MODE_DEFAULT, PARSING_MODE_DEFAULT,
quirks_mode); quirks_mode);

View file

@ -10,8 +10,8 @@ use Atom;
use computed_values::font_family::FamilyName; use computed_values::font_family::FamilyName;
use cssparser::{AtRuleParser, AtRuleType, BasicParseError, DeclarationListParser, DeclarationParser, Parser}; use cssparser::{AtRuleParser, AtRuleType, BasicParseError, DeclarationListParser, DeclarationParser, Parser};
use cssparser::{CowRcStr, RuleListParser, SourceLocation, QualifiedRuleParser, Token, serialize_identifier}; use cssparser::{CowRcStr, RuleListParser, SourceLocation, QualifiedRuleParser, Token, serialize_identifier};
use error_reporting::ContextualParseError; use error_reporting::{ContextualParseError, ParseErrorReporter};
use parser::{ParserContext, Parse}; use parser::{ParserContext, ParserErrorContext, Parse};
use selectors::parser::SelectorParseError; use selectors::parser::SelectorParseError;
use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard}; use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard};
use std::fmt; use std::fmt;
@ -210,20 +210,26 @@ macro_rules! font_feature_values_blocks {
} }
/// Parses a `FontFeatureValuesRule`. /// Parses a `FontFeatureValuesRule`.
pub fn parse(context: &ParserContext, input: &mut Parser, pub fn parse<R>(context: &ParserContext,
family_names: Vec<FamilyName>, location: SourceLocation) error_context: &ParserErrorContext<R>,
-> FontFeatureValuesRule { input: &mut Parser,
family_names: Vec<FamilyName>,
location: SourceLocation)
-> FontFeatureValuesRule
where R: ParseErrorReporter
{
let mut rule = FontFeatureValuesRule::new(family_names, location); let mut rule = FontFeatureValuesRule::new(family_names, location);
{ {
let mut iter = RuleListParser::new_for_nested_rule(input, FontFeatureValuesRuleParser { let mut iter = RuleListParser::new_for_nested_rule(input, FontFeatureValuesRuleParser {
context: context, context: context,
error_context: error_context,
rule: &mut rule, rule: &mut rule,
}); });
while let Some(result) = iter.next() { while let Some(result) = iter.next() {
if let Err(err) = result { if let Err(err) = result {
let error = ContextualParseError::UnsupportedRule(err.slice, err.error); let error = ContextualParseError::UnsupportedRule(err.slice, err.error);
context.log_css_error(err.location, error); context.log_css_error(error_context, err.location, error);
} }
} }
} }
@ -293,19 +299,20 @@ macro_rules! font_feature_values_blocks {
/// } /// }
/// <feature-type> = @stylistic | @historical-forms | @styleset | /// <feature-type> = @stylistic | @historical-forms | @styleset |
/// @character-variant | @swash | @ornaments | @annotation /// @character-variant | @swash | @ornaments | @annotation
struct FontFeatureValuesRuleParser<'a> { struct FontFeatureValuesRuleParser<'a, R: 'a> {
context: &'a ParserContext<'a>, context: &'a ParserContext<'a>,
error_context: &'a ParserErrorContext<'a, R>,
rule: &'a mut FontFeatureValuesRule, rule: &'a mut FontFeatureValuesRule,
} }
/// Default methods reject all qualified rules. /// Default methods reject all qualified rules.
impl<'a, 'i> QualifiedRuleParser<'i> for FontFeatureValuesRuleParser<'a> { impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for FontFeatureValuesRuleParser<'a, R> {
type Prelude = (); type Prelude = ();
type QualifiedRule = (); type QualifiedRule = ();
type Error = SelectorParseError<'i, StyleParseError<'i>>; type Error = SelectorParseError<'i, StyleParseError<'i>>;
} }
impl<'a, 'i> AtRuleParser<'i> for FontFeatureValuesRuleParser<'a> { impl<'a, 'i, R: ParseErrorReporter> AtRuleParser<'i> for FontFeatureValuesRuleParser<'a, R> {
type Prelude = BlockType; type Prelude = BlockType;
type AtRule = (); type AtRule = ();
type Error = SelectorParseError<'i, StyleParseError<'i>>; type Error = SelectorParseError<'i, StyleParseError<'i>>;
@ -341,7 +348,7 @@ macro_rules! font_feature_values_blocks {
if let Err(err) = declaration { if let Err(err) = declaration {
let error = ContextualParseError::UnsupportedKeyframePropertyDeclaration( let error = ContextualParseError::UnsupportedKeyframePropertyDeclaration(
err.slice, err.error); err.slice, err.error);
self.context.log_css_error(err.location, error); self.context.log_css_error(self.error_context, err.location, error);
} }
} }
}, },

View file

@ -6,8 +6,8 @@
use cssparser::{AtRuleParser, Parser, QualifiedRuleParser, RuleListParser, ParserInput, CowRcStr}; use cssparser::{AtRuleParser, Parser, QualifiedRuleParser, RuleListParser, ParserInput, CowRcStr};
use cssparser::{DeclarationListParser, DeclarationParser, parse_one_rule, SourceLocation}; use cssparser::{DeclarationListParser, DeclarationParser, parse_one_rule, SourceLocation};
use error_reporting::{NullReporter, ContextualParseError}; use error_reporting::{NullReporter, ContextualParseError, ParseErrorReporter};
use parser::ParserContext; use parser::{ParserContext, ParserErrorContext};
use properties::{Importance, PropertyDeclaration, PropertyDeclarationBlock, PropertyId, PropertyParserContext}; use properties::{Importance, PropertyDeclaration, PropertyDeclarationBlock, PropertyId, PropertyParserContext};
use properties::{PropertyDeclarationId, LonghandId, SourcePropertyDeclaration}; use properties::{PropertyDeclarationId, LonghandId, SourcePropertyDeclaration};
use properties::LonghandIdSet; use properties::LonghandIdSet;
@ -218,11 +218,11 @@ impl Keyframe {
let mut context = ParserContext::new( let mut context = ParserContext::new(
parent_stylesheet_contents.origin, parent_stylesheet_contents.origin,
&url_data, &url_data,
&error_reporter,
Some(CssRuleType::Keyframe), Some(CssRuleType::Keyframe),
PARSING_MODE_DEFAULT, PARSING_MODE_DEFAULT,
parent_stylesheet_contents.quirks_mode parent_stylesheet_contents.quirks_mode
); );
let error_context = ParserErrorContext { error_reporter: &error_reporter };
context.namespaces = Some(&*namespaces); context.namespaces = Some(&*namespaces);
let mut input = ParserInput::new(css); let mut input = ParserInput::new(css);
let mut input = Parser::new(&mut input); let mut input = Parser::new(&mut input);
@ -230,6 +230,7 @@ impl Keyframe {
let mut declarations = SourcePropertyDeclaration::new(); let mut declarations = SourcePropertyDeclaration::new();
let mut rule_parser = KeyframeListParser { let mut rule_parser = KeyframeListParser {
context: &context, context: &context,
error_context: &error_context,
shared_lock: &lock, shared_lock: &lock,
declarations: &mut declarations, declarations: &mut declarations,
}; };
@ -447,37 +448,42 @@ impl KeyframesAnimation {
/// 40%, 60%, 100% { /// 40%, 60%, 100% {
/// width: 100%; /// width: 100%;
/// } /// }
struct KeyframeListParser<'a> { struct KeyframeListParser<'a, R: 'a> {
context: &'a ParserContext<'a>, context: &'a ParserContext<'a>,
error_context: &'a ParserErrorContext<'a, R>,
shared_lock: &'a SharedRwLock, shared_lock: &'a SharedRwLock,
declarations: &'a mut SourcePropertyDeclaration, declarations: &'a mut SourcePropertyDeclaration,
} }
/// Parses a keyframe list from CSS input. /// Parses a keyframe list from CSS input.
pub fn parse_keyframe_list( pub fn parse_keyframe_list<R>(
context: &ParserContext, context: &ParserContext,
error_context: &ParserErrorContext<R>,
input: &mut Parser, input: &mut Parser,
shared_lock: &SharedRwLock shared_lock: &SharedRwLock
) -> Vec<Arc<Locked<Keyframe>>> { ) -> Vec<Arc<Locked<Keyframe>>>
where R: ParseErrorReporter
{
debug_assert!(context.namespaces.is_some(), debug_assert!(context.namespaces.is_some(),
"Parsing a keyframe list from a context without namespaces?"); "Parsing a keyframe list from a context without namespaces?");
let mut declarations = SourcePropertyDeclaration::new(); let mut declarations = SourcePropertyDeclaration::new();
RuleListParser::new_for_nested_rule(input, KeyframeListParser { RuleListParser::new_for_nested_rule(input, KeyframeListParser {
context: context, context: context,
error_context: error_context,
shared_lock: shared_lock, shared_lock: shared_lock,
declarations: &mut declarations, declarations: &mut declarations,
}).filter_map(Result::ok).collect() }).filter_map(Result::ok).collect()
} }
enum Void {} enum Void {}
impl<'a, 'i> AtRuleParser<'i> for KeyframeListParser<'a> { impl<'a, 'i, R> AtRuleParser<'i> for KeyframeListParser<'a, R> {
type Prelude = Void; type Prelude = Void;
type AtRule = Arc<Locked<Keyframe>>; type AtRule = Arc<Locked<Keyframe>>;
type Error = SelectorParseError<'i, StyleParseError<'i>>; type Error = SelectorParseError<'i, StyleParseError<'i>>;
} }
impl<'a, 'i> QualifiedRuleParser<'i> for KeyframeListParser<'a> { impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for KeyframeListParser<'a, R> {
type Prelude = KeyframeSelector; type Prelude = KeyframeSelector;
type QualifiedRule = Arc<Locked<Keyframe>>; type QualifiedRule = Arc<Locked<Keyframe>>;
type Error = SelectorParseError<'i, StyleParseError<'i>>; type Error = SelectorParseError<'i, StyleParseError<'i>>;
@ -489,7 +495,7 @@ impl<'a, 'i> QualifiedRuleParser<'i> for KeyframeListParser<'a> {
Ok(sel) => Ok(sel), Ok(sel) => Ok(sel),
Err(e) => { Err(e) => {
let error = ContextualParseError::InvalidKeyframeRule(input.slice_from(start_position), e.clone()); let error = ContextualParseError::InvalidKeyframeRule(input.slice_from(start_position), e.clone());
self.context.log_css_error(start_location, error); self.context.log_css_error(self.error_context, start_location, error);
Err(e) Err(e)
} }
} }
@ -518,7 +524,7 @@ impl<'a, 'i> QualifiedRuleParser<'i> for KeyframeListParser<'a> {
Err(err) => { Err(err) => {
iter.parser.declarations.clear(); iter.parser.declarations.clear();
let error = ContextualParseError::UnsupportedKeyframePropertyDeclaration(err.slice, err.error); let error = ContextualParseError::UnsupportedKeyframePropertyDeclaration(err.slice, err.error);
context.log_css_error(err.location, error); context.log_css_error(self.error_context, err.location, error);
} }
} }
// `parse_important` is not called here, `!important` is not allowed in keyframe blocks. // `parse_important` is not called here, `!important` is not allowed in keyframe blocks.

View file

@ -26,7 +26,7 @@ pub mod viewport_rule;
use cssparser::{parse_one_rule, Parser, ParserInput}; use cssparser::{parse_one_rule, Parser, ParserInput};
use error_reporting::NullReporter; use error_reporting::NullReporter;
use parser::ParserContext; use parser::{ParserContext, ParserErrorContext};
use servo_arc::Arc; use servo_arc::Arc;
use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard}; use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard};
use std::fmt; use std::fmt;
@ -230,7 +230,6 @@ impl CssRule {
let context = ParserContext::new( let context = ParserContext::new(
parent_stylesheet_contents.origin, parent_stylesheet_contents.origin,
&url_data, &url_data,
&error_reporter,
None, None,
PARSING_MODE_DEFAULT, PARSING_MODE_DEFAULT,
parent_stylesheet_contents.quirks_mode, parent_stylesheet_contents.quirks_mode,
@ -246,6 +245,7 @@ impl CssRule {
let mut rule_parser = TopLevelRuleParser { let mut rule_parser = TopLevelRuleParser {
stylesheet_origin: parent_stylesheet_contents.origin, stylesheet_origin: parent_stylesheet_contents.origin,
context: context, context: context,
error_context: ParserErrorContext { error_reporter: &error_reporter },
shared_lock: &shared_lock, shared_lock: &shared_lock,
loader: loader, loader: loader,
state: state, state: state,

View file

@ -9,10 +9,10 @@ use computed_values::font_family::FamilyName;
use counter_style::{parse_counter_style_body, parse_counter_style_name}; use counter_style::{parse_counter_style_body, parse_counter_style_name};
use cssparser::{AtRuleParser, AtRuleType, Parser, QualifiedRuleParser, RuleListParser}; use cssparser::{AtRuleParser, AtRuleType, Parser, QualifiedRuleParser, RuleListParser};
use cssparser::{CowRcStr, SourceLocation, BasicParseError}; use cssparser::{CowRcStr, SourceLocation, BasicParseError};
use error_reporting::ContextualParseError; use error_reporting::{ContextualParseError, ParseErrorReporter};
use font_face::parse_font_face_block; use font_face::parse_font_face_block;
use media_queries::{parse_media_query_list, MediaList}; use media_queries::{parse_media_query_list, MediaList};
use parser::{Parse, ParserContext}; use parser::{Parse, ParserContext, ParserErrorContext};
use properties::parse_property_declaration_list; use properties::parse_property_declaration_list;
use selector_parser::{SelectorImpl, SelectorParser}; use selector_parser::{SelectorImpl, SelectorParser};
use selectors::SelectorList; use selectors::SelectorList;
@ -35,7 +35,7 @@ use values::KeyframesName;
use values::specified::url::SpecifiedUrl; use values::specified::url::SpecifiedUrl;
/// The parser for the top-level rules in a stylesheet. /// The parser for the top-level rules in a stylesheet.
pub struct TopLevelRuleParser<'a> { pub struct TopLevelRuleParser<'a, R: 'a> {
/// The origin of the stylesheet we're parsing. /// The origin of the stylesheet we're parsing.
pub stylesheet_origin: Origin, pub stylesheet_origin: Origin,
/// A reference to the lock we need to use to create rules. /// A reference to the lock we need to use to create rules.
@ -47,6 +47,8 @@ pub struct TopLevelRuleParser<'a> {
/// This won't contain any namespaces, and only nested parsers created with /// This won't contain any namespaces, and only nested parsers created with
/// `ParserContext::new_with_rule_type` will. /// `ParserContext::new_with_rule_type` will.
pub context: ParserContext<'a>, pub context: ParserContext<'a>,
/// The context required for reporting parse errors.
pub error_context: ParserErrorContext<'a, R>,
/// The current state of the parser. /// The current state of the parser.
pub state: State, pub state: State,
/// Whether we have tried to parse was invalid due to being in the wrong /// Whether we have tried to parse was invalid due to being in the wrong
@ -59,12 +61,13 @@ pub struct TopLevelRuleParser<'a> {
pub namespaces: &'a mut Namespaces, pub namespaces: &'a mut Namespaces,
} }
impl<'b> TopLevelRuleParser<'b> { impl<'b, R> TopLevelRuleParser<'b, R> {
fn nested<'a: 'b>(&'a self) -> NestedRuleParser<'a, 'b> { fn nested<'a: 'b>(&'a self) -> NestedRuleParser<'a, 'b, R> {
NestedRuleParser { NestedRuleParser {
stylesheet_origin: self.stylesheet_origin, stylesheet_origin: self.stylesheet_origin,
shared_lock: self.shared_lock, shared_lock: self.shared_lock,
context: &self.context, context: &self.context,
error_context: &self.error_context,
namespaces: &self.namespaces, namespaces: &self.namespaces,
} }
} }
@ -147,7 +150,7 @@ fn register_namespace(_: &Namespace) -> Result<(), ()> {
Ok(()) // servo doesn't use namespace ids Ok(()) // servo doesn't use namespace ids
} }
impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> { impl<'a, 'i, R: ParseErrorReporter> AtRuleParser<'i> for TopLevelRuleParser<'a, R> {
type Prelude = AtRulePrelude; type Prelude = AtRulePrelude;
type AtRule = CssRule; type AtRule = CssRule;
type Error = SelectorParseError<'i, StyleParseError<'i>>; type Error = SelectorParseError<'i, StyleParseError<'i>>;
@ -256,7 +259,7 @@ pub struct QualifiedRuleParserPrelude {
source_location: SourceLocation, source_location: SourceLocation,
} }
impl<'a, 'i> QualifiedRuleParser<'i> for TopLevelRuleParser<'a> { impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for TopLevelRuleParser<'a, R> {
type Prelude = QualifiedRuleParserPrelude; type Prelude = QualifiedRuleParserPrelude;
type QualifiedRule = CssRule; type QualifiedRule = CssRule;
type Error = SelectorParseError<'i, StyleParseError<'i>>; type Error = SelectorParseError<'i, StyleParseError<'i>>;
@ -281,14 +284,15 @@ impl<'a, 'i> QualifiedRuleParser<'i> for TopLevelRuleParser<'a> {
} }
#[derive(Clone)] // shallow, relatively cheap .clone #[derive(Clone)] // shallow, relatively cheap .clone
struct NestedRuleParser<'a, 'b: 'a> { struct NestedRuleParser<'a, 'b: 'a, R: 'b> {
stylesheet_origin: Origin, stylesheet_origin: Origin,
shared_lock: &'a SharedRwLock, shared_lock: &'a SharedRwLock,
context: &'a ParserContext<'b>, context: &'a ParserContext<'b>,
error_context: &'a ParserErrorContext<'b, R>,
namespaces: &'a Namespaces, namespaces: &'a Namespaces,
} }
impl<'a, 'b> NestedRuleParser<'a, 'b> { impl<'a, 'b, R: ParseErrorReporter> NestedRuleParser<'a, 'b, R> {
fn parse_nested_rules( fn parse_nested_rules(
&mut self, &mut self,
input: &mut Parser, input: &mut Parser,
@ -301,6 +305,7 @@ impl<'a, 'b> NestedRuleParser<'a, 'b> {
stylesheet_origin: self.stylesheet_origin, stylesheet_origin: self.stylesheet_origin,
shared_lock: self.shared_lock, shared_lock: self.shared_lock,
context: &context, context: &context,
error_context: &self.error_context,
namespaces: self.namespaces, namespaces: self.namespaces,
}; };
@ -311,7 +316,7 @@ impl<'a, 'b> NestedRuleParser<'a, 'b> {
Ok(rule) => rules.push(rule), Ok(rule) => rules.push(rule),
Err(err) => { Err(err) => {
let error = ContextualParseError::UnsupportedRule(err.slice, err.error); let error = ContextualParseError::UnsupportedRule(err.slice, err.error);
self.context.log_css_error(err.location, error); self.context.log_css_error(self.error_context, err.location, error);
} }
} }
} }
@ -319,7 +324,7 @@ impl<'a, 'b> NestedRuleParser<'a, 'b> {
} }
} }
impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> { impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a, 'b, R> {
type Prelude = AtRulePrelude; type Prelude = AtRulePrelude;
type AtRule = CssRule; type AtRule = CssRule;
type Error = SelectorParseError<'i, StyleParseError<'i>>; type Error = SelectorParseError<'i, StyleParseError<'i>>;
@ -428,7 +433,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
); );
Ok(CssRule::FontFace(Arc::new(self.shared_lock.wrap( Ok(CssRule::FontFace(Arc::new(self.shared_lock.wrap(
parse_font_face_block(&context, input, location).into())))) parse_font_face_block(&context, self.error_context, input, location).into()))))
} }
AtRulePrelude::FontFeatureValues(family_names, location) => { AtRulePrelude::FontFeatureValues(family_names, location) => {
let context = let context =
@ -438,7 +443,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
self.namespaces, self.namespaces,
); );
Ok(CssRule::FontFeatureValues(Arc::new(self.shared_lock.wrap( Ok(CssRule::FontFeatureValues(Arc::new(self.shared_lock.wrap(
FontFeatureValuesRule::parse(&context, input, family_names, location))))) FontFeatureValuesRule::parse(&context, self.error_context, input, family_names, location)))))
} }
AtRulePrelude::CounterStyle(name) => { AtRulePrelude::CounterStyle(name) => {
let context = let context =
@ -448,7 +453,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
self.namespaces, self.namespaces,
); );
Ok(CssRule::CounterStyle(Arc::new(self.shared_lock.wrap( Ok(CssRule::CounterStyle(Arc::new(self.shared_lock.wrap(
parse_counter_style_body(name, &context, input)?.into())))) parse_counter_style_body(name, &context, self.error_context, input)?.into()))))
} }
AtRulePrelude::Media(media_queries, location) => { AtRulePrelude::Media(media_queries, location) => {
Ok(CssRule::Media(Arc::new(self.shared_lock.wrap(MediaRule { Ok(CssRule::Media(Arc::new(self.shared_lock.wrap(MediaRule {
@ -480,7 +485,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
self.namespaces, self.namespaces,
); );
Ok(CssRule::Viewport(Arc::new(self.shared_lock.wrap( Ok(CssRule::Viewport(Arc::new(self.shared_lock.wrap(
ViewportRule::parse(&context, input)?)))) ViewportRule::parse(&context, self.error_context, input)?))))
} }
AtRulePrelude::Keyframes(name, prefix, location) => { AtRulePrelude::Keyframes(name, prefix, location) => {
let context = let context =
@ -492,7 +497,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
Ok(CssRule::Keyframes(Arc::new(self.shared_lock.wrap(KeyframesRule { Ok(CssRule::Keyframes(Arc::new(self.shared_lock.wrap(KeyframesRule {
name: name, name: name,
keyframes: parse_keyframe_list(&context, input, self.shared_lock), keyframes: parse_keyframe_list(&context, self.error_context, input, self.shared_lock),
vendor_prefix: prefix, vendor_prefix: prefix,
source_location: location, source_location: location,
})))) }))))
@ -504,7 +509,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
CssRuleType::Page, CssRuleType::Page,
self.namespaces, self.namespaces,
); );
let declarations = parse_property_declaration_list(&context, input); let declarations = parse_property_declaration_list(&context, self.error_context, input);
Ok(CssRule::Page(Arc::new(self.shared_lock.wrap(PageRule { Ok(CssRule::Page(Arc::new(self.shared_lock.wrap(PageRule {
block: Arc::new(self.shared_lock.wrap(declarations)), block: Arc::new(self.shared_lock.wrap(declarations)),
source_location: location, source_location: location,
@ -525,7 +530,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
} }
} }
impl<'a, 'b, 'i> QualifiedRuleParser<'i> for NestedRuleParser<'a, 'b> { impl<'a, 'b, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for NestedRuleParser<'a, 'b, R> {
type Prelude = QualifiedRuleParserPrelude; type Prelude = QualifiedRuleParserPrelude;
type QualifiedRule = CssRule; type QualifiedRule = CssRule;
type Error = SelectorParseError<'i, StyleParseError<'i>>; type Error = SelectorParseError<'i, StyleParseError<'i>>;
@ -561,7 +566,7 @@ impl<'a, 'b, 'i> QualifiedRuleParser<'i> for NestedRuleParser<'a, 'b> {
CssRuleType::Style, CssRuleType::Style,
self.namespaces, self.namespaces,
); );
let declarations = parse_property_declaration_list(&context, input); let declarations = parse_property_declaration_list(&context, self.error_context, input);
Ok(CssRule::Style(Arc::new(self.shared_lock.wrap(StyleRule { Ok(CssRule::Style(Arc::new(self.shared_lock.wrap(StyleRule {
selectors: prelude.selectors, selectors: prelude.selectors,
block: Arc::new(self.shared_lock.wrap(declarations)), block: Arc::new(self.shared_lock.wrap(declarations)),

View file

@ -10,7 +10,7 @@ use fnv::FnvHashMap;
use invalidation::media_queries::{MediaListKey, ToMediaListKey}; use invalidation::media_queries::{MediaListKey, ToMediaListKey};
use media_queries::{MediaList, Device}; use media_queries::{MediaList, Device};
use parking_lot::RwLock; use parking_lot::RwLock;
use parser::ParserContext; use parser::{ParserContext, ParserErrorContext};
use servo_arc::Arc; use servo_arc::Arc;
use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard}; use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard};
use std::mem; use std::mem;
@ -67,13 +67,13 @@ pub struct StylesheetContents {
impl StylesheetContents { impl StylesheetContents {
/// Parse a given CSS string, with a given url-data, origin, and /// Parse a given CSS string, with a given url-data, origin, and
/// quirks mode. /// quirks mode.
pub fn from_str( pub fn from_str<R: ParseErrorReporter>(
css: &str, css: &str,
url_data: UrlExtraData, url_data: UrlExtraData,
origin: Origin, origin: Origin,
shared_lock: &SharedRwLock, shared_lock: &SharedRwLock,
stylesheet_loader: Option<&StylesheetLoader>, stylesheet_loader: Option<&StylesheetLoader>,
error_reporter: &ParseErrorReporter, error_reporter: &R,
quirks_mode: QuirksMode, quirks_mode: QuirksMode,
line_number_offset: u64 line_number_offset: u64
) -> Self { ) -> Self {
@ -313,12 +313,14 @@ impl StylesheetInDocument for DocumentStyleSheet {
impl Stylesheet { impl Stylesheet {
/// Updates an empty stylesheet from a given string of text. /// Updates an empty stylesheet from a given string of text.
pub fn update_from_str(existing: &Stylesheet, pub fn update_from_str<R>(existing: &Stylesheet,
css: &str, css: &str,
url_data: UrlExtraData, url_data: UrlExtraData,
stylesheet_loader: Option<&StylesheetLoader>, stylesheet_loader: Option<&StylesheetLoader>,
error_reporter: &ParseErrorReporter, error_reporter: &R,
line_number_offset: u64) { line_number_offset: u64)
where R: ParseErrorReporter
{
let namespaces = RwLock::new(Namespaces::default()); let namespaces = RwLock::new(Namespaces::default());
let (rules, dirty_on_viewport_size_change, source_map_url) = let (rules, dirty_on_viewport_size_change, source_map_url) =
Stylesheet::parse_rules( Stylesheet::parse_rules(
@ -347,14 +349,14 @@ impl Stylesheet {
*existing.contents.source_map_url.write() = source_map_url; *existing.contents.source_map_url.write() = source_map_url;
} }
fn parse_rules( fn parse_rules<R: ParseErrorReporter>(
css: &str, css: &str,
url_data: &UrlExtraData, url_data: &UrlExtraData,
origin: Origin, origin: Origin,
namespaces: &mut Namespaces, namespaces: &mut Namespaces,
shared_lock: &SharedRwLock, shared_lock: &SharedRwLock,
stylesheet_loader: Option<&StylesheetLoader>, stylesheet_loader: Option<&StylesheetLoader>,
error_reporter: &ParseErrorReporter, error_reporter: &R,
quirks_mode: QuirksMode, quirks_mode: QuirksMode,
line_number_offset: u64 line_number_offset: u64
) -> (Vec<CssRule>, bool, Option<String>) { ) -> (Vec<CssRule>, bool, Option<String>) {
@ -366,17 +368,18 @@ impl Stylesheet {
ParserContext::new_with_line_number_offset( ParserContext::new_with_line_number_offset(
origin, origin,
url_data, url_data,
error_reporter,
line_number_offset, line_number_offset,
PARSING_MODE_DEFAULT, PARSING_MODE_DEFAULT,
quirks_mode quirks_mode
); );
let error_context = ParserErrorContext { error_reporter };
let rule_parser = TopLevelRuleParser { let rule_parser = TopLevelRuleParser {
stylesheet_origin: origin, stylesheet_origin: origin,
shared_lock: shared_lock, shared_lock: shared_lock,
loader: stylesheet_loader, loader: stylesheet_loader,
context: context, context: context,
error_context: error_context,
state: State::Start, state: State::Start,
had_hierarchy_error: false, had_hierarchy_error: false,
namespaces: namespaces, namespaces: namespaces,
@ -393,7 +396,8 @@ impl Stylesheet {
Ok(rule) => rules.push(rule), Ok(rule) => rules.push(rule),
Err(err) => { Err(err) => {
let error = ContextualParseError::InvalidRule(err.slice, err.error); let error = ContextualParseError::InvalidRule(err.slice, err.error);
iter.parser.context.log_css_error(err.location, error); iter.parser.context.log_css_error(&iter.parser.error_context,
err.location, error);
} }
} }
} }
@ -408,16 +412,18 @@ impl Stylesheet {
/// ///
/// Effectively creates a new stylesheet and forwards the hard work to /// Effectively creates a new stylesheet and forwards the hard work to
/// `Stylesheet::update_from_str`. /// `Stylesheet::update_from_str`.
pub fn from_str(css: &str, pub fn from_str<R: ParseErrorReporter>(
url_data: UrlExtraData, css: &str,
origin: Origin, url_data: UrlExtraData,
media: Arc<Locked<MediaList>>, origin: Origin,
shared_lock: SharedRwLock, media: Arc<Locked<MediaList>>,
stylesheet_loader: Option<&StylesheetLoader>, shared_lock: SharedRwLock,
error_reporter: &ParseErrorReporter, stylesheet_loader: Option<&StylesheetLoader>,
quirks_mode: QuirksMode, error_reporter: &R,
line_number_offset: u64) quirks_mode: QuirksMode,
-> Stylesheet { line_number_offset: u64)
-> Stylesheet
{
let contents = StylesheetContents::from_str( let contents = StylesheetContents::from_str(
css, css,
url_data, url_data,

View file

@ -11,11 +11,11 @@ use app_units::Au;
use context::QuirksMode; use context::QuirksMode;
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser, parse_important}; use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser, parse_important};
use cssparser::{CowRcStr, ToCss as ParserToCss}; use cssparser::{CowRcStr, ToCss as ParserToCss};
use error_reporting::ContextualParseError; use error_reporting::{ContextualParseError, ParseErrorReporter};
use euclid::TypedSize2D; use euclid::TypedSize2D;
use font_metrics::get_metrics_provider_for_product; use font_metrics::get_metrics_provider_for_product;
use media_queries::Device; use media_queries::Device;
use parser::{Parse, ParserContext}; use parser::{ParserContext, ParserErrorContext};
use properties::StyleBuilder; use properties::StyleBuilder;
use selectors::parser::SelectorParseError; use selectors::parser::SelectorParseError;
use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard}; use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard};
@ -346,8 +346,14 @@ fn is_whitespace_separator_or_equals(c: &char) -> bool {
WHITESPACE.contains(c) || SEPARATOR.contains(c) || *c == '=' WHITESPACE.contains(c) || SEPARATOR.contains(c) || *c == '='
} }
impl Parse for ViewportRule { impl ViewportRule {
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> { /// Parse a single @viewport rule.
pub fn parse<'i, 't, R>(context: &ParserContext,
error_context: &ParserErrorContext<R>,
input: &mut Parser<'i, 't>)
-> Result<Self, ParseError<'i>>
where R: ParseErrorReporter
{
let parser = ViewportRuleParser { context: context }; let parser = ViewportRuleParser { context: context };
let mut cascade = Cascade::new(); let mut cascade = Cascade::new();
@ -361,7 +367,7 @@ impl Parse for ViewportRule {
} }
Err(err) => { Err(err) => {
let error = ContextualParseError::UnsupportedViewportDescriptorDeclaration(err.slice, err.error); let error = ContextualParseError::UnsupportedViewportDescriptorDeclaration(err.slice, err.error);
context.log_css_error(err.location, error); context.log_css_error(error_context, err.location, error);
} }
} }
} }

View file

@ -1986,13 +1986,16 @@ pub extern "C" fn Servo_StyleSet_CompatModeChanged(raw_data: RawServoStyleSetBor
data.stylist.set_quirks_mode(quirks_mode.into()); data.stylist.set_quirks_mode(quirks_mode.into());
} }
fn parse_property_into(declarations: &mut SourcePropertyDeclaration, fn parse_property_into<R>(declarations: &mut SourcePropertyDeclaration,
property_id: PropertyId, property_id: PropertyId,
value: *const nsACString, value: *const nsACString,
data: *mut URLExtraData, data: *mut URLExtraData,
parsing_mode: structs::ParsingMode, parsing_mode: structs::ParsingMode,
quirks_mode: QuirksMode, quirks_mode: QuirksMode,
reporter: &ParseErrorReporter) -> Result<(), ()> { reporter: &R)
-> Result<(), ()>
where R: ParseErrorReporter
{
use style_traits::ParsingMode; use style_traits::ParsingMode;
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() }; let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
let url_data = unsafe { RefPtr::from_ptr_ref(&data) }; let url_data = unsafe { RefPtr::from_ptr_ref(&data) };
@ -2039,10 +2042,8 @@ pub extern "C" fn Servo_ParseEasing(easing: *const nsAString,
use style::properties::longhands::transition_timing_function; use style::properties::longhands::transition_timing_function;
let url_data = unsafe { RefPtr::from_ptr_ref(&data) }; let url_data = unsafe { RefPtr::from_ptr_ref(&data) };
let reporter = NullReporter;
let context = ParserContext::new(Origin::Author, let context = ParserContext::new(Origin::Author,
url_data, url_data,
&reporter,
Some(CssRuleType::Style), Some(CssRuleType::Style),
PARSING_MODE_DEFAULT, PARSING_MODE_DEFAULT,
QuirksMode::NoQuirks); QuirksMode::NoQuirks);
@ -2370,8 +2371,7 @@ pub extern "C" fn Servo_MediaList_SetText(list: RawServoMediaListBorrowed, text:
let mut input = ParserInput::new(&text); let mut input = ParserInput::new(&text);
let mut parser = Parser::new(&mut input); let mut parser = Parser::new(&mut input);
let url_data = unsafe { dummy_url_data() }; let url_data = unsafe { dummy_url_data() };
let reporter = NullReporter; let context = ParserContext::new_for_cssom(url_data, Some(CssRuleType::Media),
let context = ParserContext::new_for_cssom(url_data, &reporter, Some(CssRuleType::Media),
PARSING_MODE_DEFAULT, PARSING_MODE_DEFAULT,
QuirksMode::NoQuirks); QuirksMode::NoQuirks);
write_locked_arc(list, |list: &mut MediaList| { write_locked_arc(list, |list: &mut MediaList| {
@ -2402,8 +2402,7 @@ pub extern "C" fn Servo_MediaList_AppendMedium(list: RawServoMediaListBorrowed,
new_medium: *const nsACString) { new_medium: *const nsACString) {
let new_medium = unsafe { new_medium.as_ref().unwrap().as_str_unchecked() }; let new_medium = unsafe { new_medium.as_ref().unwrap().as_str_unchecked() };
let url_data = unsafe { dummy_url_data() }; let url_data = unsafe { dummy_url_data() };
let reporter = NullReporter; let context = ParserContext::new_for_cssom(url_data, Some(CssRuleType::Media),
let context = ParserContext::new_for_cssom(url_data, &reporter, Some(CssRuleType::Media),
PARSING_MODE_DEFAULT, PARSING_MODE_DEFAULT,
QuirksMode::NoQuirks); QuirksMode::NoQuirks);
write_locked_arc(list, |list: &mut MediaList| { write_locked_arc(list, |list: &mut MediaList| {
@ -2416,8 +2415,7 @@ pub extern "C" fn Servo_MediaList_DeleteMedium(list: RawServoMediaListBorrowed,
old_medium: *const nsACString) -> bool { old_medium: *const nsACString) -> bool {
let old_medium = unsafe { old_medium.as_ref().unwrap().as_str_unchecked() }; let old_medium = unsafe { old_medium.as_ref().unwrap().as_str_unchecked() };
let url_data = unsafe { dummy_url_data() }; let url_data = unsafe { dummy_url_data() };
let reporter = NullReporter; let context = ParserContext::new_for_cssom(url_data, Some(CssRuleType::Media),
let context = ParserContext::new_for_cssom(url_data, &reporter, Some(CssRuleType::Media),
PARSING_MODE_DEFAULT, PARSING_MODE_DEFAULT,
QuirksMode::NoQuirks); QuirksMode::NoQuirks);
write_locked_arc(list, |list: &mut MediaList| list.delete_medium(&context, old_medium)) write_locked_arc(list, |list: &mut MediaList| list.delete_medium(&context, old_medium))
@ -2783,8 +2781,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetBackgroundImage(declarations:
let url_data = unsafe { RefPtr::from_ptr_ref(&raw_extra_data) }; let url_data = unsafe { RefPtr::from_ptr_ref(&raw_extra_data) };
let string = unsafe { (*value).to_string() }; let string = unsafe { (*value).to_string() };
let error_reporter = NullReporter; let context = ParserContext::new(Origin::Author, url_data,
let context = ParserContext::new(Origin::Author, url_data, &error_reporter,
Some(CssRuleType::Style), PARSING_MODE_DEFAULT, Some(CssRuleType::Style), PARSING_MODE_DEFAULT,
QuirksMode::NoQuirks); QuirksMode::NoQuirks);
if let Ok(mut url) = SpecifiedUrl::parse_from_string(string.into(), &context) { if let Ok(mut url) = SpecifiedUrl::parse_from_string(string.into(), &context) {
@ -2837,13 +2834,11 @@ pub extern "C" fn Servo_CSSSupports(cond: *const nsACString) -> bool {
let cond = input.parse_entirely(|i| parse_condition_or_declaration(i)); let cond = input.parse_entirely(|i| parse_condition_or_declaration(i));
if let Ok(cond) = cond { if let Ok(cond) = cond {
let url_data = unsafe { dummy_url_data() }; let url_data = unsafe { dummy_url_data() };
let reporter = NullReporter;
// NOTE(emilio): The supports API is not associated to any stylesheet, // NOTE(emilio): The supports API is not associated to any stylesheet,
// so the fact that there are no namespace map here is fine. // so the fact that there are no namespace map here is fine.
let context = let context =
ParserContext::new_for_cssom( ParserContext::new_for_cssom(
url_data, url_data,
&reporter,
Some(CssRuleType::Style), Some(CssRuleType::Style),
PARSING_MODE_DEFAULT, PARSING_MODE_DEFAULT,
QuirksMode::NoQuirks, QuirksMode::NoQuirks,

View file

@ -3,7 +3,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use cssparser::{Parser, ParserInput}; use cssparser::{Parser, ParserInput};
use media_queries::CSSErrorReporterTest;
use parsing::parse; use parsing::parse;
use style::context::QuirksMode; use style::context::QuirksMode;
use style::parser::{Parse, ParserContext}; use style::parser::{Parse, ParserContext};
@ -41,8 +40,7 @@ fn test_parsing_modes() {
// In SVG length mode, non-zero lengths are assumed to be px. // In SVG length mode, non-zero lengths are assumed to be px.
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap(); let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
let reporter = CSSErrorReporterTest; let context = ParserContext::new(Origin::Author, &url,
let context = ParserContext::new(Origin::Author, &url, &reporter,
Some(CssRuleType::Style), PARSING_MODE_ALLOW_UNITLESS_LENGTH, Some(CssRuleType::Style), PARSING_MODE_ALLOW_UNITLESS_LENGTH,
QuirksMode::NoQuirks); QuirksMode::NoQuirks);
let mut input = ParserInput::new("1"); let mut input = ParserInput::new("1");

View file

@ -5,7 +5,6 @@
//! Tests for parsing and serialization of values/properties //! Tests for parsing and serialization of values/properties
use cssparser::{Parser, ParserInput}; use cssparser::{Parser, ParserInput};
use media_queries::CSSErrorReporterTest;
use style::context::QuirksMode; use style::context::QuirksMode;
use style::parser::ParserContext; use style::parser::ParserContext;
use style::stylesheets::{CssRuleType, Origin}; use style::stylesheets::{CssRuleType, Origin};
@ -20,8 +19,7 @@ where F: for<'t> Fn(&ParserContext, &mut Parser<'static, 't>) -> Result<T, Parse
fn parse_input<'i: 't, 't, T, F>(f: F, input: &'t mut ParserInput<'i>) -> Result<T, ParseError<'i>> fn parse_input<'i: 't, 't, T, F>(f: F, input: &'t mut ParserInput<'i>) -> Result<T, ParseError<'i>>
where F: Fn(&ParserContext, &mut Parser<'i, 't>) -> Result<T, ParseError<'i>> { where F: Fn(&ParserContext, &mut Parser<'i, 't>) -> Result<T, ParseError<'i>> {
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap(); let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
let reporter = CSSErrorReporterTest; let context = ParserContext::new(Origin::Author, &url, Some(CssRuleType::Style),
let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style),
PARSING_MODE_DEFAULT, PARSING_MODE_DEFAULT,
QuirksMode::NoQuirks); QuirksMode::NoQuirks);
let mut parser = Parser::new(input); let mut parser = Parser::new(input);

View file

@ -4,7 +4,6 @@
use app_units::Au; use app_units::Au;
use cssparser::{Parser, ParserInput}; use cssparser::{Parser, ParserInput};
use media_queries::CSSErrorReporterTest;
use style::context::QuirksMode; use style::context::QuirksMode;
use style::parser::ParserContext; use style::parser::ParserContext;
use style::stylesheets::{CssRuleType, Origin}; use style::stylesheets::{CssRuleType, Origin};
@ -23,8 +22,7 @@ fn length_has_viewport_percentage() {
fn test_parsing_allo_all_numeric_values() { fn test_parsing_allo_all_numeric_values() {
// In SVG length mode, non-zero lengths are assumed to be px. // In SVG length mode, non-zero lengths are assumed to be px.
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap(); let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
let reporter = CSSErrorReporterTest; let context = ParserContext::new(Origin::Author, &url,
let context = ParserContext::new(Origin::Author, &url, &reporter,
Some(CssRuleType::Style), PARSING_MODE_ALLOW_ALL_NUMERIC_VALUES, Some(CssRuleType::Style), PARSING_MODE_ALLOW_ALL_NUMERIC_VALUES,
QuirksMode::NoQuirks); QuirksMode::NoQuirks);
let mut input = ParserInput::new("-1"); let mut input = ParserInput::new("-1");

View file

@ -7,5 +7,5 @@ use style::properties::longhands::background_size;
#[test] #[test]
fn background_size_should_reject_negative_values() { fn background_size_should_reject_negative_values() {
assert!(parse(background_size::parse, "-40% -40%").is_err()); assert!(parse(|c, _, i| background_size::parse(c, i), "-40% -40%").is_err());
} }

View file

@ -5,25 +5,32 @@
use cssparser::{Parser, ParserInput}; use cssparser::{Parser, ParserInput};
use media_queries::CSSErrorReporterTest; use media_queries::CSSErrorReporterTest;
use style::context::QuirksMode; use style::context::QuirksMode;
use style::parser::ParserContext; use style::parser::{ParserContext, ParserErrorContext};
use style::stylesheets::{CssRuleType, Origin}; use style::stylesheets::{CssRuleType, Origin};
use style_traits::{PARSING_MODE_DEFAULT, ParseError}; use style_traits::{PARSING_MODE_DEFAULT, ParseError};
fn parse<T, F>(f: F, s: &'static str) -> Result<T, ParseError<'static>> fn parse<T, F>(f: F, s: &'static str) -> Result<T, ParseError<'static>>
where F: for<'t> Fn(&ParserContext, &mut Parser<'static, 't>) -> Result<T, ParseError<'static>> { where F: for<'t> Fn(&ParserContext,
&ParserErrorContext<CSSErrorReporterTest>,
&mut Parser<'static, 't>) -> Result<T, ParseError<'static>>
{
let mut input = ParserInput::new(s); let mut input = ParserInput::new(s);
parse_input(f, &mut input) parse_input(f, &mut input)
} }
fn parse_input<'i: 't, 't, T, F>(f: F, input: &'t mut ParserInput<'i>) -> Result<T, ParseError<'i>> fn parse_input<'i: 't, 't, T, F>(f: F, input: &'t mut ParserInput<'i>) -> Result<T, ParseError<'i>>
where F: Fn(&ParserContext, &mut Parser<'i, 't>) -> Result<T, ParseError<'i>> { where F: Fn(&ParserContext,
&ParserErrorContext<CSSErrorReporterTest>,
&mut Parser<'i, 't>) -> Result<T, ParseError<'i>>
{
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap(); let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
let reporter = CSSErrorReporterTest; let context = ParserContext::new(Origin::Author, &url, Some(CssRuleType::Style),
let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style),
PARSING_MODE_DEFAULT, PARSING_MODE_DEFAULT,
QuirksMode::NoQuirks); QuirksMode::NoQuirks);
let reporter = CSSErrorReporterTest;
let error_context = ParserErrorContext { error_reporter: &reporter };
let mut parser = Parser::new(input); let mut parser = Parser::new(input);
f(&context, &mut parser) f(&context, &error_context, &mut parser)
} }
macro_rules! assert_roundtrip_with_context { macro_rules! assert_roundtrip_with_context {
@ -31,7 +38,7 @@ macro_rules! assert_roundtrip_with_context {
assert_roundtrip_with_context!($fun, $string, $string); assert_roundtrip_with_context!($fun, $string, $string);
}; };
($fun:expr, $input:expr, $output:expr) => {{ ($fun:expr, $input:expr, $output:expr) => {{
let serialized = parse(|context, i| { let serialized = parse(|context, _, i| {
let parsed = $fun(context, i) let parsed = $fun(context, i)
.expect(&format!("Failed to parse {}", $input)); .expect(&format!("Failed to parse {}", $input));
let serialized = ToCss::to_css_string(&parsed); let serialized = ToCss::to_css_string(&parsed);
@ -40,7 +47,7 @@ macro_rules! assert_roundtrip_with_context {
}, $input).unwrap(); }, $input).unwrap();
let mut input = ::cssparser::ParserInput::new(&serialized); let mut input = ::cssparser::ParserInput::new(&serialized);
let unwrapped = parse_input(|context, i| { let unwrapped = parse_input(|context, _, i| {
let re_parsed = $fun(context, i) let re_parsed = $fun(context, i)
.expect(&format!("Failed to parse serialization {}", $input)); .expect(&format!("Failed to parse serialization {}", $input));
let re_serialized = ToCss::to_css_string(&re_parsed); let re_serialized = ToCss::to_css_string(&re_parsed);

View file

@ -426,7 +426,7 @@ mod shorthand_serialization {
border-left: 4px solid; \ border-left: 4px solid; \
border-image: none;"; border-image: none;";
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
let serialization = block.to_css_string(); let serialization = block.to_css_string();
@ -568,7 +568,7 @@ mod shorthand_serialization {
background-origin: border-box; \ background-origin: border-box; \
background-clip: padding-box;"; background-clip: padding-box;";
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
let serialization = block.to_css_string(); let serialization = block.to_css_string();
@ -592,7 +592,7 @@ mod shorthand_serialization {
background-origin: padding-box; \ background-origin: padding-box; \
background-clip: padding-box;"; background-clip: padding-box;";
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
let serialization = block.to_css_string(); let serialization = block.to_css_string();
@ -616,7 +616,7 @@ mod shorthand_serialization {
background-origin: border-box, padding-box; \ background-origin: border-box, padding-box; \
background-clip: padding-box, padding-box;"; background-clip: padding-box, padding-box;";
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
let serialization = block.to_css_string(); let serialization = block.to_css_string();
@ -647,7 +647,7 @@ mod shorthand_serialization {
background-origin: border-box; \ background-origin: border-box; \
background-clip: padding-box, padding-box;"; background-clip: padding-box, padding-box;";
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
let serialization = block.to_css_string(); let serialization = block.to_css_string();
@ -661,7 +661,7 @@ mod shorthand_serialization {
let block_text = "\ let block_text = "\
background-position-x: 30px;\ background-position-x: 30px;\
background-position-y: bottom 20px;"; background-position-y: bottom 20px;";
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
let serialization = block.to_css_string(); let serialization = block.to_css_string();
assert_eq!(serialization, "background-position: left 30px bottom 20px;"); assert_eq!(serialization, "background-position: left 30px bottom 20px;");
@ -670,7 +670,7 @@ mod shorthand_serialization {
let block_text = "\ let block_text = "\
background-position-x: center;\ background-position-x: center;\
background-position-y: 20px;"; background-position-y: 20px;";
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
let serialization = block.to_css_string(); let serialization = block.to_css_string();
assert_eq!(serialization, "background-position: center 20px;"); assert_eq!(serialization, "background-position: center 20px;");
} }
@ -755,7 +755,7 @@ mod shorthand_serialization {
animation-iteration-count: infinite;\ animation-iteration-count: infinite;\
animation-play-state: paused;"; animation-play-state: paused;";
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
let serialization = block.to_css_string(); let serialization = block.to_css_string();
@ -774,7 +774,7 @@ mod shorthand_serialization {
animation-iteration-count: infinite, 2;\ animation-iteration-count: infinite, 2;\
animation-play-state: paused, running;"; animation-play-state: paused, running;";
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
let serialization = block.to_css_string(); let serialization = block.to_css_string();
@ -800,7 +800,7 @@ mod shorthand_serialization {
animation-iteration-count: infinite, 2; \ animation-iteration-count: infinite, 2; \
animation-play-state: paused, running;"; animation-play-state: paused, running;";
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
let serialization = block.to_css_string(); let serialization = block.to_css_string();
@ -817,7 +817,7 @@ mod shorthand_serialization {
animation-iteration-count: infinite, 2; \ animation-iteration-count: infinite, 2; \
animation-play-state: paused, running;"; animation-play-state: paused, running;";
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
let serialization = block.to_css_string(); let serialization = block.to_css_string();
@ -835,7 +835,7 @@ mod shorthand_serialization {
transition-delay: 4s; \ transition-delay: 4s; \
transition-timing-function: cubic-bezier(0.2, 5, 0.5, 2);"; transition-timing-function: cubic-bezier(0.2, 5, 0.5, 2);";
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
let serialization = block.to_css_string(); let serialization = block.to_css_string();
@ -849,7 +849,7 @@ mod shorthand_serialization {
transition-delay: 4s, 5s; \ transition-delay: 4s, 5s; \
transition-timing-function: cubic-bezier(0.2, 5, 0.5, 2), ease;"; transition-timing-function: cubic-bezier(0.2, 5, 0.5, 2), ease;";
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
let serialization = block.to_css_string(); let serialization = block.to_css_string();
@ -871,7 +871,7 @@ mod shorthand_serialization {
transition-delay: 4s, 5s; \ transition-delay: 4s, 5s; \
transition-timing-function: cubic-bezier(0.2, 5, 0.5, 2), ease;"; transition-timing-function: cubic-bezier(0.2, 5, 0.5, 2), ease;";
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
let serialization = block.to_css_string(); let serialization = block.to_css_string();
@ -884,7 +884,7 @@ mod shorthand_serialization {
transition-duration: 3s; \ transition-duration: 3s; \
transition-delay: 4s; \ transition-delay: 4s; \
transition-timing-function: steps(2, start);"; transition-timing-function: steps(2, start);";
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
let serialization = block.to_css_string(); let serialization = block.to_css_string();
@ -897,7 +897,7 @@ mod shorthand_serialization {
transition-duration: 3s; \ transition-duration: 3s; \
transition-delay: 4s; \ transition-delay: 4s; \
transition-timing-function: frames(2);"; transition-timing-function: frames(2);";
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
let serialization = block.to_css_string(); let serialization = block.to_css_string();
@ -910,7 +910,7 @@ mod shorthand_serialization {
#[test] #[test]
fn css_wide_keywords_should_be_parsed() { fn css_wide_keywords_should_be_parsed() {
let block_text = "--a:inherit;"; let block_text = "--a:inherit;";
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
let serialization = block.to_css_string(); let serialization = block.to_css_string();
assert_eq!(serialization, "--a: inherit;"); assert_eq!(serialization, "--a: inherit;");
@ -919,7 +919,7 @@ mod shorthand_serialization {
#[test] #[test]
fn non_keyword_custom_property_should_be_unparsed() { fn non_keyword_custom_property_should_be_unparsed() {
let block_text = "--main-color: #06c;"; let block_text = "--main-color: #06c;";
let block = parse(|c, i| Ok(parse_property_declaration_list(c, i)), block_text).unwrap(); let block = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), block_text).unwrap();
let serialization = block.to_css_string(); let serialization = block.to_css_string();
assert_eq!(serialization, block_text); assert_eq!(serialization, block_text);
@ -949,7 +949,7 @@ mod shorthand_serialization {
let shadow_decl = BoxShadowList(vec![shadow_val]); let shadow_decl = BoxShadowList(vec![shadow_val]);
properties.push(PropertyDeclaration::BoxShadow(shadow_decl)); properties.push(PropertyDeclaration::BoxShadow(shadow_decl));
let shadow_css = "box-shadow: 1px 2px 3px 4px;"; let shadow_css = "box-shadow: 1px 2px 3px 4px;";
let shadow = parse(|c, i| Ok(parse_property_declaration_list(c, i)), shadow_css).unwrap(); let shadow = parse(|c, e, i| Ok(parse_property_declaration_list(c, e, i)), shadow_css).unwrap();
assert_eq!(shadow.to_css_string(), shadow_css); assert_eq!(shadow.to_css_string(), shadow_css);
} }

View file

@ -11,7 +11,7 @@ use servo_config::prefs::{PREFS, PrefValue};
use servo_url::ServoUrl; use servo_url::ServoUrl;
use style::context::QuirksMode; use style::context::QuirksMode;
use style::media_queries::{Device, MediaList, MediaType}; use style::media_queries::{Device, MediaList, MediaType};
use style::parser::{Parse, ParserContext}; use style::parser::{Parse, ParserContext, ParserErrorContext};
use style::shared_lock::SharedRwLock; use style::shared_lock::SharedRwLock;
use style::stylesheets::{CssRuleType, Stylesheet, StylesheetInDocument, Origin}; use style::stylesheets::{CssRuleType, Stylesheet, StylesheetInDocument, Origin};
use style::stylesheets::viewport_rule::*; use style::stylesheets::viewport_rule::*;
@ -302,14 +302,14 @@ fn multiple_stylesheets_cascading() {
#[test] #[test]
fn constrain_viewport() { fn constrain_viewport() {
let url = ServoUrl::parse("http://localhost").unwrap(); let url = ServoUrl::parse("http://localhost").unwrap();
let reporter = CSSErrorReporterTest; let context = ParserContext::new(Origin::Author, &url, Some(CssRuleType::Viewport),
let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Viewport),
PARSING_MODE_DEFAULT, PARSING_MODE_DEFAULT,
QuirksMode::NoQuirks); QuirksMode::NoQuirks);
let error_context = ParserErrorContext { error_reporter: &CSSErrorReporterTest };
macro_rules! from_css { macro_rules! from_css {
($css:expr) => { ($css:expr) => {
&ViewportRule::parse(&context, &mut Parser::new(&mut $css)).unwrap() &ViewportRule::parse(&context, &error_context, &mut Parser::new(&mut $css)).unwrap()
} }
} }