mirror of
https://github.com/servo/servo.git
synced 2025-06-14 11:24:33 +00:00
Extract some code into a new fetch_a_classic_script function.
This commit is contained in:
parent
1feeff2972
commit
20a8c97cf0
1 changed files with 30 additions and 25 deletions
|
@ -180,6 +180,35 @@ impl AsyncResponseListener for ScriptContext {
|
||||||
|
|
||||||
impl PreInvoke for ScriptContext {}
|
impl PreInvoke for ScriptContext {}
|
||||||
|
|
||||||
|
/// https://html.spec.whatwg.org/multipage/#fetch-a-classic-script
|
||||||
|
fn fetch_a_classic_script(script: &HTMLScriptElement, url: Url) {
|
||||||
|
// TODO(#9186): use the fetch infrastructure.
|
||||||
|
let context = Arc::new(Mutex::new(ScriptContext {
|
||||||
|
elem: Trusted::new(script),
|
||||||
|
data: vec!(),
|
||||||
|
metadata: None,
|
||||||
|
url: url.clone(),
|
||||||
|
status: Ok(())
|
||||||
|
}));
|
||||||
|
|
||||||
|
let doc = document_from_node(script);
|
||||||
|
|
||||||
|
let (action_sender, action_receiver) = ipc::channel().unwrap();
|
||||||
|
let listener = NetworkListener {
|
||||||
|
context: context,
|
||||||
|
script_chan: doc.window().networking_task_source(),
|
||||||
|
wrapper: Some(doc.window().get_runnable_wrapper()),
|
||||||
|
};
|
||||||
|
let response_target = AsyncResponseTarget {
|
||||||
|
sender: action_sender,
|
||||||
|
};
|
||||||
|
ROUTER.add_route(action_receiver.to_opaque(), box move |message| {
|
||||||
|
listener.notify_action(message.to().unwrap());
|
||||||
|
});
|
||||||
|
|
||||||
|
doc.load_async(LoadType::Script(url), response_target);
|
||||||
|
}
|
||||||
|
|
||||||
impl HTMLScriptElement {
|
impl HTMLScriptElement {
|
||||||
/// https://html.spec.whatwg.org/multipage/#prepare-a-script
|
/// https://html.spec.whatwg.org/multipage/#prepare-a-script
|
||||||
pub fn prepare(&self) -> NextParserState {
|
pub fn prepare(&self) -> NextParserState {
|
||||||
|
@ -297,31 +326,7 @@ impl HTMLScriptElement {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Step 18.6.
|
// Step 18.6.
|
||||||
// TODO(#9186): use the fetch infrastructure.
|
fetch_a_classic_script(self, url);
|
||||||
let elem = Trusted::new(self);
|
|
||||||
|
|
||||||
let context = Arc::new(Mutex::new(ScriptContext {
|
|
||||||
elem: elem,
|
|
||||||
data: vec!(),
|
|
||||||
metadata: None,
|
|
||||||
url: url.clone(),
|
|
||||||
status: Ok(())
|
|
||||||
}));
|
|
||||||
|
|
||||||
let (action_sender, action_receiver) = ipc::channel().unwrap();
|
|
||||||
let listener = NetworkListener {
|
|
||||||
context: context,
|
|
||||||
script_chan: doc.window().networking_task_source(),
|
|
||||||
wrapper: Some(doc.window().get_runnable_wrapper()),
|
|
||||||
};
|
|
||||||
let response_target = AsyncResponseTarget {
|
|
||||||
sender: action_sender,
|
|
||||||
};
|
|
||||||
ROUTER.add_route(action_receiver.to_opaque(), box move |message| {
|
|
||||||
listener.notify_action(message.to().unwrap());
|
|
||||||
});
|
|
||||||
|
|
||||||
doc.load_async(LoadType::Script(url), response_target);
|
|
||||||
true
|
true
|
||||||
},
|
},
|
||||||
None => false,
|
None => false,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue