mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Prevent JS execution and layout operations while DOM in inconsistent state.
This commit is contained in:
parent
231a37be24
commit
14b0de30db
4 changed files with 40 additions and 0 deletions
|
@ -410,6 +410,8 @@ pub struct Document {
|
|||
responsive_images: DomRefCell<Vec<Dom<HTMLImageElement>>>,
|
||||
/// Number of redirects for the document load
|
||||
redirect_count: Cell<u16>,
|
||||
///
|
||||
script_and_layout_blockers: Cell<u32>,
|
||||
}
|
||||
|
||||
#[derive(JSTraceable, MallocSizeOf)]
|
||||
|
@ -2695,9 +2697,27 @@ impl Document {
|
|||
fired_unload: Cell::new(false),
|
||||
responsive_images: Default::default(),
|
||||
redirect_count: Cell::new(0),
|
||||
script_and_layout_blockers: Cell::new(0),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_script_and_layout_blocker(&self) {
|
||||
self.script_and_layout_blockers.set(
|
||||
self.script_and_layout_blockers.get() + 1
|
||||
);
|
||||
}
|
||||
|
||||
pub fn remove_script_and_layout_blocker(&self) {
|
||||
assert!(self.script_and_layout_blockers.get() > 0);
|
||||
self.script_and_layout_blockers.set(
|
||||
self.script_and_layout_blockers.get() - 1
|
||||
);
|
||||
}
|
||||
|
||||
pub fn ensure_safe_to_run_script_or_layout(&self) {
|
||||
assert_eq!(self.script_and_layout_blockers.get(), 0);
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-document-document
|
||||
pub fn Constructor(window: &Window) -> Fallible<DomRoot<Document>> {
|
||||
let doc = window.Document();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue