aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorFernando Jiménez Moreno <ferjmoreno@gmail.com>2017-04-12 11:43:07 +0200
committerFernando Jiménez Moreno <ferjmoreno@gmail.com>2017-04-12 11:43:07 +0200
commit11f227b4fff8e832f1bd140ee7db70d10475aea0 (patch)
tree53de5a41314bf9277bd11d1d0b31c8c43652d7bf /components/script/dom
parent3ad473755c00e9a8e66cc47b3fe3dd303d8c2709 (diff)
downloadservo-11f227b4fff8e832f1bd140ee7db70d10475aea0.tar.gz
servo-11f227b4fff8e832f1bd140ee7db70d10475aea0.zip
Inform about unminify errors and store unmodified version if js-beautify fails
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/htmlscriptelement.rs47
1 files changed, 25 insertions, 22 deletions
diff --git a/components/script/dom/htmlscriptelement.rs b/components/script/dom/htmlscriptelement.rs
index 5b8e11f237f..d6679c5168c 100644
--- a/components/script/dom/htmlscriptelement.rs
+++ b/components/script/dom/htmlscriptelement.rs
@@ -461,38 +461,41 @@ impl HTMLScriptElement {
return;
}
- let process = Command::new("js-beautify")
- .stdin(Stdio::piped())
- .stdout(Stdio::piped())
- .spawn()
- .expect("Failed to execute js-beautify");
-
- let mut script_content = String::from(script.text.clone());
- let _ = process.stdin.unwrap().write_all(script_content.as_bytes());
- script_content.clear();
- let _ = process.stdout.unwrap().read_to_string(&mut script_content);
+ match Command::new("js-beautify")
+ .stdin(Stdio::piped())
+ .stdout(Stdio::piped())
+ .spawn() {
+ Err(_) => {
+ warn!("Failed to execute js-beautify. Will store unmodified script");
+ },
+ Ok(process) => {
+ let mut script_content = String::from(script.text.clone());
+ let _ = process.stdin.unwrap().write_all(script_content.as_bytes());
+ script_content.clear();
+ let _ = process.stdout.unwrap().read_to_string(&mut script_content);
- script.text = DOMString::from(script_content);
+ script.text = DOMString::from(script_content);
+ },
+ }
- let unminified_js_dir = PathBuf::from(window_from_node(self).unminified_js_dir().unwrap());
+ let path = PathBuf::from(window_from_node(self).unminified_js_dir().unwrap());
let path = if script.external {
// External script.
- debug!("unminifying script {:?}", script.url);
- let url = script.url.clone().into_string();
- let path_parts = url.split("/").collect::<Vec<&str>>();
+ let path_parts = script.url.path_segments().unwrap();
match path_parts.last() {
- Some(script_name) => unminified_js_dir.join(script_name),
- None => unminified_js_dir.join(Uuid::new_v4().to_string()),
+ Some(script_name) => path.join(script_name),
+ None => path.join(Uuid::new_v4().to_string()),
}
} else {
// Inline script.
- debug!("unminifying inline script for {:?}", script.url);
- unminified_js_dir.join(Uuid::new_v4().to_string())
+ path.join(Uuid::new_v4().to_string())
};
- debug!("unminified script will be stored in {:?}", path);
- if let Ok(mut file) = File::create(&path) {
- file.write_all(script.text.as_bytes()).unwrap();
+ debug!("script will be stored in {:?}", path);
+
+ match File::create(&path) {
+ Ok(mut file) => file.write_all(script.text.as_bytes()).unwrap(),
+ Err(why) => warn!("Could not store script {:?}", why),
}
}