diff options
author | Anthony Ramine <n.oxyde@gmail.com> | 2016-08-20 20:37:54 +0200 |
---|---|---|
committer | Anthony Ramine <n.oxyde@gmail.com> | 2016-08-20 20:37:54 +0200 |
commit | 2e310f83ad53c919858230ffac429482ee44ef9a (patch) | |
tree | 134212c8bb41ea28c09eb2708ebe8a56d6f41515 /components/script/dom | |
parent | ef2ee4646fedc45e37fdf16658a70c849744ed32 (diff) | |
download | servo-2e310f83ad53c919858230ffac429482ee44ef9a.tar.gz servo-2e310f83ad53c919858230ffac429482ee44ef9a.zip |
Use feature try_borrow instead of borrow_state in script
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/bindings/cell.rs | 75 |
1 files changed, 31 insertions, 44 deletions
diff --git a/components/script/dom/bindings/cell.rs b/components/script/dom/bindings/cell.rs index 37143165a7d..3eb2a978c7a 100644 --- a/components/script/dom/bindings/cell.rs +++ b/components/script/dom/bindings/cell.rs @@ -6,7 +6,7 @@ use dom::bindings::trace::JSTraceable; use js::jsapi::JSTracer; -use std::cell::{BorrowState, Ref, RefCell, RefMut}; +use std::cell::{BorrowError, BorrowMutError, Ref, RefCell, RefMut}; use util::thread_state; use util::thread_state::SCRIPT; @@ -52,49 +52,6 @@ impl<T> DOMRefCell<T> { &mut *self.value.as_unsafe_cell().get() } - /// Is the cell mutably borrowed? - /// - /// For safety checks in debug builds only. - pub fn is_mutably_borrowed(&self) -> bool { - self.value.borrow_state() == BorrowState::Writing - } - - /// Attempts to immutably borrow the wrapped value. - /// - /// The borrow lasts until the returned `Ref` exits scope. Multiple - /// immutable borrows can be taken out at the same time. - /// - /// Returns `None` if the value is currently mutably borrowed. - /// - /// # Panics - /// - /// Panics if this is called off the script thread. - pub fn try_borrow(&self) -> Option<Ref<T>> { - debug_assert!(thread_state::get().is_script()); - match self.value.borrow_state() { - BorrowState::Writing => None, - _ => Some(self.value.borrow()), - } - } - - /// Mutably borrows the wrapped value. - /// - /// The borrow lasts until the returned `RefMut` exits scope. The value - /// cannot be borrowed while this borrow is active. - /// - /// Returns `None` if the value is currently borrowed. - /// - /// # Panics - /// - /// Panics if this is called off the script thread. - pub fn try_borrow_mut(&self) -> Option<RefMut<T>> { - debug_assert!(thread_state::get().is_script()); - match self.value.borrow_state() { - BorrowState::Unused => Some(self.value.borrow_mut()), - _ => None, - } - } - /// Version of the above that we use during restyle while the script thread /// is blocked. pub fn borrow_mut_for_layout(&self) -> RefMut<T> { @@ -149,4 +106,34 @@ impl<T> DOMRefCell<T> { pub fn borrow_mut(&self) -> RefMut<T> { self.try_borrow_mut().expect("DOMRefCell<T> already borrowed") } + + /// Attempts to immutably borrow the wrapped value. + /// + /// The borrow lasts until the returned `Ref` exits scope. Multiple + /// immutable borrows can be taken out at the same time. + /// + /// Returns `None` if the value is currently mutably borrowed. + /// + /// # Panics + /// + /// Panics if this is called off the script thread. + pub fn try_borrow(&self) -> Result<Ref<T>, BorrowError<T>> { + debug_assert!(thread_state::get().is_script()); + self.value.try_borrow() + } + + /// Mutably borrows the wrapped value. + /// + /// The borrow lasts until the returned `RefMut` exits scope. The value + /// cannot be borrowed while this borrow is active. + /// + /// Returns `None` if the value is currently borrowed. + /// + /// # Panics + /// + /// Panics if this is called off the script thread. + pub fn try_borrow_mut(&self) -> Result<RefMut<T>, BorrowMutError<T>> { + debug_assert!(thread_state::get().is_script()); + self.value.try_borrow_mut() + } } |