mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +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
|
@ -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<UserAgentStylesheets, &'static str> {
|
|||
Origin::UserAgent,
|
||||
Default::default(),
|
||||
None,
|
||||
Box::new(StdoutErrorReporter),
|
||||
&StdoutErrorReporter,
|
||||
ParserContextExtraData::default()))
|
||||
}
|
||||
|
||||
|
@ -1576,8 +1576,7 @@ fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> {
|
|||
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"));
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -331,8 +331,8 @@ impl Window {
|
|||
&self.bluetooth_extra_permission_data
|
||||
}
|
||||
|
||||
pub fn css_error_reporter(&self) -> Box<ParseErrorReporter + Send> {
|
||||
self.error_reporter.clone()
|
||||
pub fn css_error_reporter(&self) -> &ParseErrorReporter {
|
||||
&self.error_reporter
|
||||
}
|
||||
|
||||
/// Sets a new list of scroll offsets.
|
||||
|
|
|
@ -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<ParseErrorReporter + Send + Sync> {
|
||||
box CSSErrorReporter {
|
||||
pipelineid: self.pipelineid,
|
||||
script_chan: self.script_chan.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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::<PropertyDeclarationBlock>::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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
|
@ -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()
|
||||
}};
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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%"));
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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| {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue