From b4de69e3ebf5b2a6e82b68b66df090e9220b9e61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 14 Mar 2017 00:12:38 +0100 Subject: [PATCH] style: Avoid cloning all over the error reporter. --- components/layout_thread/lib.rs | 9 +++---- components/script/dom/css.rs | 4 +-- components/script/dom/csssupportsrule.rs | 6 +++-- components/script/dom/window.rs | 4 +-- .../script_layout_interface/reporter.rs | 22 +++++++-------- components/style/animation.rs | 2 +- components/style/context.rs | 2 +- components/style/error_reporting.rs | 23 ++++++++-------- components/style/gecko/wrapper.rs | 2 +- components/style/keyframes.rs | 4 +-- components/style/matching.rs | 2 +- components/style/parser.rs | 19 ++++++++----- .../style/properties/declaration_block.rs | 15 +++++++---- components/style/properties/helpers.mako.rs | 2 +- .../style/properties/longhand/box.mako.rs | 2 +- .../style/properties/longhand/text.mako.rs | 2 +- .../style/properties/properties.mako.rs | 15 +++++------ components/style/stylesheets.rs | 15 +++++------ components/style/stylist.rs | 4 +-- ports/geckolib/glue.rs | 17 +++++++----- tests/unit/style/media_queries.rs | 8 ++---- tests/unit/style/parsing/background.rs | 15 +++++++---- tests/unit/style/parsing/border.rs | 27 ++++++++++++------- tests/unit/style/parsing/column.rs | 6 +++-- tests/unit/style/parsing/effects.rs | 3 ++- tests/unit/style/parsing/font.rs | 6 +++-- tests/unit/style/parsing/inherited_text.rs | 9 ++++--- tests/unit/style/parsing/mask.rs | 15 +++++++---- tests/unit/style/parsing/mod.rs | 12 ++++++--- tests/unit/style/parsing/outline.rs | 3 ++- tests/unit/style/parsing/ui.rs | 3 ++- tests/unit/style/properties/background.rs | 3 ++- tests/unit/style/properties/serialization.rs | 9 ++++--- tests/unit/style/rule_tree/bench.rs | 6 +---- tests/unit/style/stylesheets.rs | 24 +++++++---------- tests/unit/style/viewport.rs | 20 +++++++------- 36 files changed, 186 insertions(+), 154 deletions(-) diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index d3e28e5f48d..58f81a71a59 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -110,7 +110,7 @@ use style::animation::Animation; use style::context::{QuirksMode, ReflowGoal, SharedStyleContext, ThreadLocalStyleContextCreationInfo}; use style::data::StoredRestyleHint; use style::dom::{ShowSubtree, ShowSubtreeDataAndPrimaryValues, TElement, TNode}; -use style::error_reporting::{ParseErrorReporter, StdoutErrorReporter}; +use style::error_reporting::StdoutErrorReporter; use style::logical_geometry::LogicalPoint; use style::media_queries::{Device, MediaType}; use style::parser::ParserContextExtraData; @@ -505,7 +505,7 @@ impl LayoutThread { stylist: rw_data.stylist.clone(), running_animations: self.running_animations.clone(), expired_animations: self.expired_animations.clone(), - error_reporter: self.error_reporter.clone(), + error_reporter: Box::new(self.error_reporter.clone()), local_context_creation_data: Mutex::new(thread_local_style_context_creation_data), timer: self.timer.clone(), quirks_mode: self.quirks_mode.unwrap(), @@ -1563,7 +1563,7 @@ fn get_ua_stylesheets() -> Result { Origin::UserAgent, Default::default(), None, - Box::new(StdoutErrorReporter), + &StdoutErrorReporter, ParserContextExtraData::default())) } @@ -1576,8 +1576,7 @@ fn get_ua_stylesheets() -> Result { for &(ref contents, ref url) in &opts::get().user_stylesheets { user_or_user_agent_stylesheets.push(Stylesheet::from_bytes( &contents, url.clone(), None, None, Origin::User, Default::default(), - None, Box::new(StdoutErrorReporter), - ParserContextExtraData::default())); + None, &StdoutErrorReporter, ParserContextExtraData::default())); } let quirks_mode_stylesheet = try!(parse_ua_stylesheet("quirks-mode.css")); diff --git a/components/script/dom/css.rs b/components/script/dom/css.rs index e24b3657775..92c15a10067 100644 --- a/components/script/dom/css.rs +++ b/components/script/dom/css.rs @@ -29,7 +29,7 @@ impl CSS { pub fn Supports(win: &Window, property: DOMString, value: DOMString) -> bool { let decl = Declaration { prop: property.into(), val: value.into() }; let url = win.Document().url(); - let context = ParserContext::new_for_cssom(&url); + let context = ParserContext::new_for_cssom(&url, win.css_error_reporter()); decl.eval(&context) } @@ -39,7 +39,7 @@ impl CSS { let cond = parse_condition_or_declaration(&mut input); if let Ok(cond) = cond { let url = win.Document().url(); - let context = ParserContext::new_for_cssom(&url); + let context = ParserContext::new_for_cssom(&url, win.css_error_reporter()); cond.eval(&context) } else { false diff --git a/components/script/dom/csssupportsrule.rs b/components/script/dom/csssupportsrule.rs index 7b1e77a6c8f..0cc113bef1c 100644 --- a/components/script/dom/csssupportsrule.rs +++ b/components/script/dom/csssupportsrule.rs @@ -56,8 +56,10 @@ impl CSSSupportsRule { let mut input = Parser::new(&text); let cond = SupportsCondition::parse(&mut input); if let Ok(cond) = cond { - let url = self.global().as_window().Document().url(); - let context = ParserContext::new_for_cssom(&url); + let global = self.global(); + let win = global.as_window(); + let url = win.Document().url(); + let context = ParserContext::new_for_cssom(&url, win.css_error_reporter()); let enabled = cond.eval(&context); let mut rule = self.supportsrule.write(); rule.condition = cond; diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 64a303c9412..fcb7f85d4cf 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -331,8 +331,8 @@ impl Window { &self.bluetooth_extra_permission_data } - pub fn css_error_reporter(&self) -> Box { - self.error_reporter.clone() + pub fn css_error_reporter(&self) -> &ParseErrorReporter { + &self.error_reporter } /// Sets a new list of scroll offsets. diff --git a/components/script_layout_interface/reporter.rs b/components/script_layout_interface/reporter.rs index 171f96d9d06..1c84bd31fc5 100644 --- a/components/script_layout_interface/reporter.rs +++ b/components/script_layout_interface/reporter.rs @@ -11,7 +11,7 @@ use servo_url::ServoUrl; use std::sync::{Mutex, Arc}; use style::error_reporting::ParseErrorReporter; -#[derive(HeapSizeOf)] +#[derive(HeapSizeOf, Clone)] pub struct CSSErrorReporter { pub pipelineid: PipelineId, // Arc+Mutex combo is necessary to make this struct Sync, @@ -22,11 +22,18 @@ pub struct CSSErrorReporter { } impl ParseErrorReporter for CSSErrorReporter { - fn report_error(&self, input: &mut Parser, position: SourcePosition, message: &str, - url: &ServoUrl) { + fn report_error(&self, + input: &mut Parser, + position: SourcePosition, + message: &str, + url: &ServoUrl) { let location = input.source_location(position); if log_enabled!(log::LogLevel::Info) { - info!("Url:\t{}\n{}:{} {}", url.as_str(), location.line, location.column, message) + info!("Url:\t{}\n{}:{} {}", + url.as_str(), + location.line, + location.column, + message) } //TODO: report a real filename @@ -37,11 +44,4 @@ impl ParseErrorReporter for CSSErrorReporter { location.column, message.to_owned())); } - - fn clone(&self) -> Box { - box CSSErrorReporter { - pipelineid: self.pipelineid, - script_chan: self.script_chan.clone(), - } - } } diff --git a/components/style/animation.rs b/components/style/animation.rs index 27c10401e2d..ddf1498d983 100644 --- a/components/style/animation.rs +++ b/components/style/animation.rs @@ -432,7 +432,7 @@ fn compute_style_for_animation_step(context: &SharedStyleContext, previous_style, previous_style, /* cascade_info = */ None, - context.error_reporter.clone(), + &*context.error_reporter, /* Metrics provider */ None, CascadeFlags::empty()); computed diff --git a/components/style/context.rs b/components/style/context.rs index a40c0679b76..44485915c2c 100644 --- a/components/style/context.rs +++ b/components/style/context.rs @@ -72,7 +72,7 @@ pub struct SharedStyleContext { pub expired_animations: Arc>>>, ///The CSS error reporter for all CSS loaded in this layout thread - pub error_reporter: Box, + pub error_reporter: Box, /// Data needed to create the thread-local style context from the shared one. pub local_context_creation_data: Mutex, diff --git a/components/style/error_reporting.rs b/components/style/error_reporting.rs index e815d0bf29e..ca62212fdaf 100644 --- a/components/style/error_reporting.rs +++ b/components/style/error_reporting.rs @@ -11,16 +11,16 @@ use log; use servo_url::ServoUrl; /// A generic trait for an error reporter. -pub trait ParseErrorReporter { +pub trait ParseErrorReporter : Sync + Send { /// Called the style engine detects an error. /// /// Returns the current input being parsed, the source position it was /// reported from, and a message. - fn report_error(&self, input: &mut Parser, position: SourcePosition, message: &str, url: &ServoUrl); - /// Clone this error reporter. - /// - /// TODO(emilio): I'm pretty sure all the box shenanigans can go away. - fn clone(&self) -> Box; + fn report_error(&self, + input: &mut Parser, + position: SourcePosition, + message: &str, + url: &ServoUrl); } /// An error reporter that reports the errors to the `info` log channel. @@ -28,15 +28,14 @@ pub trait ParseErrorReporter { /// TODO(emilio): The name of this reporter is a lie, and should be renamed! pub struct StdoutErrorReporter; impl ParseErrorReporter for StdoutErrorReporter { - fn report_error(&self, input: &mut Parser, position: SourcePosition, message: &str, - url: &ServoUrl) { + fn report_error(&self, + input: &mut Parser, + position: SourcePosition, + message: &str, + url: &ServoUrl) { if log_enabled!(log::LogLevel::Info) { let location = input.source_location(position); info!("Url:\t{}\n{}:{} {}", url.as_str(), location.line, location.column, message) } } - - fn clone(&self) -> Box { - Box::new(StdoutErrorReporter) - } } diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index 85ed9152580..ffeda8793cc 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -299,7 +299,7 @@ impl<'le> GeckoElement<'le> { pub fn parse_style_attribute(value: &str, base_url: &ServoUrl, extra_data: ParserContextExtraData) -> PropertyDeclarationBlock { - parse_style_attribute(value, base_url, Box::new(StdoutErrorReporter), extra_data) + parse_style_attribute(value, base_url, &StdoutErrorReporter, extra_data) } fn flags(&self) -> u32 { diff --git a/components/style/keyframes.rs b/components/style/keyframes.rs index 348bc028ee6..068dc169e9e 100644 --- a/components/style/keyframes.rs +++ b/components/style/keyframes.rs @@ -126,10 +126,10 @@ impl Keyframe { parent_stylesheet: &Stylesheet, extra_data: ParserContextExtraData) -> Result>, ()> { - let error_reporter = Box::new(MemoryHoleReporter); + let error_reporter = MemoryHoleReporter; let context = ParserContext::new_with_extra_data(parent_stylesheet.origin, &parent_stylesheet.base_url, - error_reporter, + &error_reporter, extra_data); let mut input = Parser::new(css); diff --git a/components/style/matching.rs b/components/style/matching.rs index 00a0a187844..619e1d57f7a 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -544,7 +544,7 @@ trait PrivateMatchMethods: TElement { inherited_values, layout_parent_style, Some(&mut cascade_info), - shared_context.error_reporter.clone(), + &*shared_context.error_reporter, cascade_flags)); cascade_info.finish(&self.as_node()); diff --git a/components/style/parser.rs b/components/style/parser.rs index b6ac5968c07..8a8628d2d89 100644 --- a/components/style/parser.rs +++ b/components/style/parser.rs @@ -12,7 +12,7 @@ use error_reporting::ParseErrorReporter; use gecko_bindings::sugar::refptr::{GeckoArcPrincipal, GeckoArcURI}; use servo_url::ServoUrl; use style_traits::OneOrMoreCommaSeparated; -use stylesheets::{MemoryHoleReporter, Origin}; +use stylesheets::Origin; /// Extra data that the style backend may need to parse stylesheets. #[cfg(not(feature = "gecko"))] @@ -67,7 +67,7 @@ pub struct ParserContext<'a> { /// The base url we're parsing this stylesheet as. pub base_url: &'a ServoUrl, /// An error reporter to report syntax errors. - pub error_reporter: Box, + pub error_reporter: &'a ParseErrorReporter, /// Implementation-dependent extra data. pub extra_data: ParserContextExtraData, } @@ -76,7 +76,7 @@ impl<'a> ParserContext<'a> { /// Create a `ParserContext` with extra data. pub fn new_with_extra_data(stylesheet_origin: Origin, base_url: &'a ServoUrl, - error_reporter: Box, + error_reporter: &'a ParseErrorReporter, extra_data: ParserContextExtraData) -> ParserContext<'a> { ParserContext { @@ -90,22 +90,27 @@ impl<'a> ParserContext<'a> { /// Create a parser context with the default extra data. pub fn new(stylesheet_origin: Origin, base_url: &'a ServoUrl, - error_reporter: Box) + error_reporter: &'a ParseErrorReporter) -> ParserContext<'a> { let extra_data = ParserContextExtraData::default(); Self::new_with_extra_data(stylesheet_origin, base_url, error_reporter, extra_data) } /// Create a parser context for on-the-fly parsing in CSSOM - pub fn new_for_cssom(base_url: &'a ServoUrl) -> ParserContext<'a> { - Self::new(Origin::User, base_url, Box::new(MemoryHoleReporter)) + pub fn new_for_cssom(base_url: &'a ServoUrl, + error_reporter: &'a ParseErrorReporter) + -> ParserContext<'a> { + Self::new(Origin::User, base_url, error_reporter) } } /// Defaults to a no-op. /// Set a `RUST_LOG=style::errors` environment variable /// to log CSS parse errors to stderr. -pub fn log_css_error(input: &mut Parser, position: SourcePosition, message: &str, parsercontext: &ParserContext) { +pub fn log_css_error(input: &mut Parser, + position: SourcePosition, + message: &str, + parsercontext: &ParserContext) { let servo_url = parsercontext.base_url; parsercontext.error_reporter.report_error(input, position, message, servo_url); } diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index f10da7a7cb4..721396e8b3a 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -11,7 +11,6 @@ use cssparser::{Parser, AtRuleParser, DeclarationParser, Delimiter}; use error_reporting::ParseErrorReporter; use parser::{ParserContext, ParserContextExtraData, log_css_error}; use servo_url::ServoUrl; -use std::boxed::Box as StdBox; use std::fmt; use style_traits::ToCss; use stylesheets::Origin; @@ -570,10 +569,13 @@ pub fn append_serialization<'a, W, I, N>(dest: &mut W, /// shared between Servo and Gecko. pub fn parse_style_attribute(input: &str, base_url: &ServoUrl, - error_reporter: StdBox, + error_reporter: &ParseErrorReporter, extra_data: ParserContextExtraData) -> PropertyDeclarationBlock { - let context = ParserContext::new_with_extra_data(Origin::Author, base_url, error_reporter, extra_data); + let context = ParserContext::new_with_extra_data(Origin::Author, + base_url, + error_reporter, + extra_data); parse_property_declaration_list(&context, &mut Parser::new(input)) } @@ -585,10 +587,13 @@ pub fn parse_style_attribute(input: &str, pub fn parse_one_declaration(id: PropertyId, input: &str, base_url: &ServoUrl, - error_reporter: StdBox, + error_reporter: &ParseErrorReporter, extra_data: ParserContextExtraData) -> Result { - let context = ParserContext::new_with_extra_data(Origin::Author, base_url, error_reporter, extra_data); + let context = ParserContext::new_with_extra_data(Origin::Author, + base_url, + error_reporter, + extra_data); Parser::new(input).parse_entirely(|parser| { ParsedDeclaration::parse(id, &context, parser, false) .map_err(|_| ()) diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index cd88ae26a86..48214966928 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -233,7 +233,7 @@ context: &mut computed::Context, cacheable: &mut bool, cascade_info: &mut Option<<&mut CascadeInfo>, - error_reporter: &mut StdBox) { + error_reporter: &ParseErrorReporter) { let declared_value = match *declaration { PropertyDeclaration::${property.camel_case}(ref declared_value) => { declared_value diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index e57ce3aca34..55d348b6ceb 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -85,7 +85,7 @@ _inherited_style: &ComputedValues, context: &mut computed::Context, _cacheable: &mut bool, - _error_reporter: &mut StdBox) { + _error_reporter: &ParseErrorReporter) { longhands::_servo_display_for_hypothetical_box::derive_from_display(context); longhands::_servo_text_decorations_in_effect::derive_from_display(context); longhands::_servo_under_display_none::derive_from_display(context); diff --git a/components/style/properties/longhand/text.mako.rs b/components/style/properties/longhand/text.mako.rs index 8fed3b7acab..00b7b3fb346 100644 --- a/components/style/properties/longhand/text.mako.rs +++ b/components/style/properties/longhand/text.mako.rs @@ -210,7 +210,7 @@ ${helpers.single_keyword("unicode-bidi", _inherited_style: &ComputedValues, context: &mut computed::Context, _cacheable: &mut bool, - _error_reporter: &mut StdBox) { + _error_reporter: &ParseErrorReporter) { longhands::_servo_text_decorations_in_effect::derive_from_text_decoration(context); } % endif diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index a6cdc1af632..7855b3e1c79 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -11,7 +11,6 @@ <%namespace name="helpers" file="/helpers.mako.rs" /> use std::borrow::Cow; -use std::boxed::Box as StdBox; use std::collections::HashSet; use std::fmt; use std::sync::Arc; @@ -288,7 +287,7 @@ impl PropertyDeclarationIdSet { % endif custom_properties: &Option>, f: F, - error_reporter: &mut StdBox) + error_reporter: &ParseErrorReporter) % if property.boxed: where F: FnOnce(&DeclaredValue>) % else: @@ -322,7 +321,7 @@ impl PropertyDeclarationIdSet { from_shorthand: Option, custom_properties: &Option>, f: F, - error_reporter: &mut StdBox, + error_reporter: &ParseErrorReporter, extra_data: ParserContextExtraData) % if property.boxed: where F: FnOnce(&DeclaredValue>) @@ -338,7 +337,7 @@ impl PropertyDeclarationIdSet { // FIXME(pcwalton): Cloning the error reporter is slow! But so are custom // properties, so whatever... let context = ParserContext::new_with_extra_data( - ::stylesheets::Origin::Author, base_url, (*error_reporter).clone(), + ::stylesheets::Origin::Author, base_url, error_reporter, extra_data); Parser::new(&css).parse_entirely(|input| { match from_shorthand { @@ -1764,7 +1763,7 @@ pub type CascadePropertyFn = context: &mut computed::Context, cacheable: &mut bool, cascade_info: &mut Option<<&mut CascadeInfo>, - error_reporter: &mut StdBox); + error_reporter: &ParseErrorReporter); /// A per-longhand array of functions to perform the CSS cascade on each of /// them, effectively doing virtual dispatch. @@ -1808,7 +1807,7 @@ pub fn cascade(device: &Device, parent_style: Option<<&ComputedValues>, layout_parent_style: Option<<&ComputedValues>, cascade_info: Option<<&mut CascadeInfo>, - error_reporter: StdBox, + error_reporter: &ParseErrorReporter, flags: CascadeFlags) -> ComputedValues { debug_assert_eq!(parent_style.is_some(), layout_parent_style.is_some()); @@ -1863,7 +1862,7 @@ pub fn apply_declarations<'a, F, I>(device: &Device, inherited_style: &ComputedValues, layout_parent_style: &ComputedValues, mut cascade_info: Option<<&mut CascadeInfo>, - mut error_reporter: StdBox, + error_reporter: &ParseErrorReporter, font_metrics_provider: Option<<&FontMetricsProvider>, flags: CascadeFlags) -> ComputedValues @@ -1991,7 +1990,7 @@ pub fn apply_declarations<'a, F, I>(device: &Device, &mut context, &mut cacheable, &mut cascade_info, - &mut error_reporter); + error_reporter); } % if category_to_cascade_now == "early": let writing_mode = get_writing_mode(context.style.get_inheritedbox()); diff --git a/components/style/stylesheets.rs b/components/style/stylesheets.rs index cc72acd4c15..9145e761a4b 100644 --- a/components/style/stylesheets.rs +++ b/components/style/stylesheets.rs @@ -255,9 +255,6 @@ impl ParseErrorReporter for MemoryHoleReporter { _: &ServoUrl) { // do nothing } - fn clone(&self) -> Box { - Box::new(MemoryHoleReporter) - } } #[allow(missing_docs)] @@ -341,11 +338,11 @@ impl CssRule { extra_data: ParserContextExtraData, state: Option) -> Result<(Self, State), SingleRuleParseError> { - let error_reporter = Box::new(MemoryHoleReporter); + let error_reporter = MemoryHoleReporter; let mut namespaces = parent_stylesheet.namespaces.write(); let context = ParserContext::new_with_extra_data(parent_stylesheet.origin, &parent_stylesheet.base_url, - error_reporter.clone(), + &error_reporter, extra_data); let mut input = Parser::new(css); @@ -583,7 +580,7 @@ impl Stylesheet { origin: Origin, media: MediaList, stylesheet_loader: Option<&StylesheetLoader>, - error_reporter: Box, + error_reporter: &ParseErrorReporter, extra_data: ParserContextExtraData) -> Stylesheet { let (string, _) = decode_stylesheet_bytes( @@ -604,7 +601,7 @@ impl Stylesheet { protocol_encoding_label: Option<&str>, environment_encoding: Option, stylesheet_loader: Option<&StylesheetLoader>, - error_reporter: Box, + error_reporter: &ParseErrorReporter, extra_data: ParserContextExtraData) { let (string, _) = decode_stylesheet_bytes( bytes, protocol_encoding_label, environment_encoding); @@ -619,7 +616,7 @@ impl Stylesheet { pub fn update_from_str(existing: &Stylesheet, css: &str, stylesheet_loader: Option<&StylesheetLoader>, - error_reporter: Box, + error_reporter: &ParseErrorReporter, extra_data: ParserContextExtraData) { let mut rules = existing.rules.write(); let mut namespaces = existing.namespaces.write(); @@ -668,7 +665,7 @@ impl Stylesheet { origin: Origin, media: MediaList, stylesheet_loader: Option<&StylesheetLoader>, - error_reporter: Box, + error_reporter: &ParseErrorReporter, extra_data: ParserContextExtraData) -> Stylesheet { let s = Stylesheet { origin: origin, diff --git a/components/style/stylist.rs b/components/style/stylist.rs index 7acb9baf641..79044cd1fb5 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -329,7 +329,7 @@ impl Stylist { parent.map(|p| &**p), parent.map(|p| &**p), None, - Box::new(StdoutErrorReporter), + &StdoutErrorReporter, cascade_flags); ComputedStyle::new(rule_node, Arc::new(computed)) } @@ -411,7 +411,7 @@ impl Stylist { Some(&**parent), Some(&**parent), None, - Box::new(StdoutErrorReporter), + &StdoutErrorReporter, CascadeFlags::empty()); // Apply the selector flags. We should be in sequential mode already, diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index b46540dc5cf..0bc09c30e68 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -166,6 +166,7 @@ fn create_shared_context(per_doc_data: &PerDocumentStyleDataImpl) -> SharedStyle stylist: per_doc_data.stylist.clone(), running_animations: per_doc_data.running_animations.clone(), expired_animations: per_doc_data.expired_animations.clone(), + // FIXME(emilio): Stop boxing here. error_reporter: Box::new(StdoutErrorReporter), local_context_creation_data: Mutex::new(local_context_data), timer: Timer::new(), @@ -336,7 +337,7 @@ pub extern "C" fn Servo_StyleSheet_Empty(mode: SheetParsingMode) -> RawServoStyl }; Arc::new(Stylesheet::from_str( "", url, origin, Default::default(), None, - Box::new(StdoutErrorReporter), extra_data) + &StdoutErrorReporter, extra_data) ).into_strong() } @@ -379,7 +380,7 @@ pub extern "C" fn Servo_StyleSheet_FromUTF8Bytes(loader: *mut Loader, Arc::new(Stylesheet::from_str( input, url, origin, Default::default(), loader, - Box::new(StdoutErrorReporter), extra_data) + &StdoutErrorReporter, extra_data) ).into_strong() } @@ -415,7 +416,7 @@ pub extern "C" fn Servo_StyleSheet_ClearAndUpdate(stylesheet: RawServoStyleSheet sheet.rules.write().0.clear(); Stylesheet::update_from_str(&sheet, input, loader, - Box::new(StdoutErrorReporter), extra_data); + &StdoutErrorReporter, extra_data); } #[no_mangle] @@ -746,9 +747,10 @@ pub extern "C" fn Servo_ParseProperty(property: *const nsACString, value: *const make_context!((base, data) => (base_url, extra_data)); + let reporter = StdoutErrorReporter; let context = ParserContext::new_with_extra_data(Origin::Author, &base_url, - Box::new(StdoutErrorReporter), + &reporter, extra_data); match ParsedDeclaration::parse(id, &context, &mut Parser::new(value), false) { @@ -874,7 +876,7 @@ fn set_property(declarations: RawServoDeclarationBlockBorrowed, property_id: Pro make_context!((base, data) => (base_url, extra_data)); if let Ok(parsed) = parse_one_declaration(property_id, value, &base_url, - Box::new(StdoutErrorReporter), extra_data) { + &StdoutErrorReporter, extra_data) { let mut declarations = RwLock::::as_arc(&declarations).write(); let importance = if is_important { Importance::Important } else { Importance::Normal }; let mut changed = false; @@ -1257,7 +1259,7 @@ pub extern "C" fn Servo_CSSSupports2(property: *const nsACString, value: *const let base_url = &*DUMMY_BASE_URL; let extra_data = ParserContextExtraData::default(); - parse_one_declaration(id, &value, &base_url, Box::new(StdoutErrorReporter), extra_data).is_ok() + parse_one_declaration(id, &value, &base_url, &StdoutErrorReporter, extra_data).is_ok() } #[no_mangle] @@ -1267,7 +1269,8 @@ pub extern "C" fn Servo_CSSSupports(cond: *const nsACString) -> bool { let cond = parse_condition_or_declaration(&mut input); if let Ok(cond) = cond { let url = ServoUrl::parse("about:blank").unwrap(); - let context = ParserContext::new_for_cssom(&url); + let reporter = StdoutErrorReporter; + let context = ParserContext::new_for_cssom(&url, &reporter); cond.eval(&context) } else { false diff --git a/tests/unit/style/media_queries.rs b/tests/unit/style/media_queries.rs index b2fe60ea91e..4d3cf9e98a2 100644 --- a/tests/unit/style/media_queries.rs +++ b/tests/unit/style/media_queries.rs @@ -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 { - Box::new(CSSErrorReporterTest) - } } fn test_media_rule(css: &str, callback: F) @@ -34,7 +30,7 @@ fn test_media_rule(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); diff --git a/tests/unit/style/parsing/background.rs b/tests/unit/style/parsing/background.rs index 6d1c1f0e954..084c2e10201 100644 --- a/tests/unit/style/parsing/background.rs +++ b/tests/unit/style/parsing/background.rs @@ -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(); diff --git a/tests/unit/style/parsing/border.rs b/tests/unit/style/parsing/border.rs index ced526dea95..94a4d8f6ff3 100644 --- a/tests/unit/style/parsing/border.rs +++ b/tests/unit/style/parsing/border.rs @@ -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")); diff --git a/tests/unit/style/parsing/column.rs b/tests/unit/style/parsing/column.rs index 5de0d773329..f8aff1e04b7 100644 --- a/tests/unit/style/parsing/column.rs +++ b/tests/unit/style/parsing/column.rs @@ -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()); diff --git a/tests/unit/style/parsing/effects.rs b/tests/unit/style/parsing/effects.rs index 7453d423635..2b8ef18c2e5 100644 --- a/tests/unit/style/parsing/effects.rs +++ b/tests/unit/style/parsing/effects.rs @@ -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); diff --git a/tests/unit/style/parsing/font.rs b/tests/unit/style/parsing/font.rs index 7fdd3565e5c..6d44e1f532f 100644 --- a/tests/unit/style/parsing/font.rs +++ b/tests/unit/style/parsing/font.rs @@ -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); diff --git a/tests/unit/style/parsing/inherited_text.rs b/tests/unit/style/parsing/inherited_text.rs index a9604f8dc09..b0d474b6024 100644 --- a/tests/unit/style/parsing/inherited_text.rs +++ b/tests/unit/style/parsing/inherited_text.rs @@ -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")); diff --git a/tests/unit/style/parsing/mask.rs b/tests/unit/style/parsing/mask.rs index b57f8a2b4b4..09ea57c0686 100644 --- a/tests/unit/style/parsing/mask.rs +++ b/tests/unit/style/parsing/mask.rs @@ -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()); diff --git a/tests/unit/style/parsing/mod.rs b/tests/unit/style/parsing/mod.rs index 83cb6d1d1f7..e4a9ce985a3 100644 --- a/tests/unit/style/parsing/mod.rs +++ b/tests/unit/style/parsing/mod.rs @@ -11,7 +11,8 @@ use style::stylesheets::Origin; fn parse Result>(f: F, s: &str) -> Result { 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() }}; } diff --git a/tests/unit/style/parsing/outline.rs b/tests/unit/style/parsing/outline.rs index 7ffa5eeee5b..3603ccda1db 100644 --- a/tests/unit/style/parsing/outline.rs +++ b/tests/unit/style/parsing/outline.rs @@ -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()); diff --git a/tests/unit/style/parsing/ui.rs b/tests/unit/style/parsing/ui.rs index 1687df84848..a0b5367e9c2 100644 --- a/tests/unit/style/parsing/ui.rs +++ b/tests/unit/style/parsing/ui.rs @@ -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()); diff --git a/tests/unit/style/properties/background.rs b/tests/unit/style/properties/background.rs index 493e12e3dcf..4640845ae85 100644 --- a/tests/unit/style/properties/background.rs +++ b/tests/unit/style/properties/background.rs @@ -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%")); diff --git a/tests/unit/style/properties/serialization.rs b/tests/unit/style/properties/serialization.rs index d197a52b9cd..26a8c9d0191 100644 --- a/tests/unit/style/properties/serialization.rs +++ b/tests/unit/style/properties/serialization.rs @@ -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); diff --git a/tests/unit/style/rule_tree/bench.rs b/tests/unit/style/rule_tree/bench.rs index 74242967766..bec7018215f 100644 --- a/tests/unit/style/rule_tree/bench.rs +++ b/tests/unit/style/rule_tree/bench.rs @@ -21,10 +21,6 @@ impl ParseErrorReporter for ErrorringErrorReporter { url: &ServoUrl) { panic!("CSS error: {}\t\n{:?} {}", url.as_str(), position, message); } - - fn clone(&self) -> Box { - 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| { diff --git a/tests/unit/style/stylesheets.rs b/tests/unit/style/stylesheets.rs index a85e5e36fb0..892bcb53980 100644 --- a/tests/unit/style/stylesheets.rs +++ b/tests/unit/style/stylesheets.rs @@ -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 { - 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(); diff --git a/tests/unit/style/viewport.rs b/tests/unit/style/viewport.rs index d4ef14536d8..166094ebdc1 100644 --- a/tests/unit/style/viewport.rs +++ b/tests/unit/style/viewport.rs @@ -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(css: &str, where F: Fn(&Vec, &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) => {