fix Stylist::new() to not panic when resources cannot be loaded

This commit is contained in:
Mike Blumenkrantz 2015-05-08 17:38:17 -04:00
parent f4381a6f1e
commit 1cf5dd212c

View file

@ -9,6 +9,7 @@ use selectors::matching::{SelectorMap, Rule};
use selectors::matching::DeclarationBlock as GenericDeclarationBlock; use selectors::matching::DeclarationBlock as GenericDeclarationBlock;
use selectors::parser::PseudoElement; use selectors::parser::PseudoElement;
use selectors::tree::TNode; use selectors::tree::TNode;
use std::process;
use util::resource_files::read_resource_file; use util::resource_files::read_resource_file;
use util::smallvec::VecLike; use util::smallvec::VecLike;
@ -59,13 +60,21 @@ impl Stylist {
// FIXME: presentational-hints.css should be at author origin with zero specificity. // FIXME: presentational-hints.css should be at author origin with zero specificity.
// (Does it make a difference?) // (Does it make a difference?)
for &filename in ["user-agent.css", "servo.css", "presentational-hints.css"].iter() { for &filename in ["user-agent.css", "servo.css", "presentational-hints.css"].iter() {
let ua_stylesheet = Stylesheet::from_bytes( match read_resource_file(&[filename]) {
&read_resource_file(&[filename]).unwrap(), Ok(res) => {
Url::parse(&format!("chrome:///{:?}", filename)).unwrap(), let ua_stylesheet = Stylesheet::from_bytes(
None, &res,
None, Url::parse(&format!("chrome:///{:?}", filename)).unwrap(),
Origin::UserAgent); None,
stylist.add_stylesheet(ua_stylesheet); None,
Origin::UserAgent);
stylist.add_stylesheet(ua_stylesheet);
}
Err(..) => {
error!("Stylist::new() failed at loading {}!", filename);
process::exit(1);
}
}
} }
stylist stylist
} }