mirror of
https://github.com/servo/servo.git
synced 2025-08-16 19:05:33 +01:00
Devirtualize CSS error reporting.
This commit is contained in:
parent
2e775abfa4
commit
1297c0ff51
28 changed files with 255 additions and 211 deletions
|
@ -5,25 +5,32 @@
|
|||
use cssparser::{Parser, ParserInput};
|
||||
use media_queries::CSSErrorReporterTest;
|
||||
use style::context::QuirksMode;
|
||||
use style::parser::ParserContext;
|
||||
use style::parser::{ParserContext, ParserErrorContext};
|
||||
use style::stylesheets::{CssRuleType, Origin};
|
||||
use style_traits::{PARSING_MODE_DEFAULT, ParseError};
|
||||
|
||||
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);
|
||||
parse_input(f, &mut input)
|
||||
}
|
||||
|
||||
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 reporter = CSSErrorReporterTest;
|
||||
let context = ParserContext::new(Origin::Author, &url, &reporter, Some(CssRuleType::Style),
|
||||
let context = ParserContext::new(Origin::Author, &url, Some(CssRuleType::Style),
|
||||
PARSING_MODE_DEFAULT,
|
||||
QuirksMode::NoQuirks);
|
||||
let reporter = CSSErrorReporterTest;
|
||||
let error_context = ParserErrorContext { error_reporter: &reporter };
|
||||
let mut parser = Parser::new(input);
|
||||
f(&context, &mut parser)
|
||||
f(&context, &error_context, &mut parser)
|
||||
}
|
||||
|
||||
macro_rules! assert_roundtrip_with_context {
|
||||
|
@ -31,7 +38,7 @@ macro_rules! assert_roundtrip_with_context {
|
|||
assert_roundtrip_with_context!($fun, $string, $string);
|
||||
};
|
||||
($fun:expr, $input:expr, $output:expr) => {{
|
||||
let serialized = parse(|context, i| {
|
||||
let serialized = parse(|context, _, i| {
|
||||
let parsed = $fun(context, i)
|
||||
.expect(&format!("Failed to parse {}", $input));
|
||||
let serialized = ToCss::to_css_string(&parsed);
|
||||
|
@ -40,7 +47,7 @@ macro_rules! assert_roundtrip_with_context {
|
|||
}, $input).unwrap();
|
||||
|
||||
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)
|
||||
.expect(&format!("Failed to parse serialization {}", $input));
|
||||
let re_serialized = ToCss::to_css_string(&re_parsed);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue