From 552a418a33442ef63839e8ea3c5bd25c4aac7833 Mon Sep 17 00:00:00 2001 From: Tetsuharu OHZEKI Date: Fri, 13 Feb 2015 05:40:46 +0900 Subject: [PATCH] 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, + } } }