mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
commit
6d1a2d90e5
1 changed files with 10 additions and 4 deletions
|
@ -10,7 +10,7 @@ use js::jsapi::{JSTracer};
|
||||||
use util::task_state;
|
use util::task_state;
|
||||||
use util::task_state::{SCRIPT, IN_GC};
|
use util::task_state::{SCRIPT, IN_GC};
|
||||||
|
|
||||||
use std::cell::{RefCell, Ref, RefMut};
|
use std::cell::{BorrowState, RefCell, Ref, RefMut};
|
||||||
|
|
||||||
/// A mutable field in the DOM.
|
/// A mutable field in the DOM.
|
||||||
///
|
///
|
||||||
|
@ -52,7 +52,7 @@ impl<T> DOMRefCell<T> {
|
||||||
///
|
///
|
||||||
/// For safety checks in debug builds only.
|
/// For safety checks in debug builds only.
|
||||||
pub fn is_mutably_borrowed(&self) -> bool {
|
pub fn is_mutably_borrowed(&self) -> bool {
|
||||||
self.value.try_borrow().is_some()
|
self.value.borrow_state() == BorrowState::Writing
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attempts to immutably borrow the wrapped value.
|
/// Attempts to immutably borrow the wrapped value.
|
||||||
|
@ -67,7 +67,10 @@ impl<T> DOMRefCell<T> {
|
||||||
/// Panics if this is called off the script thread.
|
/// Panics if this is called off the script thread.
|
||||||
pub fn try_borrow<'a>(&'a self) -> Option<Ref<'a, T>> {
|
pub fn try_borrow<'a>(&'a self) -> Option<Ref<'a, T>> {
|
||||||
debug_assert!(task_state::get().is_script());
|
debug_assert!(task_state::get().is_script());
|
||||||
self.value.try_borrow()
|
match self.value.borrow_state() {
|
||||||
|
BorrowState::Writing => None,
|
||||||
|
_ => Some(self.value.borrow()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mutably borrows the wrapped value.
|
/// Mutably borrows the wrapped value.
|
||||||
|
@ -82,7 +85,10 @@ impl<T> DOMRefCell<T> {
|
||||||
/// Panics if this is called off the script thread.
|
/// Panics if this is called off the script thread.
|
||||||
pub fn try_borrow_mut<'a>(&'a self) -> Option<RefMut<'a, T>> {
|
pub fn try_borrow_mut<'a>(&'a self) -> Option<RefMut<'a, T>> {
|
||||||
debug_assert!(task_state::get().is_script());
|
debug_assert!(task_state::get().is_script());
|
||||||
self.value.try_borrow_mut()
|
match self.value.borrow_state() {
|
||||||
|
BorrowState::Unused => Some(self.value.borrow_mut()),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue