aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/cell.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/bindings/cell.rs')
-rw-r--r--components/script/dom/bindings/cell.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/components/script/dom/bindings/cell.rs b/components/script/dom/bindings/cell.rs
index 4aa993fec45..f15e829c87b 100644
--- a/components/script/dom/bindings/cell.rs
+++ b/components/script/dom/bindings/cell.rs
@@ -6,6 +6,7 @@ use dom::bindings::trace::JSTraceable;
use js::jsapi::{JSTracer};
use servo_util::task_state;
+use servo_util::task_state::{Script, InGC};
use std::cell::{Cell, UnsafeCell};
use std::kinds::marker;
@@ -33,6 +34,23 @@ impl<T> DOMRefCell<T> {
&*self.value.get()
}
+ /// Borrow the contents for the purpose of GC tracing.
+ ///
+ /// This succeeds even if the object is mutably borrowed,
+ /// so you have to be careful in trace code!
+ pub unsafe fn borrow_for_gc_trace<'a>(&'a self) -> &'a T {
+ debug_assert!(task_state::get().contains(Script | InGC));
+ &*self.value.get()
+ }
+
+ /// Is the cell mutably borrowed?
+ ///
+ /// For safety checks in debug builds only.
+ #[cfg(not(ndebug))]
+ pub fn is_mutably_borrowed(&self) -> bool {
+ self.borrow.get() == WRITING
+ }
+
pub fn try_borrow<'a>(&'a self) -> Option<Ref<'a, T>> {
debug_assert!(task_state::get().is_script());
match self.borrow.get() {