Move checks for document completion to the end of the event loop.

This better reflects the text of the specification - rather than
queuing a task to dispatch the load evnet as soon as the document
loader is unblocked, we want to "spin the event loop until there
is nothing that delays the load event in the Document." Spinning
the event loop is a concept that requires running tasks
completely, hence we check the condition before returning to the
start of the event loop.
This commit is contained in:
Josh Matthews 2017-02-28 10:30:13 -05:00
parent 2bd02fe423
commit dc5335a21e
3 changed files with 41 additions and 7 deletions

View file

@ -483,6 +483,10 @@ pub struct ScriptThread {
/// A handle to the webvr thread, if available
webvr_thread: Option<IpcSender<WebVRMsg>>,
/// A list of pipelines containing documents that finished loading all their blocking
/// resources during a turn of the event loop.
docs_with_no_blocking_loads: DOMRefCell<HashSet<JS<Document>>>,
}
/// In the event of thread panic, all data on the stack runs its destructor. However, there
@ -567,6 +571,15 @@ impl ScriptThreadFactory for ScriptThread {
}
impl ScriptThread {
pub fn mark_document_with_no_blocked_loads(doc: &Document) {
SCRIPT_THREAD_ROOT.with(|root| {
let script_thread = unsafe { &*root.get().unwrap() };
script_thread.docs_with_no_blocking_loads
.borrow_mut()
.insert(JS::from_ref(doc));
})
}
pub fn invoke_perform_a_microtask_checkpoint() {
SCRIPT_THREAD_ROOT.with(|root| {
let script_thread = unsafe { &*root.get().unwrap() };
@ -704,7 +717,9 @@ impl ScriptThread {
layout_to_constellation_chan: state.layout_to_constellation_chan,
webvr_thread: state.webvr_thread
webvr_thread: state.webvr_thread,
docs_with_no_blocking_loads: Default::default(),
}
}
@ -885,6 +900,15 @@ impl ScriptThread {
}
}
{
// https://html.spec.whatwg.org/multipage/#the-end step 6
let mut docs = self.docs_with_no_blocking_loads.borrow_mut();
for document in docs.iter() {
document.maybe_queue_document_completion();
}
docs.clear();
}
// https://html.spec.whatwg.org/multipage/#event-loop-processing-model step 7.12
// Issue batched reflows on any pages that require it (e.g. if images loaded)