diff options
-rw-r--r-- | components/script/dom/bindings/refcounted.rs | 9 | ||||
-rw-r--r-- | components/script/script_task.rs | 5 |
2 files changed, 9 insertions, 5 deletions
diff --git a/components/script/dom/bindings/refcounted.rs b/components/script/dom/bindings/refcounted.rs index adf7d71fde5..05dd4fb43ad 100644 --- a/components/script/dom/bindings/refcounted.rs +++ b/components/script/dom/bindings/refcounted.rs @@ -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(); diff --git a/components/script/script_task.rs b/components/script/script_task.rs index d75f1f06c9e..64ffedda065 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -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. |