diff options
author | Josh Matthews <josh@joshmatthews.net> | 2018-12-09 22:08:33 -0500 |
---|---|---|
committer | Josh Matthews <josh@joshmatthews.net> | 2018-12-14 13:12:47 -0500 |
commit | 14b0de30dbf90793c3b6c9017e4c65df9281c5ae (patch) | |
tree | 9c136a4c1cae27258b698c74a88e78c22b551101 /components/script/dom/document.rs | |
parent | 231a37be24ee62cef69d69e0d1919b7b7f80cfed (diff) | |
download | servo-14b0de30dbf90793c3b6c9017e4c65df9281c5ae.tar.gz servo-14b0de30dbf90793c3b6c9017e4c65df9281c5ae.zip |
Prevent JS execution and layout operations while DOM in inconsistent state.
Diffstat (limited to 'components/script/dom/document.rs')
-rw-r--r-- | components/script/dom/document.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 5ee154658d7..709305f697a 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -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(); |