auto merge of #4850 : Ms2ger/servo/root-deref, r=jdm

This commit is contained in:
bors-servo 2015-02-05 10:51:50 -07:00
commit d439c0d16d
8 changed files with 73 additions and 67 deletions

View file

@ -584,7 +584,7 @@ pub struct Root<T> {
/// List that ensures correct dynamic root ordering
root_list: &'static RootCollection,
/// Reference to rooted value that must not outlive this container
jsref: JSRef<'static, T>,
ptr: NonZero<*const T>,
/// On-stack JS pointer to assuage conservative stack scanner
js_ptr: *mut JSObject,
}
@ -596,10 +596,7 @@ impl<T: Reflectable> Root<T> {
fn new(roots: &'static RootCollection, unrooted: &JS<T>) -> Root<T> {
let root = Root {
root_list: roots,
jsref: JSRef {
ptr: unrooted.ptr.clone(),
chain: ContravariantLifetime,
},
ptr: unrooted.ptr,
js_ptr: unrooted.reflector().get_jsobject(),
};
roots.root(&root);
@ -610,7 +607,18 @@ impl<T: Reflectable> Root<T> {
/// the lifetime of this root.
pub fn r<'b>(&'b self) -> JSRef<'b, T> {
JSRef {
ptr: self.jsref.ptr,
ptr: self.ptr,
chain: ContravariantLifetime,
}
}
/// Obtain an unsafe reference to the wrapped JS owned-value that can
/// outlive the lifetime of this root.
///
/// DO NOT CALL.
pub fn get_unsound_ref_forever<'b>(&self) -> JSRef<'b, T> {
JSRef {
ptr: self.ptr,
chain: ContravariantLifetime,
}
}
@ -623,13 +631,6 @@ impl<T: Reflectable> Drop for Root<T> {
}
}
impl<'b, T: Reflectable> Deref for Root<T> {
type Target = JSRef<'b, T>;
fn deref<'c>(&'c self) -> &'c JSRef<'b, T> {
&self.jsref
}
}
impl<'a, T: Reflectable> Deref for JSRef<'a, T> {
type Target = T;
fn deref<'b>(&'b self) -> &'b T {