mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Auto merge of #15128 - nox:load-fixes, r=Ms2ger
Simplify how we handle script scheduling and delaying the load event <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15128) <!-- Reviewable:end -->
This commit is contained in:
commit
830fe189ad
2 changed files with 41 additions and 44 deletions
|
@ -229,7 +229,7 @@ pub struct Document {
|
||||||
/// https://html.spec.whatwg.org/multipage/#list-of-scripts-that-will-execute-in-order-as-soon-as-possible
|
/// https://html.spec.whatwg.org/multipage/#list-of-scripts-that-will-execute-in-order-as-soon-as-possible
|
||||||
asap_in_order_scripts_list: PendingInOrderScriptVec,
|
asap_in_order_scripts_list: PendingInOrderScriptVec,
|
||||||
/// https://html.spec.whatwg.org/multipage/#set-of-scripts-that-will-execute-as-soon-as-possible
|
/// https://html.spec.whatwg.org/multipage/#set-of-scripts-that-will-execute-as-soon-as-possible
|
||||||
asap_scripts_set: DOMRefCell<VecDeque<PendingScript>>,
|
asap_scripts_set: DOMRefCell<Vec<JS<HTMLScriptElement>>>,
|
||||||
/// https://html.spec.whatwg.org/multipage/#concept-n-noscript
|
/// https://html.spec.whatwg.org/multipage/#concept-n-noscript
|
||||||
/// True if scripting is enabled for all scripts in this document
|
/// True if scripting is enabled for all scripts in this document
|
||||||
scripting_enabled: Cell<bool>,
|
scripting_enabled: Cell<bool>,
|
||||||
|
@ -1547,29 +1547,15 @@ impl Document {
|
||||||
loader.finish_load(&load);
|
loader.finish_load(&load);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let LoadType::Script(_) = load {
|
match load {
|
||||||
self.process_deferred_scripts();
|
LoadType::Stylesheet(_) => {
|
||||||
self.process_asap_scripts();
|
self.process_deferred_scripts();
|
||||||
}
|
self.process_pending_parsing_blocking_script();
|
||||||
|
},
|
||||||
if let Some(parser) = self.get_current_parser() {
|
LoadType::PageSource(_) => {
|
||||||
let ready_to_be_executed = match self.pending_parsing_blocking_script.borrow_mut().as_mut() {
|
self.process_deferred_scripts();
|
||||||
Some(pending) => {
|
},
|
||||||
if self.script_blocking_stylesheets_count.get() > 0 {
|
_ => {},
|
||||||
return;
|
|
||||||
}
|
|
||||||
if let Some(pair) = pending.take_result() {
|
|
||||||
Some(pair)
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
None => None,
|
|
||||||
};
|
|
||||||
if let Some((element, result)) = ready_to_be_executed {
|
|
||||||
*self.pending_parsing_blocking_script.borrow_mut() = None;
|
|
||||||
parser.resume_with_pending_parsing_blocking_script(&element, result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.loader.borrow().is_blocked() && !self.loader.borrow().events_inhibited() {
|
if !self.loader.borrow().is_blocked() && !self.loader.borrow().events_inhibited() {
|
||||||
|
@ -1594,23 +1580,42 @@ impl Document {
|
||||||
|
|
||||||
/// https://html.spec.whatwg.org/multipage/#prepare-a-script step 22.d.
|
/// https://html.spec.whatwg.org/multipage/#prepare-a-script step 22.d.
|
||||||
pub fn pending_parsing_blocking_script_loaded(&self, element: &HTMLScriptElement, result: ScriptResult) {
|
pub fn pending_parsing_blocking_script_loaded(&self, element: &HTMLScriptElement, result: ScriptResult) {
|
||||||
let mut blocking_script = self.pending_parsing_blocking_script.borrow_mut();
|
{
|
||||||
let entry = blocking_script.as_mut().unwrap();
|
let mut blocking_script = self.pending_parsing_blocking_script.borrow_mut();
|
||||||
assert!(&*entry.element == element);
|
let entry = blocking_script.as_mut().unwrap();
|
||||||
entry.loaded(result);
|
assert!(&*entry.element == element);
|
||||||
|
entry.loaded(result);
|
||||||
|
}
|
||||||
|
self.process_pending_parsing_blocking_script();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn process_pending_parsing_blocking_script(&self) {
|
||||||
|
if self.script_blocking_stylesheets_count.get() > 0 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let pair = self.pending_parsing_blocking_script
|
||||||
|
.borrow_mut()
|
||||||
|
.as_mut()
|
||||||
|
.and_then(PendingScript::take_result);
|
||||||
|
if let Some((element, result)) = pair {
|
||||||
|
*self.pending_parsing_blocking_script.borrow_mut() = None;
|
||||||
|
self.get_current_parser().unwrap().resume_with_pending_parsing_blocking_script(&element, result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_asap_script(&self, script: &HTMLScriptElement) {
|
pub fn add_asap_script(&self, script: &HTMLScriptElement) {
|
||||||
self.asap_scripts_set.borrow_mut().push_back(PendingScript::new(script));
|
self.asap_scripts_set.borrow_mut().push(JS::from_ref(script));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://html.spec.whatwg.org/multipage/#the-end step 3.
|
/// https://html.spec.whatwg.org/multipage/#the-end step 3.
|
||||||
/// https://html.spec.whatwg.org/multipage/#prepare-a-script step 22.d.
|
/// https://html.spec.whatwg.org/multipage/#prepare-a-script step 22.d.
|
||||||
pub fn asap_script_loaded(&self, element: &HTMLScriptElement, result: ScriptResult) {
|
pub fn asap_script_loaded(&self, element: &HTMLScriptElement, result: ScriptResult) {
|
||||||
let mut scripts = self.asap_scripts_set.borrow_mut();
|
{
|
||||||
let idx = scripts.iter().position(|entry| &*entry.element == element).unwrap();
|
let mut scripts = self.asap_scripts_set.borrow_mut();
|
||||||
scripts.swap(0, idx);
|
let idx = scripts.iter().position(|entry| &**entry == element).unwrap();
|
||||||
scripts[0].loaded(result);
|
scripts.swap_remove(idx);
|
||||||
|
}
|
||||||
|
element.execute(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn push_asap_in_order_script(&self, script: &HTMLScriptElement) {
|
pub fn push_asap_in_order_script(&self, script: &HTMLScriptElement) {
|
||||||
|
@ -1623,14 +1628,6 @@ impl Document {
|
||||||
element: &HTMLScriptElement,
|
element: &HTMLScriptElement,
|
||||||
result: ScriptResult) {
|
result: ScriptResult) {
|
||||||
self.asap_in_order_scripts_list.loaded(element, result);
|
self.asap_in_order_scripts_list.loaded(element, result);
|
||||||
}
|
|
||||||
|
|
||||||
fn process_asap_scripts(&self) {
|
|
||||||
let pair = self.asap_scripts_set.borrow_mut().front_mut().and_then(PendingScript::take_result);
|
|
||||||
if let Some((element, result)) = pair {
|
|
||||||
self.asap_scripts_set.borrow_mut().pop_front();
|
|
||||||
element.execute(result);
|
|
||||||
}
|
|
||||||
while let Some((element, result)) = self.asap_in_order_scripts_list.take_next_ready_to_be_executed() {
|
while let Some((element, result)) = self.asap_in_order_scripts_list.take_next_ready_to_be_executed() {
|
||||||
element.execute(result);
|
element.execute(result);
|
||||||
}
|
}
|
||||||
|
@ -1643,10 +1640,11 @@ impl Document {
|
||||||
/// https://html.spec.whatwg.org/multipage/#prepare-a-script step 22.d.
|
/// https://html.spec.whatwg.org/multipage/#prepare-a-script step 22.d.
|
||||||
pub fn deferred_script_loaded(&self, element: &HTMLScriptElement, result: ScriptResult) {
|
pub fn deferred_script_loaded(&self, element: &HTMLScriptElement, result: ScriptResult) {
|
||||||
self.deferred_scripts.loaded(element, result);
|
self.deferred_scripts.loaded(element, result);
|
||||||
|
self.process_deferred_scripts();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://html.spec.whatwg.org/multipage/#the-end step 3.
|
/// https://html.spec.whatwg.org/multipage/#the-end step 3.
|
||||||
pub fn process_deferred_scripts(&self) {
|
fn process_deferred_scripts(&self) {
|
||||||
if self.ready_state.get() != DocumentReadyState::Interactive {
|
if self.ready_state.get() != DocumentReadyState::Interactive {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -359,9 +359,8 @@ impl ServoParser {
|
||||||
window.reflow(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery, ReflowReason::FirstLoad);
|
window.reflow(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery, ReflowReason::FirstLoad);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Steps 3-12 are in other castles, namely process_deferred_scripts and finish_load.
|
// Steps 3-12 are in another castle, namely finish_load.
|
||||||
let url = self.tokenizer.borrow().url().clone();
|
let url = self.tokenizer.borrow().url().clone();
|
||||||
self.document.process_deferred_scripts();
|
|
||||||
self.document.finish_load(LoadType::PageSource(url));
|
self.document.finish_load(LoadType::PageSource(url));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue