mirror of
https://github.com/servo/servo.git
synced 2025-08-09 23:45:35 +01:00
style: Avoid cloning all over the error reporter.
This commit is contained in:
parent
eaf27ccfa0
commit
b4de69e3eb
36 changed files with 186 additions and 154 deletions
|
@ -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
|
||||
|
|
|
@ -72,7 +72,7 @@ pub struct SharedStyleContext {
|
|||
pub expired_animations: Arc<RwLock<HashMap<OpaqueNode, Vec<Animation>>>>,
|
||||
|
||||
///The CSS error reporter for all CSS loaded in this layout thread
|
||||
pub error_reporter: Box<ParseErrorReporter + Sync>,
|
||||
pub error_reporter: Box<ParseErrorReporter>,
|
||||
|
||||
/// Data needed to create the thread-local style context from the shared one.
|
||||
pub local_context_creation_data: Mutex<ThreadLocalStyleContextCreationInfo>,
|
||||
|
|
|
@ -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<ParseErrorReporter + Send + Sync>;
|
||||
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<ParseErrorReporter + Send + Sync> {
|
||||
Box::new(StdoutErrorReporter)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -126,10 +126,10 @@ impl Keyframe {
|
|||
parent_stylesheet: &Stylesheet,
|
||||
extra_data: ParserContextExtraData)
|
||||
-> Result<Arc<RwLock<Self>>, ()> {
|
||||
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);
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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<ParseErrorReporter + Send>,
|
||||
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<ParseErrorReporter + Send>,
|
||||
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<ParseErrorReporter + Send>)
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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<ParseErrorReporter + Send>,
|
||||
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<ParseErrorReporter + Send>,
|
||||
error_reporter: &ParseErrorReporter,
|
||||
extra_data: ParserContextExtraData)
|
||||
-> Result<ParsedDeclaration, ()> {
|
||||
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(|_| ())
|
||||
|
|
|
@ -233,7 +233,7 @@
|
|||
context: &mut computed::Context,
|
||||
cacheable: &mut bool,
|
||||
cascade_info: &mut Option<<&mut CascadeInfo>,
|
||||
error_reporter: &mut StdBox<ParseErrorReporter + Send>) {
|
||||
error_reporter: &ParseErrorReporter) {
|
||||
let declared_value = match *declaration {
|
||||
PropertyDeclaration::${property.camel_case}(ref declared_value) => {
|
||||
declared_value
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
_inherited_style: &ComputedValues,
|
||||
context: &mut computed::Context,
|
||||
_cacheable: &mut bool,
|
||||
_error_reporter: &mut StdBox<ParseErrorReporter + Send>) {
|
||||
_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);
|
||||
|
|
|
@ -210,7 +210,7 @@ ${helpers.single_keyword("unicode-bidi",
|
|||
_inherited_style: &ComputedValues,
|
||||
context: &mut computed::Context,
|
||||
_cacheable: &mut bool,
|
||||
_error_reporter: &mut StdBox<ParseErrorReporter + Send>) {
|
||||
_error_reporter: &ParseErrorReporter) {
|
||||
longhands::_servo_text_decorations_in_effect::derive_from_text_decoration(context);
|
||||
}
|
||||
% endif
|
||||
|
|
|
@ -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<Arc<::custom_properties::ComputedValuesMap>>,
|
||||
f: F,
|
||||
error_reporter: &mut StdBox<ParseErrorReporter + Send>)
|
||||
error_reporter: &ParseErrorReporter)
|
||||
% if property.boxed:
|
||||
where F: FnOnce(&DeclaredValue<Box<longhands::${property.ident}::SpecifiedValue>>)
|
||||
% else:
|
||||
|
@ -322,7 +321,7 @@ impl PropertyDeclarationIdSet {
|
|||
from_shorthand: Option<ShorthandId>,
|
||||
custom_properties: &Option<Arc<::custom_properties::ComputedValuesMap>>,
|
||||
f: F,
|
||||
error_reporter: &mut StdBox<ParseErrorReporter + Send>,
|
||||
error_reporter: &ParseErrorReporter,
|
||||
extra_data: ParserContextExtraData)
|
||||
% if property.boxed:
|
||||
where F: FnOnce(&DeclaredValue<Box<longhands::${property.ident}::SpecifiedValue>>)
|
||||
|
@ -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<ParseErrorReporter + Send>);
|
||||
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<ParseErrorReporter + Send>,
|
||||
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<ParseErrorReporter + Send>,
|
||||
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());
|
||||
|
|
|
@ -255,9 +255,6 @@ impl ParseErrorReporter for MemoryHoleReporter {
|
|||
_: &ServoUrl) {
|
||||
// do nothing
|
||||
}
|
||||
fn clone(&self) -> Box<ParseErrorReporter + Send + Sync> {
|
||||
Box::new(MemoryHoleReporter)
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(missing_docs)]
|
||||
|
@ -341,11 +338,11 @@ impl CssRule {
|
|||
extra_data: ParserContextExtraData,
|
||||
state: Option<State>)
|
||||
-> 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<ParseErrorReporter + Send>,
|
||||
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<EncodingRef>,
|
||||
stylesheet_loader: Option<&StylesheetLoader>,
|
||||
error_reporter: Box<ParseErrorReporter + Send>,
|
||||
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<ParseErrorReporter + Send>,
|
||||
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<ParseErrorReporter + Send>,
|
||||
error_reporter: &ParseErrorReporter,
|
||||
extra_data: ParserContextExtraData) -> Stylesheet {
|
||||
let s = Stylesheet {
|
||||
origin: origin,
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue