From 552a418a33442ef63839e8ea3c5bd25c4aac7833 Mon Sep 17 00:00:00 2001 From: Tetsuharu OHZEKI Date: Fri, 13 Feb 2015 05:40:46 +0900 Subject: [PATCH 1/2] Fix warnings about RefCell.try_borrow(). --- components/script/dom/bindings/cell.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/components/script/dom/bindings/cell.rs b/components/script/dom/bindings/cell.rs index fc0a845b748..f250e818412 100644 --- a/components/script/dom/bindings/cell.rs +++ b/components/script/dom/bindings/cell.rs @@ -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 DOMRefCell { /// Panics if this is called off the script thread. pub fn try_borrow<'a>(&'a self) -> Option> { 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 DOMRefCell { /// Panics if this is called off the script thread. pub fn try_borrow_mut<'a>(&'a self) -> Option> { 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, + } } } From dbb0f49bc79d90147c398406668ace4db6d5b6d5 Mon Sep 17 00:00:00 2001 From: Tetsuharu OHZEKI Date: Fri, 13 Feb 2015 05:45:06 +0900 Subject: [PATCH 2/2] DOMRefCell.is_mutably_borrowed() should return the state correctly. This method returned the result of `RefCell.try_borrow().is_some()`. But it meant whether the state **is not** BorrowState::Writing. This wrong is introduced by [1], Before it revision, this method had returned whether the state is BorrowState::Writing or not. This doesn't change callers of this method because git blames ([3], [4]) says that the caller is introduced by [2] and [2] is introduced before [1]. [1]: https://github.com/servo/servo/commit/86d609abaf7bf980a55916b90add2795cc11bf17 [2]: https://github.com/servo/servo/commit/49234484d6539a4d8df8374a9548c2004b8e68b7 [3]: https://github.com/servo/servo/blame/2cc08f289ab909de44fa09a07b2c43b70ce379b9/components/script/dom/servohtmlparser.rs [4]: https://github.com/servo/servo/blame/a7e29939a1df679bd865573dc71f7ba65f0268c4/components/script/dom/bindings/cell.rs --- components/script/dom/bindings/cell.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/script/dom/bindings/cell.rs b/components/script/dom/bindings/cell.rs index f250e818412..81085256821 100644 --- a/components/script/dom/bindings/cell.rs +++ b/components/script/dom/bindings/cell.rs @@ -52,7 +52,7 @@ impl DOMRefCell { /// /// For safety checks in debug builds only. 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.