mirror of
https://github.com/servo/servo.git
synced 2025-06-08 08:33:26 +00:00
Improve spec-compliance of script loading and execution during document startup
Including proper support for async and deferred scripts.
This commit is contained in:
parent
6b95c3957b
commit
a0c5d47910
9 changed files with 298 additions and 128 deletions
|
@ -20,7 +20,7 @@
|
|||
use devtools;
|
||||
use devtools_traits::ScriptToDevtoolsControlMsg;
|
||||
use devtools_traits::{DevtoolScriptControlMsg, DevtoolsPageInfo};
|
||||
use document_loader::{DocumentLoader, LoadType, NotifierData};
|
||||
use document_loader::{DocumentLoader, LoadType};
|
||||
use dom::bindings::cell::DOMRefCell;
|
||||
use dom::bindings::codegen::Bindings::DocumentBinding::{DocumentMethods, DocumentReadyState};
|
||||
use dom::bindings::conversions::{Castable, FromJSValConvertible, StringificationBehavior};
|
||||
|
@ -1614,15 +1614,8 @@ impl ScriptTask {
|
|||
_ => None
|
||||
};
|
||||
|
||||
let notifier_data = {
|
||||
let MainThreadScriptChan(ref sender) = self.chan;
|
||||
NotifierData {
|
||||
script_chan: sender.clone(),
|
||||
pipeline: page.pipeline(),
|
||||
}
|
||||
};
|
||||
let loader = DocumentLoader::new_with_task(self.resource_task.clone(),
|
||||
Some(notifier_data),
|
||||
Some(page.pipeline()),
|
||||
Some(incomplete.url.clone()));
|
||||
let document = Document::new(window.r(),
|
||||
Some(final_url.clone()),
|
||||
|
@ -1935,8 +1928,11 @@ impl ScriptTask {
|
|||
let document = page.document();
|
||||
let final_url = document.r().url();
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#the-end step 1
|
||||
document.r().set_ready_state(DocumentReadyState::Interactive);
|
||||
|
||||
// TODO: Execute step 2 here.
|
||||
|
||||
// Kick off the initial reflow of the page.
|
||||
debug!("kicking off initial reflow of {:?}", final_url);
|
||||
document.r().disarm_reflow_timeout();
|
||||
|
@ -1948,14 +1944,14 @@ impl ScriptTask {
|
|||
// No more reflow required
|
||||
page.set_reflow_status(false);
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#the-end step 4
|
||||
let addr: Trusted<Document> = Trusted::new(self.get_cx(), document.r(), self.chan.clone());
|
||||
let handler = box DocumentProgressHandler::new(addr, DocumentProgressTask::DOMContentLoaded);
|
||||
self.chan.send(CommonScriptMsg::RunnableMsg(ScriptTaskEventCategory::DocumentEvent, handler)).unwrap();
|
||||
// https://html.spec.whatwg.org/multipage/#the-end steps 3-4.
|
||||
document.r().process_deferred_scripts();
|
||||
|
||||
window.r().set_fragment_name(final_url.fragment.clone());
|
||||
|
||||
// Notify devtools that a new script global exists.
|
||||
//TODO: should this happen as soon as the global is created, or at least once the first
|
||||
// script runs?
|
||||
self.notify_devtools(document.r().Title(), (*final_url).clone(), (id, None));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue