diff options
author | Ms2ger <ms2ger@gmail.com> | 2014-06-12 14:19:29 +0200 |
---|---|---|
committer | Ms2ger <ms2ger@gmail.com> | 2014-06-13 19:19:56 +0200 |
commit | c331b200b18728c32ad924c5bb6fc0444b077d3c (patch) | |
tree | 1388199f8de37a5bbea928c08ab60689cf592d0d /src/components/script/dom/bindings/utils.rs | |
parent | 4c5437c58b278a4a29ac520e9866217496029d79 (diff) | |
download | servo-c331b200b18728c32ad924c5bb6fc0444b077d3c.tar.gz servo-c331b200b18728c32ad924c5bb6fc0444b077d3c.zip |
Use Cell for Reflector::object.
Diffstat (limited to 'src/components/script/dom/bindings/utils.rs')
-rw-r--r-- | src/components/script/dom/bindings/utils.rs | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/components/script/dom/bindings/utils.rs b/src/components/script/dom/bindings/utils.rs index 5eb3486c20c..db104c13666 100644 --- a/src/components/script/dom/bindings/utils.rs +++ b/src/components/script/dom/bindings/utils.rs @@ -14,8 +14,9 @@ use servo_util::str::DOMString; use collections::hashmap::HashMap; use libc; use libc::c_uint; -use std::mem; +use std::cell::Cell; use std::cmp::Eq; +use std::mem; use std::ptr; use std::ptr::null; use std::slice; @@ -415,31 +416,33 @@ pub fn reflect_dom_object<T: Reflectable> #[allow(raw_pointer_deriving)] #[deriving(Eq)] pub struct Reflector { - object: *mut JSObject, + object: Cell<*mut JSObject>, } impl Reflector { #[inline] pub fn get_jsobject(&self) -> *mut JSObject { - self.object + self.object.get() } - pub fn set_jsobject(&mut self, object: *mut JSObject) { - assert!(self.object.is_null()); + pub fn set_jsobject(&self, object: *mut JSObject) { + assert!(self.object.get().is_null()); assert!(object.is_not_null()); - self.object = object; + self.object.set(object); } /// Return a pointer to the memory location at which the JS reflector object is stored. /// Used by Temporary values to root the reflector, as required by the JSAPI rooting /// APIs. - pub fn rootable<'a>(&'a mut self) -> &'a mut *mut JSObject { - &mut self.object + pub fn rootable(&self) -> *mut *mut JSObject { + &self.object as *Cell<*mut JSObject> + as *mut Cell<*mut JSObject> + as *mut *mut JSObject } pub fn new() -> Reflector { Reflector { - object: ptr::mut_null(), + object: Cell::new(ptr::mut_null()), } } } |