mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
"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.
This commit is contained in:
parent
6ae6031468
commit
709cd3a0b6
1 changed files with 26 additions and 28 deletions
|
@ -2334,39 +2334,37 @@ impl ScriptThread {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn eval_js_url(global_scope: &GlobalScope, load_data: &mut LoadData) {
|
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
|
||||||
// Turn javascript: URL into JS code to eval, according to the steps in
|
// https://html.spec.whatwg.org/multipage/#javascript-protocol
|
||||||
// https://html.spec.whatwg.org/multipage/#javascript-protocol
|
|
||||||
|
|
||||||
// This slice of the URL’s serialization is equivalent to (5.) to (7.):
|
// This slice of the URL’s serialization is equivalent to (5.) to (7.):
|
||||||
// Start with the scheme data of the parsed URL;
|
// Start with the scheme data of the parsed URL;
|
||||||
// append question mark and query component, if any;
|
// append question mark and query component, if any;
|
||||||
// append number sign and fragment component if any.
|
// append number sign and fragment component if any.
|
||||||
let encoded = &load_data.url[Position::BeforePath..];
|
let encoded = &load_data.url.clone()[Position::BeforePath..];
|
||||||
|
|
||||||
// Percent-decode (8.) and UTF-8 decode (9.)
|
// Percent-decode (8.) and UTF-8 decode (9.)
|
||||||
let script_source = percent_decode(encoded.as_bytes()).decode_utf8_lossy();
|
let script_source = percent_decode(encoded.as_bytes()).decode_utf8_lossy();
|
||||||
|
|
||||||
// Script source is ready to be evaluated (11.)
|
// Script source is ready to be evaluated (11.)
|
||||||
let _ac = JSAutoCompartment::new(global_scope.get_cx(), global_scope.reflector().get_jsobject().get());
|
let _ac = JSAutoCompartment::new(global_scope.get_cx(), global_scope.reflector().get_jsobject().get());
|
||||||
rooted!(in(global_scope.get_cx()) let mut jsval = UndefinedValue());
|
rooted!(in(global_scope.get_cx()) let mut jsval = UndefinedValue());
|
||||||
global_scope.evaluate_js_on_global_with_result(&script_source, jsval.handle_mut());
|
global_scope.evaluate_js_on_global_with_result(&script_source, jsval.handle_mut());
|
||||||
|
|
||||||
load_data.js_eval_result = if jsval.get().is_string() {
|
load_data.js_eval_result = if jsval.get().is_string() {
|
||||||
unsafe {
|
unsafe {
|
||||||
let strval = DOMString::from_jsval(global_scope.get_cx(),
|
let strval = DOMString::from_jsval(global_scope.get_cx(),
|
||||||
jsval.handle(),
|
jsval.handle(),
|
||||||
StringificationBehavior::Empty);
|
StringificationBehavior::Empty);
|
||||||
match strval {
|
match strval {
|
||||||
Ok(ConversionResult::Success(s)) => {
|
Ok(ConversionResult::Success(s)) => {
|
||||||
Some(JsEvalResult::Ok(String::from(s).as_bytes().to_vec()))
|
Some(JsEvalResult::Ok(String::from(s).as_bytes().to_vec()))
|
||||||
},
|
},
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
Some(JsEvalResult::NoContent)
|
} else {
|
||||||
};
|
Some(JsEvalResult::NoContent)
|
||||||
};
|
};
|
||||||
|
|
||||||
load_data.url = ServoUrl::parse("about:blank").unwrap();
|
load_data.url = ServoUrl::parse("about:blank").unwrap();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue