From a60bbc81b892d123917750fef71e64df1502d048 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sun, 15 Jan 2017 16:31:17 +0100 Subject: [PATCH] Reorder some Document methods to put them together --- components/script/dom/document.rs | 102 +++++++++++++++--------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index fc3025615a7..ae0cf9a0e27 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -1450,29 +1450,6 @@ impl Document { changed } - pub fn set_pending_parsing_blocking_script(&self, - script: &HTMLScriptElement, - load: Option) { - assert!(!self.has_pending_parsing_blocking_script()); - *self.pending_parsing_blocking_script.borrow_mut() = Some(PendingScript::new_with_load(script, load)); - } - - pub fn has_pending_parsing_blocking_script(&self) -> bool { - self.pending_parsing_blocking_script.borrow().is_some() - } - - pub fn add_deferred_script(&self, script: &HTMLScriptElement) { - self.deferred_scripts.push(script); - } - - pub fn add_asap_script(&self, script: &HTMLScriptElement) { - self.asap_scripts_set.borrow_mut().push_back(PendingScript::new(script)); - } - - pub fn push_asap_in_order_script(&self, script: &HTMLScriptElement) { - self.asap_in_order_scripts_list.push(script); - } - pub fn trigger_mozbrowser_event(&self, event: MozBrowserEvent) { if PREFS.is_mozbrowser_enabled() { if let Some((parent_pipeline_id, _)) = self.window.parent_info() { @@ -1613,6 +1590,17 @@ impl Document { } } + pub fn set_pending_parsing_blocking_script(&self, + script: &HTMLScriptElement, + load: Option) { + assert!(!self.has_pending_parsing_blocking_script()); + *self.pending_parsing_blocking_script.borrow_mut() = Some(PendingScript::new_with_load(script, load)); + } + + pub fn has_pending_parsing_blocking_script(&self) -> bool { + self.pending_parsing_blocking_script.borrow().is_some() + } + /// https://html.spec.whatwg.org/multipage/#prepare-a-script step 22.d. pub fn pending_parsing_blocking_script_loaded(&self, element: &HTMLScriptElement, result: ScriptResult) { let mut blocking_script = self.pending_parsing_blocking_script.borrow_mut(); @@ -1621,6 +1609,46 @@ impl Document { entry.loaded(result); } + pub fn add_asap_script(&self, script: &HTMLScriptElement) { + self.asap_scripts_set.borrow_mut().push_back(PendingScript::new(script)); + } + + /// https://html.spec.whatwg.org/multipage/#the-end step 3. + /// https://html.spec.whatwg.org/multipage/#prepare-a-script step 22.d. + 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(); + scripts.swap(0, idx); + scripts[0].loaded(result); + } + + pub fn push_asap_in_order_script(&self, script: &HTMLScriptElement) { + self.asap_in_order_scripts_list.push(script); + } + + /// https://html.spec.whatwg.org/multipage/#the-end step 3. + /// https://html.spec.whatwg.org/multipage/#prepare-a-script step 22.c. + pub fn asap_in_order_script_loaded(&self, + element: &HTMLScriptElement, + result: ScriptResult) { + 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() { + element.execute(result); + } + } + + pub fn add_deferred_script(&self, script: &HTMLScriptElement) { + self.deferred_scripts.push(script); + } + /// https://html.spec.whatwg.org/multipage/#prepare-a-script step 22.d. pub fn deferred_script_loaded(&self, element: &HTMLScriptElement, result: ScriptResult) { self.deferred_scripts.loaded(element, result); @@ -1648,34 +1676,6 @@ impl Document { } } - /// https://html.spec.whatwg.org/multipage/#the-end step 3. - /// https://html.spec.whatwg.org/multipage/#prepare-a-script step 22.d. - 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(); - scripts.swap(0, idx); - scripts[0].loaded(result); - } - - /// https://html.spec.whatwg.org/multipage/#the-end step 3. - /// https://html.spec.whatwg.org/multipage/#prepare-a-script step 22.c. - pub fn asap_in_order_script_loaded(&self, - element: &HTMLScriptElement, - result: ScriptResult) { - 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() { - element.execute(result); - } - } - pub fn maybe_dispatch_dom_content_loaded(&self) { if self.domcontentloaded_dispatched.get() { return;