mirror of
https://github.com/servo/servo.git
synced 2025-08-02 04:00:32 +01:00
Rewrite how parser handles script scheduling
This commit is contained in:
parent
e1eff691f8
commit
c801327eab
10 changed files with 54 additions and 100 deletions
|
@ -142,12 +142,6 @@ pub enum IsHTMLDocument {
|
|||
NonHTMLDocument,
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
enum ParserBlockedByScript {
|
||||
Blocked,
|
||||
Unblocked,
|
||||
}
|
||||
|
||||
#[derive(JSTraceable, HeapSizeOf)]
|
||||
#[must_root]
|
||||
pub struct StylesheetInDocument {
|
||||
|
@ -1546,15 +1540,13 @@ impl Document {
|
|||
self.process_asap_scripts();
|
||||
}
|
||||
|
||||
if self.maybe_execute_parser_blocking_script() == ParserBlockedByScript::Blocked {
|
||||
return;
|
||||
}
|
||||
|
||||
// A finished resource load can potentially unblock parsing. In that case, resume the
|
||||
// parser so its loop can find out.
|
||||
if let Some(parser) = self.get_current_parser() {
|
||||
if parser.is_suspended() {
|
||||
parser.resume();
|
||||
if let Some(script) = self.pending_parsing_blocking_script.get() {
|
||||
if self.script_blocking_stylesheets_count.get() > 0 || !script.is_ready_to_be_executed() {
|
||||
return;
|
||||
}
|
||||
self.pending_parsing_blocking_script.set(None);
|
||||
parser.resume_with_pending_parsing_blocking_script(&script);
|
||||
}
|
||||
} else if self.reflow_timeout.get().is_none() {
|
||||
// If we don't have a parser, and the reflow timer has been reset, explicitly
|
||||
|
@ -1577,23 +1569,6 @@ impl Document {
|
|||
}
|
||||
}
|
||||
|
||||
/// If document parsing is blocked on a script, and that script is ready to run,
|
||||
/// execute it.
|
||||
/// https://html.spec.whatwg.org/multipage/#ready-to-be-parser-executed
|
||||
fn maybe_execute_parser_blocking_script(&self) -> ParserBlockedByScript {
|
||||
let script = match self.pending_parsing_blocking_script.get() {
|
||||
None => return ParserBlockedByScript::Unblocked,
|
||||
Some(script) => script,
|
||||
};
|
||||
|
||||
if self.script_blocking_stylesheets_count.get() == 0 && script.is_ready_to_be_executed() {
|
||||
self.pending_parsing_blocking_script.set(None);
|
||||
script.execute();
|
||||
return ParserBlockedByScript::Unblocked;
|
||||
}
|
||||
ParserBlockedByScript::Blocked
|
||||
}
|
||||
|
||||
/// https://html.spec.whatwg.org/multipage/#the-end step 3
|
||||
pub fn process_deferred_scripts(&self) {
|
||||
if self.ready_state.get() != DocumentReadyState::Interactive {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue