style: Avoid cloning all over the error reporter.

This commit is contained in:
Emilio Cobos Álvarez 2017-03-14 00:12:38 +01:00
parent eaf27ccfa0
commit b4de69e3eb
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
36 changed files with 186 additions and 154 deletions

View file

@ -21,10 +21,6 @@ impl ParseErrorReporter for CSSErrorReporterTest {
fn report_error(&self, _input: &mut Parser, _position: SourcePosition, _message: &str,
_url: &ServoUrl) {
}
fn clone(&self) -> Box<ParseErrorReporter + Send + Sync> {
Box::new(CSSErrorReporterTest)
}
}
fn test_media_rule<F>(css: &str, callback: F)
@ -34,7 +30,7 @@ fn test_media_rule<F>(css: &str, callback: F)
let css_str = css.to_owned();
let stylesheet = Stylesheet::from_str(
css, url, Origin::Author, Default::default(),
None, Box::new(CSSErrorReporterTest),
None, &CSSErrorReporterTest,
ParserContextExtraData::default());
let mut rule_count = 0;
media_queries(&stylesheet.rules.read().0, &mut |mq| {
@ -61,7 +57,7 @@ fn media_query_test(device: &Device, css: &str, expected_rule_count: usize) {
let url = ServoUrl::parse("http://localhost").unwrap();
let ss = Stylesheet::from_str(
css, url, Origin::Author, Default::default(),
None, Box::new(CSSErrorReporterTest),
None, &CSSErrorReporterTest,
ParserContextExtraData::default());
let mut rule_count = 0;
ss.effective_style_rules(device, |_| rule_count += 1);

View file

@ -15,7 +15,8 @@ use style::stylesheets::Origin;
#[test]
fn background_shorthand_should_parse_all_available_properties_when_specified() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new("url(\"http://servo/test.png\") top center / 200px 200px repeat-x fixed padding-box \
content-box red");
let result = background::parse_value(&context, &mut parser).unwrap();
@ -34,7 +35,8 @@ fn background_shorthand_should_parse_all_available_properties_when_specified() {
#[test]
fn background_shorthand_should_parse_when_some_fields_set() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new("14px 40px repeat-y");
let result = background::parse_value(&context, &mut parser).unwrap();
@ -64,7 +66,8 @@ fn background_shorthand_should_parse_when_some_fields_set() {
#[test]
fn background_shorthand_should_parse_comma_separated_declarations() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new("url(\"http://servo/test.png\") top left no-repeat, url(\"http://servo/test.png\") \
center / 100% 100% no-repeat, white");
let result = background::parse_value(&context, &mut parser).unwrap();
@ -85,7 +88,8 @@ fn background_shorthand_should_parse_comma_separated_declarations() {
#[test]
fn background_shorthand_should_parse_position_and_size_correctly() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new("7px 4px");
let result = background::parse_value(&context, &mut parser).unwrap();
@ -109,7 +113,8 @@ fn background_shorthand_should_parse_position_and_size_correctly() {
#[test]
fn background_shorthand_should_parse_origin_and_clip_correctly() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new("padding-box content-box");
let result = background::parse_value(&context, &mut parser).unwrap();

View file

@ -15,7 +15,8 @@ use style_traits::ToCss;
#[test]
fn border_image_shorthand_should_parse_when_all_properties_specified() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new("linear-gradient(red, blue) 30 30% 45 fill / 20px 40px / 10px \
round stretch");
let result = border_image::parse_value(&context, &mut parser).unwrap();
@ -31,7 +32,8 @@ fn border_image_shorthand_should_parse_when_all_properties_specified() {
#[test]
fn border_image_shorthand_should_parse_without_width() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new("linear-gradient(red, blue) 30 30% 45 fill / / 10px round stretch");
let result = border_image::parse_value(&context, &mut parser).unwrap();
@ -46,7 +48,8 @@ fn border_image_shorthand_should_parse_without_width() {
#[test]
fn border_image_shorthand_should_parse_without_outset() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new("linear-gradient(red, blue) 30 30% 45 fill / 20px 40px round");
let result = border_image::parse_value(&context, &mut parser).unwrap();
@ -61,7 +64,8 @@ fn border_image_shorthand_should_parse_without_outset() {
#[test]
fn border_image_shorthand_should_parse_without_width_or_outset() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new("linear-gradient(red, blue) 30 30% 45 fill round");
let result = border_image::parse_value(&context, &mut parser).unwrap();
@ -76,7 +80,8 @@ fn border_image_shorthand_should_parse_without_width_or_outset() {
#[test]
fn border_image_shorthand_should_parse_with_just_source() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new("linear-gradient(red, blue)");
let result = border_image::parse_value(&context, &mut parser).unwrap();
@ -91,7 +96,8 @@ fn border_image_shorthand_should_parse_with_just_source() {
#[test]
fn border_image_outset_should_error_on_negative_length() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new("-1em");
let result = border_image_outset::parse(&context, &mut parser);
assert_eq!(result, Err(()));
@ -100,7 +106,8 @@ fn border_image_outset_should_error_on_negative_length() {
#[test]
fn border_image_outset_should_error_on_negative_number() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new("-15");
let result = border_image_outset::parse(&context, &mut parser);
assert_eq!(result, Err(()));
@ -109,7 +116,8 @@ fn border_image_outset_should_error_on_negative_number() {
#[test]
fn border_image_outset_should_return_number_on_plain_zero() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new("0");
let result = border_image_outset::parse(&context, &mut parser);
assert_eq!(result.unwrap(), parse_longhand!(border_image_outset, "0"));
@ -118,7 +126,8 @@ fn border_image_outset_should_return_number_on_plain_zero() {
#[test]
fn border_image_outset_should_return_length_on_length_zero() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new("0em");
let result = border_image_outset::parse(&context, &mut parser);
assert_eq!(result.unwrap(), parse_longhand!(border_image_outset, "0em"));

View file

@ -19,7 +19,8 @@ fn test_column_width() {
assert_roundtrip_with_context!(column_width::parse, "0.3vw");
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut negative = Parser::new("-6px");
assert!(column_width::parse(&context, &mut negative).is_err());
@ -35,7 +36,8 @@ fn test_column_gap() {
assert_roundtrip_with_context!(column_gap::parse, "0.3vw");
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut negative = Parser::new("-6px");
assert!(column_gap::parse(&context, &mut negative).is_err());

View file

@ -38,7 +38,8 @@ fn test_clip() {
#[test]
fn test_longhands_parse_origin() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new("1px some-rubbish");
let parsed = longhands::parse_origin(&context, &mut parser);

View file

@ -53,7 +53,8 @@ fn font_feature_settings_should_parse_properly() {
#[test]
fn font_feature_settings_should_throw_on_bad_input() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut empty = Parser::new("");
assert!(font_feature_settings::parse(&context, &mut empty).is_err());
@ -103,7 +104,8 @@ fn font_weight_keyword_should_preserve_keyword() {
use style::properties::longhands::font_weight::SpecifiedValue;
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new("normal");
let result = font_weight::parse(&context, &mut parser);
assert_eq!(result.unwrap(), SpecifiedValue::Normal);

View file

@ -111,7 +111,8 @@ fn webkit_text_stroke_shorthand_should_parse_properly() {
use style::properties::shorthands::_webkit_text_stroke;
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new("thin red");
let result = _webkit_text_stroke::parse_value(&context, &mut parser).unwrap();
@ -132,7 +133,8 @@ fn line_height_should_return_number_on_plain_zero() {
use style::properties::longhands::line_height;
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new("0");
let result = line_height::parse(&context, &mut parser);
assert_eq!(result.unwrap(), parse_longhand!(line_height, "0"));
@ -145,7 +147,8 @@ fn line_height_should_return_length_on_length_zero() {
use style::properties::longhands::line_height;
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new("0px");
let result = line_height::parse(&context, &mut parser);
assert_eq!(result.unwrap(), parse_longhand!(line_height, "0px"));

View file

@ -14,7 +14,8 @@ use style::stylesheets::Origin;
#[test]
fn mask_shorthand_should_parse_all_available_properties_when_specified() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new("url(\"http://servo/test.png\") luminance 7px 4px / 70px 50px \
repeat-x padding-box border-box subtract");
let result = mask::parse_value(&context, &mut parser).unwrap();
@ -33,7 +34,8 @@ fn mask_shorthand_should_parse_all_available_properties_when_specified() {
#[test]
fn mask_shorthand_should_parse_when_some_fields_set() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new("14px 40px repeat-y");
let result = mask::parse_value(&context, &mut parser).unwrap();
@ -62,7 +64,8 @@ fn mask_shorthand_should_parse_when_some_fields_set() {
#[test]
fn mask_shorthand_should_parse_position_and_size_correctly() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new("7px 4px");
let result = mask::parse_value(&context, &mut parser).unwrap();
@ -86,7 +89,8 @@ fn mask_shorthand_should_parse_position_and_size_correctly() {
#[test]
fn mask_shorthand_should_parse_origin_and_clip_correctly() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new("padding-box content-box");
let result = mask::parse_value(&context, &mut parser).unwrap();
@ -109,7 +113,8 @@ fn mask_shorthand_should_parse_origin_and_clip_correctly() {
#[test]
fn mask_shorthand_should_parse_mode_everywhere() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new("luminance 7px 4px repeat-x padding-box");
assert!(mask::parse_value(&context, &mut parser).is_ok());

View file

@ -11,7 +11,8 @@ use style::stylesheets::Origin;
fn parse<T, F: Fn(&ParserContext, &mut Parser) -> Result<T, ()>>(f: F, s: &str) -> Result<T, ()> {
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new(s);
f(&context, &mut parser)
}
@ -24,7 +25,8 @@ macro_rules! assert_roundtrip_with_context {
};
($fun:expr,$input:expr, $output:expr) => {
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new($input);
let parsed = $fun(&context, &mut parser)
.expect(&format!("Failed to parse {}", $input));
@ -61,7 +63,8 @@ macro_rules! assert_roundtrip {
macro_rules! assert_parser_exhausted {
($name:ident, $string:expr, $should_exhausted:expr) => {{
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new($string);
let parsed = $name::parse(&context, &mut parser);
assert_eq!(parsed.is_ok(), true);
@ -72,7 +75,8 @@ macro_rules! assert_parser_exhausted {
macro_rules! parse_longhand {
($name:ident, $s:expr) => {{
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
$name::parse(&context, &mut Parser::new($s)).unwrap()
}};
}

View file

@ -28,7 +28,8 @@ fn test_outline_style() {
// except that 'hidden' is not a legal outline style.
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new(r#"hidden"#);
let parsed = outline_style::parse(&context, &mut parser);
assert!(parsed.is_err());

View file

@ -27,7 +27,8 @@ fn test_moz_user_select() {
assert_roundtrip_with_context!(_moz_user_select::parse, "-moz-text");
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut negative = Parser::new("potato");
assert!(_moz_user_select::parse(&context, &mut negative).is_err());

View file

@ -11,7 +11,8 @@ use style::stylesheets::Origin;
#[test]
fn background_size_should_reject_negative_values() {
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let parse_result = background_size::parse(&context, &mut Parser::new("-40% -40%"));

View file

@ -21,7 +21,8 @@ use stylesheets::block_from;
fn parse_declaration_block(css_properties: &str) -> PropertyDeclarationBlock {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let mut parser = Parser::new(css_properties);
parse_property_declaration_list(&context, &mut parser)
}
@ -963,7 +964,8 @@ mod shorthand_serialization {
let mut s = String::new();
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let parsed = transform::parse(&context, &mut Parser::new("none")).unwrap();
let try_serialize = parsed.to_css(&mut s);
@ -986,7 +988,8 @@ mod shorthand_serialization {
let mut s = String::new();
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
let parsed = quotes::parse(&context, &mut Parser::new("none")).unwrap();
let try_serialize = parsed.to_css(&mut s);

View file

@ -21,10 +21,6 @@ impl ParseErrorReporter for ErrorringErrorReporter {
url: &ServoUrl) {
panic!("CSS error: {}\t\n{:?} {}", url.as_str(), position, message);
}
fn clone(&self) -> Box<ParseErrorReporter + Send + Sync> {
Box::new(ErrorringErrorReporter)
}
}
struct AutoGCRuleTree<'a>(&'a RuleTree);
@ -49,7 +45,7 @@ fn parse_rules(css: &str) -> Vec<(StyleSource, CascadeLevel)> {
media_queries: vec![],
},
None,
Box::new(ErrorringErrorReporter),
&ErrorringErrorReporter,
ParserContextExtraData {});
let rules = s.rules.read();
rules.0.iter().filter_map(|rule| {

View file

@ -63,7 +63,7 @@ fn test_parse_stylesheet() {
let url = ServoUrl::parse("about::test").unwrap();
let stylesheet = Stylesheet::from_str(css, url.clone(), Origin::UserAgent, Default::default(),
None,
Box::new(CSSErrorReporterTest),
&CSSErrorReporterTest,
ParserContextExtraData::default());
let mut namespaces = Namespaces::default();
namespaces.default = Some(ns!(html));
@ -289,13 +289,15 @@ impl CSSInvalidErrorReporterTest {
}
impl ParseErrorReporter for CSSInvalidErrorReporterTest {
fn report_error(&self, input: &mut CssParser, position: SourcePosition, message: &str,
url: &ServoUrl) {
fn report_error(&self,
input: &mut CssParser,
position: SourcePosition,
message: &str,
url: &ServoUrl) {
let location = input.source_location(position);
let errors = self.errors.clone();
let mut errors = errors.lock().unwrap();
let mut errors = self.errors.lock().unwrap();
errors.push(
CSSError{
@ -306,14 +308,6 @@ impl ParseErrorReporter for CSSInvalidErrorReporterTest {
}
);
}
fn clone(&self) -> Box<ParseErrorReporter + Send + Sync> {
return Box::new(
CSSInvalidErrorReporterTest{
errors: self.errors.clone()
}
);
}
}
@ -327,13 +321,13 @@ fn test_report_error_stylesheet() {
}
";
let url = ServoUrl::parse("about::test").unwrap();
let error_reporter = Box::new(CSSInvalidErrorReporterTest::new());
let error_reporter = CSSInvalidErrorReporterTest::new();
let errors = error_reporter.errors.clone();
Stylesheet::from_str(css, url.clone(), Origin::UserAgent, Default::default(),
None,
error_reporter,
&error_reporter,
ParserContextExtraData::default());
let mut errors = errors.lock().unwrap();

View file

@ -7,7 +7,6 @@ use euclid::size::TypedSize2D;
use media_queries::CSSErrorReporterTest;
use servo_config::prefs::{PREFS, PrefValue};
use servo_url::ServoUrl;
use style::error_reporting::ParseErrorReporter;
use style::media_queries::{Device, MediaType};
use style::parser::{ParserContext, ParserContextExtraData};
use style::stylesheets::{Stylesheet, Origin};
@ -26,7 +25,7 @@ macro_rules! stylesheet {
Origin::$origin,
Default::default(),
None,
$error_reporter,
&$error_reporter,
ParserContextExtraData::default()
))
}
@ -38,7 +37,7 @@ fn test_viewport_rule<F>(css: &str,
where F: Fn(&Vec<ViewportDescriptorDeclaration>, &str)
{
PREFS.set("layout.viewport.enabled", PrefValue::Boolean(true));
let stylesheet = stylesheet!(css, Author, Box::new(CSSErrorReporterTest));
let stylesheet = stylesheet!(css, Author, CSSErrorReporterTest);
let mut rule_count = 0;
stylesheet.effective_viewport_rules(&device, |rule| {
rule_count += 1;
@ -253,9 +252,9 @@ fn multiple_stylesheets_cascading() {
let device = Device::new(MediaType::Screen, TypedSize2D::new(800., 600.));
let error_reporter = CSSErrorReporterTest;
let stylesheets = vec![
stylesheet!("@viewport { min-width: 100px; min-height: 100px; zoom: 1; }", UserAgent, error_reporter.clone()),
stylesheet!("@viewport { min-width: 200px; min-height: 200px; }", User, error_reporter.clone()),
stylesheet!("@viewport { min-width: 300px; }", Author, error_reporter.clone())];
stylesheet!("@viewport { min-width: 100px; min-height: 100px; zoom: 1; }", UserAgent, error_reporter),
stylesheet!("@viewport { min-width: 200px; min-height: 200px; }", User, error_reporter),
stylesheet!("@viewport { min-width: 300px; }", Author, error_reporter)];
let declarations = Cascade::from_stylesheets(&stylesheets, &device).finish();
assert_decl_len!(declarations == 3);
@ -264,11 +263,11 @@ fn multiple_stylesheets_cascading() {
assert_decl_eq!(&declarations[2], Author, MinWidth: viewport_length!(300., px));
let stylesheets = vec![
stylesheet!("@viewport { min-width: 100px !important; }", UserAgent, error_reporter.clone()),
stylesheet!("@viewport { min-width: 100px !important; }", UserAgent, error_reporter),
stylesheet!("@viewport { min-width: 200px !important; min-height: 200px !important; }",
User, error_reporter.clone()),
User, error_reporter),
stylesheet!("@viewport { min-width: 300px !important; min-height: 300px !important; zoom: 3 !important; }",
Author, error_reporter.clone())];
Author, error_reporter)];
let declarations = Cascade::from_stylesheets(&stylesheets, &device).finish();
assert_decl_len!(declarations == 3);
assert_decl_eq!(&declarations[0], UserAgent, MinWidth: viewport_length!(100., px), !important);
@ -279,7 +278,8 @@ fn multiple_stylesheets_cascading() {
#[test]
fn constrain_viewport() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest));
let reporter = CSSErrorReporterTest;
let context = ParserContext::new(Origin::Author, &url, &reporter);
macro_rules! from_css {
($css:expr) => {