From f87c2a8d7616112ca924e30292db2d244cf87eec Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Tue, 26 Sep 2017 01:53:40 +0200 Subject: Rename Root to DomRoot In a later PR, DomRoot will become a type alias of Root>, where Root will be able to handle all the things that need to be rooted that have a stable traceable address that doesn't move for the whole lifetime of the root. Stay tuned. --- components/script/dom/bindings/root.rs | 58 +++++++++++++++++----------------- 1 file changed, 29 insertions(+), 29 deletions(-) (limited to 'components/script/dom/bindings/root.rs') diff --git a/components/script/dom/bindings/root.rs b/components/script/dom/bindings/root.rs index 417d4b9de52..1a81965fef9 100644 --- a/components/script/dom/bindings/root.rs +++ b/components/script/dom/bindings/root.rs @@ -11,16 +11,16 @@ //! //! Here is a brief overview of the important types: //! -//! - `Root`: a stack-based reference to a rooted DOM object. +//! - `DomRoot`: a stack-based reference to a rooted DOM object. //! - `Dom`: a reference to a DOM object that can automatically be traced by //! the GC when encountered as a field of a Rust structure. //! //! `Dom` does not allow access to their inner value without explicitly -//! creating a stack-based root via the `root` method. This returns a `Root`, +//! creating a stack-based root via the `root` method. This returns a `DomRoot`, //! which causes the JS-owned value to be uncollectable for the duration of the //! `Root` object's lifetime. A reference to the object can then be obtained //! from the `Root` object. These references are not allowed to outlive their -//! originating `Root`. +//! originating `DomRoot`. //! use core::nonzero::NonZero; @@ -259,10 +259,10 @@ impl MutDom { } /// Get the value in this `MutDom`. - pub fn get(&self) -> Root { + pub fn get(&self) -> DomRoot { debug_assert!(thread_state::get().is_script()); unsafe { - Root::from_ref(&*ptr::read(self.val.get())) + DomRoot::from_ref(&*ptr::read(self.val.get())) } } } @@ -313,8 +313,8 @@ impl MutNullableDom { /// Retrieve a copy of the current inner value. If it is `None`, it is /// initialized with the result of `cb` first. - pub fn or_init(&self, cb: F) -> Root - where F: FnOnce() -> Root + pub fn or_init(&self, cb: F) -> DomRoot + where F: FnOnce() -> DomRoot { debug_assert!(thread_state::get().is_script()); match self.get() { @@ -337,10 +337,10 @@ impl MutNullableDom { /// Get a rooted value out of this object #[allow(unrooted_must_root)] - pub fn get(&self) -> Option> { + pub fn get(&self) -> Option> { debug_assert!(thread_state::get().is_script()); unsafe { - ptr::read(self.ptr.get()).map(|o| Root::from_ref(&*o)) + ptr::read(self.ptr.get()).map(|o| DomRoot::from_ref(&*o)) } } @@ -353,7 +353,7 @@ impl MutNullableDom { } /// Gets the current value out of this object and sets it to `None`. - pub fn take(&self) -> Option> { + pub fn take(&self) -> Option> { let value = self.get(); self.set(None); value @@ -409,7 +409,7 @@ impl DomOnceCell { /// initialized with the result of `cb` first. #[allow(unrooted_must_root)] pub fn init_once(&self, cb: F) -> &T - where F: FnOnce() -> Root + where F: FnOnce() -> DomRoot { debug_assert!(thread_state::get().is_script()); &self.ptr.init_once(|| Dom::from_ref(&cb())) @@ -559,16 +559,16 @@ pub unsafe fn trace_roots(tracer: *mut JSTracer) { /// for the same JS value. `Root`s cannot outlive the associated /// `RootCollection` object. #[allow_unrooted_interior] -pub struct Root { +pub struct DomRoot { /// Reference to rooted value that must not outlive this container ptr: NonZero<*const T>, /// List that ensures correct dynamic root ordering root_list: *const RootCollection, } -impl Root { +impl DomRoot { /// Cast a DOM object root upwards to one of the interfaces it derives from. - pub fn upcast(root: Root) -> Root + pub fn upcast(root: DomRoot) -> DomRoot where U: Castable, T: DerivedFrom { @@ -576,7 +576,7 @@ impl Root { } /// Cast a DOM object root downwards to one of the interfaces it might implement. - pub fn downcast(root: Root) -> Option> + pub fn downcast(root: DomRoot) -> Option> where U: DerivedFrom { if root.is::() { @@ -587,16 +587,16 @@ impl Root { } } -impl Root { +impl DomRoot { /// Create a new stack-bounded root for the provided JS-owned value. /// It cannot outlive its associated `RootCollection`, and it gives /// out references which cannot outlive this new `Root`. - pub fn new(unrooted: NonZero<*const T>) -> Root { + pub fn new(unrooted: NonZero<*const T>) -> DomRoot { debug_assert!(thread_state::get().is_script()); STACK_ROOTS.with(|ref collection| { let RootCollectionPtr(collection) = collection.get().unwrap(); unsafe { (*collection).root(&*(*unrooted.get()).reflector()) } - Root { + DomRoot { ptr: unrooted, root_list: collection, } @@ -604,19 +604,19 @@ impl Root { } /// Generate a new root from a reference - pub fn from_ref(unrooted: &T) -> Root { - Root::new(unsafe { NonZero::new_unchecked(unrooted) }) + pub fn from_ref(unrooted: &T) -> DomRoot { + DomRoot::new(unsafe { NonZero::new_unchecked(unrooted) }) } } -impl<'root, T: DomObject + 'root> RootedReference<'root> for Root { +impl<'root, T: DomObject + 'root> RootedReference<'root> for DomRoot { type Ref = &'root T; fn r(&'root self) -> &'root T { self } } -impl Deref for Root { +impl Deref for DomRoot { type Target = T; fn deref(&self) -> &T { debug_assert!(thread_state::get().is_script()); @@ -624,25 +624,25 @@ impl Deref for Root { } } -impl HeapSizeOf for Root { +impl HeapSizeOf for DomRoot { fn heap_size_of_children(&self) -> usize { (**self).heap_size_of_children() } } -impl PartialEq for Root { +impl PartialEq for DomRoot { fn eq(&self, other: &Self) -> bool { self.ptr == other.ptr } } -impl Clone for Root { - fn clone(&self) -> Root { - Root::from_ref(&*self) +impl Clone for DomRoot { + fn clone(&self) -> DomRoot { + DomRoot::from_ref(&*self) } } -impl Drop for Root { +impl Drop for DomRoot { fn drop(&mut self) { unsafe { (*self.root_list).unroot(self.reflector()); @@ -650,7 +650,7 @@ impl Drop for Root { } } -unsafe impl JSTraceable for Root { +unsafe impl JSTraceable for DomRoot { unsafe fn trace(&self, _: *mut JSTracer) { // Already traced. } -- cgit v1.2.3