auto merge of #4705 : Ms2ger/servo/refcounted, r=larsbergstrom

This will allow us to make them Send in the future.
This commit is contained in:
bors-servo 2015-01-21 12:09:56 -07:00
commit ad328fda65
2 changed files with 9 additions and 5 deletions

View file

@ -39,6 +39,9 @@ use std::sync::{Arc, Mutex};
thread_local!(pub static LIVE_REFERENCES: Rc<RefCell<Option<LiveDOMReferences>>> = Rc::new(RefCell::new(None)))
/// A pointer to a Rust DOM object that needs to be destroyed.
pub struct TrustedReference(*const libc::c_void);
/// A safe wrapper around a raw pointer to a DOM object that can be
/// shared among tasks for use in asynchronous operations. The underlying
/// DOM object is guaranteed to live at least as long as the last outstanding
@ -108,7 +111,8 @@ impl<T: Reflectable> Drop for Trusted<T> {
assert!(*refcount > 0);
*refcount -= 1;
if *refcount == 0 {
self.script_chan.send(ScriptMsg::RefcountCleanup(self.ptr));
self.script_chan.send(
ScriptMsg::RefcountCleanup(TrustedReference(self.ptr)));
}
}
}
@ -151,7 +155,8 @@ impl LiveDOMReferences {
}
/// Unpin the given DOM object if its refcount is 0.
pub fn cleanup(cx: *mut JSContext, raw_reflectable: *const libc::c_void) {
pub fn cleanup(cx: *mut JSContext, raw_reflectable: TrustedReference) {
let TrustedReference(raw_reflectable) = raw_reflectable;
LIVE_REFERENCES.with(|ref r| {
let r = r.borrow();
let live_references = r.as_ref().unwrap();

View file

@ -18,7 +18,7 @@ use dom::bindings::conversions::StringificationBehavior;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JS, JSRef, Temporary, OptionalRootable};
use dom::bindings::js::{RootCollection, RootCollectionPtr};
use dom::bindings::refcounted::{LiveDOMReferences, Trusted};
use dom::bindings::refcounted::{LiveDOMReferences, Trusted, TrustedReference};
use dom::bindings::structuredclone::StructuredCloneData;
use dom::bindings::trace::JSTraceable;
use dom::bindings::utils::{wrap_for_same_compartment, pre_wrap};
@ -77,7 +77,6 @@ use js::rust::{Cx, RtUtils};
use js;
use url::Url;
use libc;
use std::any::{Any, AnyRefExt};
use std::borrow::ToOwned;
use std::cell::Cell;
@ -125,7 +124,7 @@ pub enum ScriptMsg {
/// Generic message that encapsulates event handling.
RunnableMsg(Box<Runnable+Send>),
/// A DOM object's last pinned reference was removed (dispatched to all tasks).
RefcountCleanup(*const libc::c_void),
RefcountCleanup(TrustedReference),
}
/// A cloneable interface for communicating with an event loop.