aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/script_thread.rs
diff options
context:
space:
mode:
authorDaniel Johnson <danielj41@gmail.com>2017-09-07 17:03:41 -0700
committerDaniel Johnson <danielj41@gmail.com>2017-09-07 17:03:41 -0700
commit709cd3a0b636f601c0a4ca606c241500eca13789 (patch)
tree2759bba982b8f798a7f3e79e74a907fe8eb0e773 /components/script/script_thread.rs
parent6ae6031468662161280a4353da9c0c23368cd83d (diff)
downloadservo-709cd3a0b636f601c0a4ca606c241500eca13789.tar.gz
servo-709cd3a0b636f601c0a4ca606c241500eca13789.zip
"javascript:" urls: remove unnecessary block
Remove this block and unindent the code one level. Doing this required cloning `load_data.url` so that we could later mutate `load_data.url` in the same block.
Diffstat (limited to 'components/script/script_thread.rs')
-rw-r--r--components/script/script_thread.rs62
1 files changed, 30 insertions, 32 deletions
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs
index 6ca5b05bc67..ccc3f70146a 100644
--- a/components/script/script_thread.rs
+++ b/components/script/script_thread.rs
@@ -2334,39 +2334,37 @@ impl ScriptThread {
}
pub fn eval_js_url(global_scope: &GlobalScope, load_data: &mut LoadData) {
- {
- // Turn javascript: URL into JS code to eval, according to the steps in
- // https://html.spec.whatwg.org/multipage/#javascript-protocol
-
- // This slice of the URL’s serialization is equivalent to (5.) to (7.):
- // Start with the scheme data of the parsed URL;
- // append question mark and query component, if any;
- // append number sign and fragment component if any.
- let encoded = &load_data.url[Position::BeforePath..];
-
- // Percent-decode (8.) and UTF-8 decode (9.)
- let script_source = percent_decode(encoded.as_bytes()).decode_utf8_lossy();
-
- // Script source is ready to be evaluated (11.)
- let _ac = JSAutoCompartment::new(global_scope.get_cx(), global_scope.reflector().get_jsobject().get());
- rooted!(in(global_scope.get_cx()) let mut jsval = UndefinedValue());
- global_scope.evaluate_js_on_global_with_result(&script_source, jsval.handle_mut());
-
- load_data.js_eval_result = if jsval.get().is_string() {
- unsafe {
- let strval = DOMString::from_jsval(global_scope.get_cx(),
- jsval.handle(),
- StringificationBehavior::Empty);
- match strval {
- Ok(ConversionResult::Success(s)) => {
- Some(JsEvalResult::Ok(String::from(s).as_bytes().to_vec()))
- },
- _ => None,
- }
+ // Turn javascript: URL into JS code to eval, according to the steps in
+ // https://html.spec.whatwg.org/multipage/#javascript-protocol
+
+ // This slice of the URL’s serialization is equivalent to (5.) to (7.):
+ // Start with the scheme data of the parsed URL;
+ // append question mark and query component, if any;
+ // append number sign and fragment component if any.
+ let encoded = &load_data.url.clone()[Position::BeforePath..];
+
+ // Percent-decode (8.) and UTF-8 decode (9.)
+ let script_source = percent_decode(encoded.as_bytes()).decode_utf8_lossy();
+
+ // Script source is ready to be evaluated (11.)
+ let _ac = JSAutoCompartment::new(global_scope.get_cx(), global_scope.reflector().get_jsobject().get());
+ rooted!(in(global_scope.get_cx()) let mut jsval = UndefinedValue());
+ global_scope.evaluate_js_on_global_with_result(&script_source, jsval.handle_mut());
+
+ load_data.js_eval_result = if jsval.get().is_string() {
+ unsafe {
+ let strval = DOMString::from_jsval(global_scope.get_cx(),
+ jsval.handle(),
+ StringificationBehavior::Empty);
+ match strval {
+ Ok(ConversionResult::Success(s)) => {
+ Some(JsEvalResult::Ok(String::from(s).as_bytes().to_vec()))
+ },
+ _ => None,
}
- } else {
- Some(JsEvalResult::NoContent)
- };
+ }
+ } else {
+ Some(JsEvalResult::NoContent)
};
load_data.url = ServoUrl::parse("about:blank").unwrap();