mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Pull HTMLScriptElement::load inside-out.
This commit is contained in:
parent
180569f65f
commit
4896200467
1 changed files with 9 additions and 9 deletions
|
@ -61,7 +61,7 @@ pub struct HTMLScriptElement {
|
||||||
parser_document: JS<Document>,
|
parser_document: JS<Document>,
|
||||||
|
|
||||||
/// The source this script was loaded from
|
/// The source this script was loaded from
|
||||||
load: DOMRefCell<Option<ScriptOrigin>>,
|
load: DOMRefCell<Option<Result<ScriptOrigin, NetworkError>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HTMLScriptElement {
|
impl HTMLScriptElement {
|
||||||
|
@ -113,7 +113,7 @@ static SCRIPT_JS_MIMES: StaticStringVec = &[
|
||||||
#[derive(HeapSizeOf, JSTraceable)]
|
#[derive(HeapSizeOf, JSTraceable)]
|
||||||
pub enum ScriptOrigin {
|
pub enum ScriptOrigin {
|
||||||
Internal(DOMString, Url),
|
Internal(DOMString, Url),
|
||||||
External(Result<(String, Url), NetworkError>),
|
External(String, Url),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The context required for asynchronously loading an external script source.
|
/// The context required for asynchronously loading an external script source.
|
||||||
|
@ -172,14 +172,14 @@ impl AsyncResponseListener for ScriptContext {
|
||||||
|
|
||||||
// Step 7.
|
// Step 7.
|
||||||
let source_text = encoding.decode(&self.data, DecoderTrap::Replace).unwrap();
|
let source_text = encoding.decode(&self.data, DecoderTrap::Replace).unwrap();
|
||||||
(source_text, metadata.final_url)
|
ScriptOrigin::External(source_text, metadata.final_url)
|
||||||
});
|
});
|
||||||
|
|
||||||
// Step 9.
|
// Step 9.
|
||||||
// https://html.spec.whatwg.org/multipage/#prepare-a-script
|
// https://html.spec.whatwg.org/multipage/#prepare-a-script
|
||||||
// Step 18.6 (When the chosen algorithm asynchronously completes).
|
// Step 18.6 (When the chosen algorithm asynchronously completes).
|
||||||
let elem = self.elem.root();
|
let elem = self.elem.root();
|
||||||
*elem.load.borrow_mut() = Some(ScriptOrigin::External(load));
|
*elem.load.borrow_mut() = Some(load);
|
||||||
elem.ready_to_be_parser_executed.set(true);
|
elem.ready_to_be_parser_executed.set(true);
|
||||||
|
|
||||||
let document = document_from_node(elem.r());
|
let document = document_from_node(elem.r());
|
||||||
|
@ -374,13 +374,13 @@ impl HTMLScriptElement {
|
||||||
// TODO: check for script nesting levels.
|
// TODO: check for script nesting levels.
|
||||||
doc.get_script_blocking_stylesheets_count() > 0 {
|
doc.get_script_blocking_stylesheets_count() > 0 {
|
||||||
doc.set_pending_parsing_blocking_script(Some(self));
|
doc.set_pending_parsing_blocking_script(Some(self));
|
||||||
*self.load.borrow_mut() = Some(ScriptOrigin::Internal(text, base_url));
|
*self.load.borrow_mut() = Some(Ok(ScriptOrigin::Internal(text, base_url)));
|
||||||
self.ready_to_be_parser_executed.set(true);
|
self.ready_to_be_parser_executed.set(true);
|
||||||
// Step 20.f: otherwise.
|
// Step 20.f: otherwise.
|
||||||
} else {
|
} else {
|
||||||
assert!(!text.is_empty());
|
assert!(!text.is_empty());
|
||||||
self.ready_to_be_parser_executed.set(true);
|
self.ready_to_be_parser_executed.set(true);
|
||||||
*self.load.borrow_mut() = Some(ScriptOrigin::Internal(text, base_url));
|
*self.load.borrow_mut() = Some(Ok(ScriptOrigin::Internal(text, base_url)));
|
||||||
self.execute();
|
self.execute();
|
||||||
return NextParserState::Continue;
|
return NextParserState::Continue;
|
||||||
}
|
}
|
||||||
|
@ -411,18 +411,18 @@ impl HTMLScriptElement {
|
||||||
let load = self.load.borrow_mut().take().unwrap();
|
let load = self.load.borrow_mut().take().unwrap();
|
||||||
let (source, external, url) = match load {
|
let (source, external, url) = match load {
|
||||||
// Step 2.
|
// Step 2.
|
||||||
ScriptOrigin::External(Err(e)) => {
|
Err(e) => {
|
||||||
warn!("error loading script {:?}", e);
|
warn!("error loading script {:?}", e);
|
||||||
self.dispatch_error_event();
|
self.dispatch_error_event();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptOrigin::External(Ok((text, url))) => {
|
Ok(ScriptOrigin::External(text, url)) => {
|
||||||
debug!("loading external script, url = {}", url);
|
debug!("loading external script, url = {}", url);
|
||||||
(DOMString::from(text), true, url)
|
(DOMString::from(text), true, url)
|
||||||
},
|
},
|
||||||
|
|
||||||
ScriptOrigin::Internal(text, url) => {
|
Ok(ScriptOrigin::Internal(text, url)) => {
|
||||||
(text, false, url)
|
(text, false, url)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue