Fix warnings about RefCell<T>.try_borrow().

This commit is contained in:
Tetsuharu OHZEKI 2015-02-13 05:40:46 +09:00
parent b655b54f80
commit 552a418a33

View file

@ -10,7 +10,7 @@ use js::jsapi::{JSTracer};
use util::task_state;
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.
///
@ -67,7 +67,10 @@ impl<T> DOMRefCell<T> {
/// Panics if this is called off the script thread.
pub fn try_borrow<'a>(&'a self) -> Option<Ref<'a, T>> {
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.
@ -82,7 +85,10 @@ impl<T> DOMRefCell<T> {
/// Panics if this is called off the script thread.
pub fn try_borrow_mut<'a>(&'a self) -> Option<RefMut<'a, T>> {
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,
}
}
}