diff options
author | Anthony Ramine <n.oxyde@gmail.com> | 2017-09-26 01:53:40 +0200 |
---|---|---|
committer | Anthony Ramine <n.oxyde@gmail.com> | 2017-09-26 09:49:10 +0200 |
commit | f87c2a8d7616112ca924e30292db2d244cf87eec (patch) | |
tree | 7344afe7ec0ec1ac7d1d13f5385111ee9c4be332 /components/script/dom/bindings | |
parent | 577370746e2ce3da7fa25a20b8e1bbeed319df65 (diff) | |
download | servo-f87c2a8d7616112ca924e30292db2d244cf87eec.tar.gz servo-f87c2a8d7616112ca924e30292db2d244cf87eec.zip |
Rename Root<T> to DomRoot<T>
In a later PR, DomRoot<T> will become a type alias of Root<Dom<T>>,
where Root<T> 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.
Diffstat (limited to 'components/script/dom/bindings')
-rw-r--r-- | components/script/dom/bindings/callback.rs | 4 | ||||
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 26 | ||||
-rw-r--r-- | components/script/dom/bindings/codegen/Configuration.py | 2 | ||||
-rw-r--r-- | components/script/dom/bindings/conversions.rs | 24 | ||||
-rw-r--r-- | components/script/dom/bindings/interface.rs | 10 | ||||
-rw-r--r-- | components/script/dom/bindings/iterable.rs | 4 | ||||
-rw-r--r-- | components/script/dom/bindings/refcounted.rs | 6 | ||||
-rw-r--r-- | components/script/dom/bindings/reflector.rs | 8 | ||||
-rw-r--r-- | components/script/dom/bindings/root.rs | 58 | ||||
-rw-r--r-- | components/script/dom/bindings/settings_stack.rs | 14 | ||||
-rw-r--r-- | components/script/dom/bindings/structuredclone.rs | 4 | ||||
-rw-r--r-- | components/script/dom/bindings/trace.rs | 14 | ||||
-rw-r--r-- | components/script/dom/bindings/weakref.rs | 12 |
13 files changed, 95 insertions, 91 deletions
diff --git a/components/script/dom/bindings/callback.rs b/components/script/dom/bindings/callback.rs index 15458499782..7a73ce60215 100644 --- a/components/script/dom/bindings/callback.rs +++ b/components/script/dom/bindings/callback.rs @@ -6,7 +6,7 @@ use dom::bindings::error::{Error, Fallible, report_pending_exception}; use dom::bindings::reflector::DomObject; -use dom::bindings::root::{Dom, Root}; +use dom::bindings::root::{Dom, DomRoot}; use dom::bindings::settings_stack::{AutoEntryScript, AutoIncumbentScript}; use dom::bindings::utils::AsCCharPtrPtr; use dom::globalscope::GlobalScope; @@ -223,7 +223,7 @@ pub fn wrap_call_this_object<T: DomObject>(cx: *mut JSContext, pub struct CallSetup { /// The global for reporting exceptions. This is the global object of the /// (possibly wrapped) callback object. - exception_global: Root<GlobalScope>, + exception_global: DomRoot<GlobalScope>, /// The `JSContext` used for the call. cx: *mut JSContext, /// The compartment we were in before the call. diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 888a17a3a8c..8880707f7d5 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -2254,7 +2254,7 @@ def UnionTypes(descriptors, dictionaries, callbacks, typedefs, config): 'dom::bindings::conversions::root_from_handlevalue', 'dom::bindings::error::throw_not_in_union', 'dom::bindings::mozmap::MozMap', - 'dom::bindings::root::Root', + 'dom::bindings::root::DomRoot', 'dom::bindings::str::ByteString', 'dom::bindings::str::DOMString', 'dom::bindings::str::USVString', @@ -2558,7 +2558,7 @@ class CGWrapMethod(CGAbstractMethod): args = [Argument('*mut JSContext', 'cx'), Argument('&GlobalScope', 'scope'), Argument("Box<%s>" % descriptor.concreteType, 'object')] - retval = 'Root<%s>' % descriptor.concreteType + retval = 'DomRoot<%s>' % descriptor.concreteType CGAbstractMethod.__init__(self, descriptor, 'Wrap', retval, args, pub=True, unsafe=True) @@ -2580,7 +2580,7 @@ assert!(!proto.is_null()); %(copyUnforgeable)s (*raw).init_reflector(obj.get()); -Root::from_ref(&*raw)""" % {'copyUnforgeable': unforgeable, 'createObject': create}) +DomRoot::from_ref(&*raw)""" % {'copyUnforgeable': unforgeable, 'createObject': create}) class CGWrapGlobalMethod(CGAbstractMethod): @@ -2592,7 +2592,7 @@ class CGWrapGlobalMethod(CGAbstractMethod): assert descriptor.isGlobal() args = [Argument('*mut JSContext', 'cx'), Argument("Box<%s>" % descriptor.concreteType, 'object')] - retval = 'Root<%s>' % descriptor.concreteType + retval = 'DomRoot<%s>' % descriptor.concreteType CGAbstractMethod.__init__(self, descriptor, 'Wrap', retval, args, pub=True, unsafe=True) self.properties = properties @@ -2638,7 +2638,7 @@ assert!(immutable); %(unforgeable)s -Root::from_ref(&*raw)\ +DomRoot::from_ref(&*raw)\ """ % values) @@ -3421,7 +3421,9 @@ class CGAbstractStaticBindingMethod(CGAbstractMethod): def definition_body(self): preamble = "let global = GlobalScope::from_object(JS_CALLEE(cx, vp).to_object());\n" if len(self.exposureSet) == 1: - preamble += "let global = Root::downcast::<dom::types::%s>(global).unwrap();\n" % list(self.exposureSet)[0] + preamble += """ +let global = DomRoot::downcast::<dom::types::%s>(global).unwrap(); +""" % list(self.exposureSet)[0] return CGList([CGGeneric(preamble), self.generate_code()]) def generate_code(self): @@ -5352,7 +5354,9 @@ class CGClassConstructHook(CGAbstractExternMethod): def definition_body(self): preamble = """let global = GlobalScope::from_object(JS_CALLEE(cx, vp).to_object());\n""" if len(self.exposureSet) == 1: - preamble += "let global = Root::downcast::<dom::types::%s>(global).unwrap();\n" % list(self.exposureSet)[0] + preamble += """\ +let global = DomRoot::downcast::<dom::types::%s>(global).unwrap(); +""" % list(self.exposureSet)[0] preamble += """let args = CallArgs::from_vp(vp, argc);\n""" preamble = CGGeneric(preamble) if self.constructor.isHTMLConstructor(): @@ -5408,7 +5412,7 @@ if !JS_WrapObject(cx, prototype.handle_mut()) { return false; } -let result: Result<Root<%s>, Error> = html_constructor(&global, &args); +let result: Result<DomRoot<%s>, Error> = html_constructor(&global, &args); let result = match result { Ok(result) => result, Err(e) => { @@ -5713,8 +5717,8 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries 'dom::bindings::reflector::MutDomObject', 'dom::bindings::reflector::DomObject', 'dom::bindings::root::Dom', + 'dom::bindings::root::DomRoot', 'dom::bindings::root::OptionalHeapSetter', - 'dom::bindings::root::Root', 'dom::bindings::root::RootedReference', 'dom::bindings::utils::AsVoidPtr', 'dom::bindings::utils::DOMClass', @@ -6281,7 +6285,7 @@ class CGRegisterProxyHandlers(CGThing): class CGBindingRoot(CGThing): """ - Root codegen class for binding generation. Instantiate the class, and call + DomRoot codegen class for binding generation. Instantiate the class, and call declare or define to generate header or cpp code (respectively). """ def __init__(self, config, prefix, webIDLFile): @@ -7195,7 +7199,7 @@ class GlobalGenRoots(): imports = [CGGeneric("use dom::types::*;\n"), CGGeneric("use dom::bindings::conversions::{DerivedFrom, get_dom_class};\n"), CGGeneric("use dom::bindings::inheritance::Castable;\n"), - CGGeneric("use dom::bindings::root::{Dom, LayoutDom, Root};\n"), + CGGeneric("use dom::bindings::root::{Dom, DomRoot, LayoutDom};\n"), CGGeneric("use dom::bindings::trace::JSTraceable;\n"), CGGeneric("use dom::bindings::reflector::DomObject;\n"), CGGeneric("use js::jsapi::JSTracer;\n\n"), diff --git a/components/script/dom/bindings/codegen/Configuration.py b/components/script/dom/bindings/codegen/Configuration.py index df6c0a36c76..56141e52b09 100644 --- a/components/script/dom/bindings/codegen/Configuration.py +++ b/components/script/dom/bindings/codegen/Configuration.py @@ -212,7 +212,7 @@ class Descriptor(DescriptorProvider): self.argumentType = "???" self.nativeType = ty else: - self.returnType = "Root<%s>" % typeName + self.returnType = "DomRoot<%s>" % typeName self.argumentType = "&%s" % typeName self.nativeType = "*const %s" % typeName if self.interface.isIteratorInterface(): diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs index 7528830ea7c..075f681308e 100644 --- a/components/script/dom/bindings/conversions.rs +++ b/components/script/dom/bindings/conversions.rs @@ -24,7 +24,7 @@ //! | USVString | `USVString` | //! | ByteString | `ByteString` | //! | object | `*mut JSObject` | -//! | interface types | `&T` | `Root<T>` | +//! | interface types | `&T` | `DomRoot<T>` | //! | dictionary types | `&T` | *unsupported* | //! | enumeration types | `T` | //! | callback function types | `Rc<T>` | @@ -36,7 +36,7 @@ use dom::bindings::error::{Error, Fallible}; use dom::bindings::inheritance::Castable; use dom::bindings::num::Finite; use dom::bindings::reflector::{DomObject, Reflector}; -use dom::bindings::root::Root; +use dom::bindings::root::DomRoot; use dom::bindings::str::{ByteString, DOMString, USVString}; use dom::bindings::trace::{JSTraceable, RootedTraceableBox}; use dom::bindings::utils::DOMClass; @@ -102,13 +102,13 @@ impl<T: Float + FromJSValConvertible<Config=()>> FromJSValConvertible for Finite } } -impl <T: DomObject + IDLInterface> FromJSValConvertible for Root<T> { +impl <T: DomObject + IDLInterface> FromJSValConvertible for DomRoot<T> { type Config = (); unsafe fn from_jsval(_cx: *mut JSContext, value: HandleValue, _config: Self::Config) - -> Result<ConversionResult<Root<T>>, ()> { + -> Result<ConversionResult<DomRoot<T>>, ()> { Ok(match root_from_handlevalue(value) { Ok(result) => ConversionResult::Success(result), Err(()) => ConversionResult::Failure("value is not an object".into()), @@ -405,16 +405,16 @@ pub fn native_from_object<T>(obj: *mut JSObject) -> Result<*const T, ()> } } -/// Get a `Root<T>` for the given DOM object, unwrapping any wrapper +/// Get a `DomRoot<T>` for the given DOM object, unwrapping any wrapper /// around it first, and checking if the object is of the correct type. /// /// Returns Err(()) if `obj` is an opaque security wrapper or if the object is /// not a reflector for a DOM object of the given type (as defined by the /// proto_id and proto_depth). -pub fn root_from_object<T>(obj: *mut JSObject) -> Result<Root<T>, ()> +pub fn root_from_object<T>(obj: *mut JSObject) -> Result<DomRoot<T>, ()> where T: DomObject + IDLInterface { - native_from_object(obj).map(|ptr| unsafe { Root::from_ref(&*ptr) }) + native_from_object(obj).map(|ptr| unsafe { DomRoot::from_ref(&*ptr) }) } /// Get a `*const T` for a DOM object accessible from a `HandleValue`. @@ -428,9 +428,9 @@ pub fn native_from_handlevalue<T>(v: HandleValue) -> Result<*const T, ()> native_from_object(v.get().to_object()) } -/// Get a `Root<T>` for a DOM object accessible from a `HandleValue`. +/// Get a `DomRoot<T>` for a DOM object accessible from a `HandleValue`. /// Caller is responsible for throwing a JS exception if needed in case of error. -pub fn root_from_handlevalue<T>(v: HandleValue) -> Result<Root<T>, ()> +pub fn root_from_handlevalue<T>(v: HandleValue) -> Result<DomRoot<T>, ()> where T: DomObject + IDLInterface { if !v.get().is_object() { @@ -439,14 +439,14 @@ pub fn root_from_handlevalue<T>(v: HandleValue) -> Result<Root<T>, ()> root_from_object(v.get().to_object()) } -/// Get a `Root<T>` for a DOM object accessible from a `HandleObject`. -pub fn root_from_handleobject<T>(obj: HandleObject) -> Result<Root<T>, ()> +/// Get a `DomRoot<T>` for a DOM object accessible from a `HandleObject`. +pub fn root_from_handleobject<T>(obj: HandleObject) -> Result<DomRoot<T>, ()> where T: DomObject + IDLInterface { root_from_object(obj.get()) } -impl<T: DomObject> ToJSValConvertible for Root<T> { +impl<T: DomObject> ToJSValConvertible for DomRoot<T> { unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) { self.reflector().to_jsval(cx, rval); } diff --git a/components/script/dom/bindings/interface.rs b/components/script/dom/bindings/interface.rs index 5e04e80ad73..5604d33aa29 100644 --- a/components/script/dom/bindings/interface.rs +++ b/components/script/dom/bindings/interface.rs @@ -77,7 +77,7 @@ use dom::bindings::constant::{ConstantSpec, define_constants}; use dom::bindings::conversions::{DOM_OBJECT_SLOT, DerivedFrom, get_dom_class}; use dom::bindings::error::{Error, Fallible}; use dom::bindings::guard::Guard; -use dom::bindings::root::Root; +use dom::bindings::root::DomRoot; use dom::bindings::utils::{DOM_PROTOTYPE_SLOT, ProtoOrIfaceArray, get_proto_or_iface_array}; use dom::create::create_native_html_element; use dom::customelementregistry::ConstructionStackEntry; @@ -236,7 +236,7 @@ pub unsafe fn create_global_object( } // https://html.spec.whatwg.org/multipage/#htmlconstructor -pub unsafe fn html_constructor<T>(window: &Window, call_args: &CallArgs) -> Fallible<Root<T>> +pub unsafe fn html_constructor<T>(window: &Window, call_args: &CallArgs) -> Fallible<DomRoot<T>> where T: DerivedFrom<Element> { let document = window.Document(); @@ -289,7 +289,7 @@ pub unsafe fn html_constructor<T>(window: &Window, call_args: &CallArgs) -> Fall // Step 8.1 let name = QualName::new(None, ns!(html), definition.local_name.clone()); let element = if definition.is_autonomous() { - Root::upcast(HTMLElement::new(name.local, None, &*document)) + DomRoot::upcast(HTMLElement::new(name.local, None, &*document)) } else { create_native_html_element(name, None, &*document, ElementCreator::ScriptCreated) }; @@ -303,7 +303,7 @@ pub unsafe fn html_constructor<T>(window: &Window, call_args: &CallArgs) -> Fall element.set_custom_element_definition(definition.clone()); // Step 8.5 - Root::downcast(element).ok_or(Error::InvalidState) + DomRoot::downcast(element).ok_or(Error::InvalidState) }, // Step 9 Some(ConstructionStackEntry::Element(element)) => { @@ -315,7 +315,7 @@ pub unsafe fn html_constructor<T>(window: &Window, call_args: &CallArgs) -> Fall construction_stack.push(ConstructionStackEntry::AlreadyConstructedMarker); // Step 13 - Root::downcast(element).ok_or(Error::InvalidState) + DomRoot::downcast(element).ok_or(Error::InvalidState) }, // Step 10 Some(ConstructionStackEntry::AlreadyConstructedMarker) => Err(Error::InvalidState), diff --git a/components/script/dom/bindings/iterable.rs b/components/script/dom/bindings/iterable.rs index a7bf937b5b7..fbb9894210e 100644 --- a/components/script/dom/bindings/iterable.rs +++ b/components/script/dom/bindings/iterable.rs @@ -11,7 +11,7 @@ use dom::bindings::codegen::Bindings::IterableIteratorBinding::IterableKeyAndVal use dom::bindings::codegen::Bindings::IterableIteratorBinding::IterableKeyOrValueResult; use dom::bindings::error::Fallible; use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; -use dom::bindings::root::{Dom, Root}; +use dom::bindings::root::{Dom, DomRoot}; use dom::bindings::trace::JSTraceable; use dom::globalscope::GlobalScope; use dom_struct::dom_struct; @@ -61,7 +61,7 @@ impl<T: DomObject + JSTraceable + Iterable> IterableIterator<T> { pub fn new(iterable: &T, type_: IteratorType, wrap: unsafe fn(*mut JSContext, &GlobalScope, Box<IterableIterator<T>>) - -> Root<Self>) -> Root<Self> { + -> DomRoot<Self>) -> DomRoot<Self> { let iterator = box IterableIterator { reflector: Reflector::new(), type_: type_, diff --git a/components/script/dom/bindings/refcounted.rs b/components/script/dom/bindings/refcounted.rs index d2c1a484887..02f6784fb2f 100644 --- a/components/script/dom/bindings/refcounted.rs +++ b/components/script/dom/bindings/refcounted.rs @@ -26,7 +26,7 @@ use core::nonzero::NonZero; use dom::bindings::conversions::ToJSValConvertible; use dom::bindings::error::Error; use dom::bindings::reflector::{DomObject, Reflector}; -use dom::bindings::root::Root; +use dom::bindings::root::DomRoot; use dom::bindings::trace::trace_reflector; use dom::promise::Promise; use js::jsapi::JSTracer; @@ -178,14 +178,14 @@ impl<T: DomObject> Trusted<T> { /// Obtain a usable DOM pointer from a pinned `Trusted<T>` value. Fails if used on /// a different thread than the original value from which this `Trusted<T>` was /// obtained. - pub fn root(&self) -> Root<T> { + pub fn root(&self) -> DomRoot<T> { assert!(LIVE_REFERENCES.with(|ref r| { let r = r.borrow(); let live_references = r.as_ref().unwrap(); self.owner_thread == (&*live_references) as *const _ as *const libc::c_void })); unsafe { - Root::new(NonZero::new_unchecked(self.refcount.0 as *const T)) + DomRoot::new(NonZero::new_unchecked(self.refcount.0 as *const T)) } } } diff --git a/components/script/dom/bindings/reflector.rs b/components/script/dom/bindings/reflector.rs index 356086ac146..de6c8ab7c81 100644 --- a/components/script/dom/bindings/reflector.rs +++ b/components/script/dom/bindings/reflector.rs @@ -5,7 +5,7 @@ //! The `Reflector` struct. use dom::bindings::conversions::DerivedFrom; -use dom::bindings::root::Root; +use dom::bindings::root::DomRoot; use dom::globalscope::GlobalScope; use js::jsapi::{HandleObject, JSContext, JSObject, Heap}; use std::default::Default; @@ -15,8 +15,8 @@ use std::default::Default; pub fn reflect_dom_object<T, U>( obj: Box<T>, global: &U, - wrap_fn: unsafe fn(*mut JSContext, &GlobalScope, Box<T>) -> Root<T>) - -> Root<T> + wrap_fn: unsafe fn(*mut JSContext, &GlobalScope, Box<T>) -> DomRoot<T>) + -> DomRoot<T> where T: DomObject, U: DerivedFrom<GlobalScope> { let global_scope = global.upcast(); @@ -77,7 +77,7 @@ pub trait DomObject { fn reflector(&self) -> &Reflector; /// Returns the global scope of the realm that the DomObject was created in. - fn global(&self) -> Root<GlobalScope> where Self: Sized { + fn global(&self) -> DomRoot<GlobalScope> where Self: Sized { GlobalScope::from_reflector(self) } } 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<T>`: a stack-based reference to a rooted DOM object. +//! - `DomRoot<T>`: a stack-based reference to a rooted DOM object. //! - `Dom<T>`: a reference to a DOM object that can automatically be traced by //! the GC when encountered as a field of a Rust structure. //! //! `Dom<T>` does not allow access to their inner value without explicitly -//! creating a stack-based root via the `root` method. This returns a `Root<T>`, +//! creating a stack-based root via the `root` method. This returns a `DomRoot<T>`, //! 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<T>`. +//! originating `DomRoot<T>`. //! use core::nonzero::NonZero; @@ -259,10 +259,10 @@ impl<T: DomObject> MutDom<T> { } /// Get the value in this `MutDom`. - pub fn get(&self) -> Root<T> { + pub fn get(&self) -> DomRoot<T> { 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<T: DomObject> MutNullableDom<T> { /// 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<F>(&self, cb: F) -> Root<T> - where F: FnOnce() -> Root<T> + pub fn or_init<F>(&self, cb: F) -> DomRoot<T> + where F: FnOnce() -> DomRoot<T> { debug_assert!(thread_state::get().is_script()); match self.get() { @@ -337,10 +337,10 @@ impl<T: DomObject> MutNullableDom<T> { /// Get a rooted value out of this object #[allow(unrooted_must_root)] - pub fn get(&self) -> Option<Root<T>> { + pub fn get(&self) -> Option<DomRoot<T>> { 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<T: DomObject> MutNullableDom<T> { } /// Gets the current value out of this object and sets it to `None`. - pub fn take(&self) -> Option<Root<T>> { + pub fn take(&self) -> Option<DomRoot<T>> { let value = self.get(); self.set(None); value @@ -409,7 +409,7 @@ impl<T: DomObject> DomOnceCell<T> { /// initialized with the result of `cb` first. #[allow(unrooted_must_root)] pub fn init_once<F>(&self, cb: F) -> &T - where F: FnOnce() -> Root<T> + where F: FnOnce() -> DomRoot<T> { 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<T: DomObject> { +pub struct DomRoot<T: DomObject> { /// 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<T: Castable> Root<T> { +impl<T: Castable> DomRoot<T> { /// Cast a DOM object root upwards to one of the interfaces it derives from. - pub fn upcast<U>(root: Root<T>) -> Root<U> + pub fn upcast<U>(root: DomRoot<T>) -> DomRoot<U> where U: Castable, T: DerivedFrom<U> { @@ -576,7 +576,7 @@ impl<T: Castable> Root<T> { } /// Cast a DOM object root downwards to one of the interfaces it might implement. - pub fn downcast<U>(root: Root<T>) -> Option<Root<U>> + pub fn downcast<U>(root: DomRoot<T>) -> Option<DomRoot<U>> where U: DerivedFrom<T> { if root.is::<U>() { @@ -587,16 +587,16 @@ impl<T: Castable> Root<T> { } } -impl<T: DomObject> Root<T> { +impl<T: DomObject> DomRoot<T> { /// 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<T> { + pub fn new(unrooted: NonZero<*const T>) -> DomRoot<T> { 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<T: DomObject> Root<T> { } /// Generate a new root from a reference - pub fn from_ref(unrooted: &T) -> Root<T> { - Root::new(unsafe { NonZero::new_unchecked(unrooted) }) + pub fn from_ref(unrooted: &T) -> DomRoot<T> { + DomRoot::new(unsafe { NonZero::new_unchecked(unrooted) }) } } -impl<'root, T: DomObject + 'root> RootedReference<'root> for Root<T> { +impl<'root, T: DomObject + 'root> RootedReference<'root> for DomRoot<T> { type Ref = &'root T; fn r(&'root self) -> &'root T { self } } -impl<T: DomObject> Deref for Root<T> { +impl<T: DomObject> Deref for DomRoot<T> { type Target = T; fn deref(&self) -> &T { debug_assert!(thread_state::get().is_script()); @@ -624,25 +624,25 @@ impl<T: DomObject> Deref for Root<T> { } } -impl<T: DomObject + HeapSizeOf> HeapSizeOf for Root<T> { +impl<T: DomObject + HeapSizeOf> HeapSizeOf for DomRoot<T> { fn heap_size_of_children(&self) -> usize { (**self).heap_size_of_children() } } -impl<T: DomObject> PartialEq for Root<T> { +impl<T: DomObject> PartialEq for DomRoot<T> { fn eq(&self, other: &Self) -> bool { self.ptr == other.ptr } } -impl<T: DomObject> Clone for Root<T> { - fn clone(&self) -> Root<T> { - Root::from_ref(&*self) +impl<T: DomObject> Clone for DomRoot<T> { + fn clone(&self) -> DomRoot<T> { + DomRoot::from_ref(&*self) } } -impl<T: DomObject> Drop for Root<T> { +impl<T: DomObject> Drop for DomRoot<T> { fn drop(&mut self) { unsafe { (*self.root_list).unroot(self.reflector()); @@ -650,7 +650,7 @@ impl<T: DomObject> Drop for Root<T> { } } -unsafe impl<T: DomObject> JSTraceable for Root<T> { +unsafe impl<T: DomObject> JSTraceable for DomRoot<T> { unsafe fn trace(&self, _: *mut JSTracer) { // Already traced. } diff --git a/components/script/dom/bindings/settings_stack.rs b/components/script/dom/bindings/settings_stack.rs index 0d747cca205..fb708d1b235 100644 --- a/components/script/dom/bindings/settings_stack.rs +++ b/components/script/dom/bindings/settings_stack.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use dom::bindings::root::{Dom, Root}; +use dom::bindings::root::{Dom, DomRoot}; use dom::bindings::trace::JSTraceable; use dom::globalscope::GlobalScope; use js::jsapi::GetScriptedCallerGlobal; @@ -37,7 +37,7 @@ pub unsafe fn trace(tracer: *mut JSTracer) { /// RAII struct that pushes and pops entries from the script settings stack. pub struct AutoEntryScript { - global: Root<GlobalScope>, + global: DomRoot<GlobalScope>, } impl AutoEntryScript { @@ -51,7 +51,7 @@ impl AutoEntryScript { kind: StackEntryKind::Entry, }); AutoEntryScript { - global: Root::from_ref(global), + global: DomRoot::from_ref(global), } }) } @@ -80,13 +80,13 @@ impl Drop for AutoEntryScript { /// Returns the ["entry"] global object. /// /// ["entry"]: https://html.spec.whatwg.org/multipage/#entry -pub fn entry_global() -> Root<GlobalScope> { +pub fn entry_global() -> DomRoot<GlobalScope> { STACK.with(|stack| { stack.borrow() .iter() .rev() .find(|entry| entry.kind == StackEntryKind::Entry) - .map(|entry| Root::from_ref(&*entry.global)) + .map(|entry| DomRoot::from_ref(&*entry.global)) }).unwrap() } @@ -145,7 +145,7 @@ impl Drop for AutoIncumbentScript { /// Returns the ["incumbent"] global object. /// /// ["incumbent"]: https://html.spec.whatwg.org/multipage/#incumbent -pub fn incumbent_global() -> Option<Root<GlobalScope>> { +pub fn incumbent_global() -> Option<DomRoot<GlobalScope>> { // https://html.spec.whatwg.org/multipage/#incumbent-settings-object // Step 1, 3: See what the JS engine has to say. If we've got a scripted @@ -165,6 +165,6 @@ pub fn incumbent_global() -> Option<Root<GlobalScope>> { STACK.with(|stack| { stack.borrow() .last() - .map(|entry| Root::from_ref(&*entry.global)) + .map(|entry| DomRoot::from_ref(&*entry.global)) }) } diff --git a/components/script/dom/bindings/structuredclone.rs b/components/script/dom/bindings/structuredclone.rs index e23d478e5a8..bdc5348782f 100644 --- a/components/script/dom/bindings/structuredclone.rs +++ b/components/script/dom/bindings/structuredclone.rs @@ -8,7 +8,7 @@ use dom::bindings::conversions::root_from_handleobject; use dom::bindings::error::{Error, Fallible}; use dom::bindings::reflector::DomObject; -use dom::bindings::root::Root; +use dom::bindings::root::DomRoot; use dom::blob::{Blob, BlobImpl}; use dom::globalscope::GlobalScope; use js::jsapi::{Handle, HandleObject, HandleValue, MutableHandleValue, JSAutoCompartment, JSContext}; @@ -110,7 +110,7 @@ unsafe fn read_blob(cx: *mut JSContext, return blob.reflector().get_jsobject().get() } -unsafe fn write_blob(blob: Root<Blob>, +unsafe fn write_blob(blob: DomRoot<Blob>, w: *mut JSStructuredCloneWriter) -> Result<(), ()> { let structured_writer = StructuredCloneWriter { w: w }; diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs index 56b48b5750c..c367df5ee56 100644 --- a/components/script/dom/bindings/trace.rs +++ b/components/script/dom/bindings/trace.rs @@ -42,7 +42,7 @@ use dom::bindings::cell::DomRefCell; use dom::bindings::error::Error; use dom::bindings::refcounted::{Trusted, TrustedPromise}; use dom::bindings::reflector::{DomObject, Reflector}; -use dom::bindings::root::{Dom, Root}; +use dom::bindings::root::{Dom, DomRoot}; use dom::bindings::str::{DOMString, USVString}; use dom::bindings::utils::WindowProxyHandler; use dom::document::PendingRestyle; @@ -710,7 +710,7 @@ impl RootedTraceableSet { /// Roots any JSTraceable thing /// -/// If you have a valid DomObject, use Root. +/// If you have a valid DomObject, use DomRoot. /// If you have GC things like *mut JSObject or JSVal, use rooted!. /// If you have an arbitrary number of DomObjects to root, use rooted_vec!. /// If you know what you're doing, use this. @@ -720,7 +720,7 @@ pub struct RootedTraceable<'a, T: 'static + JSTraceable> { } impl<'a, T: JSTraceable + 'static> RootedTraceable<'a, T> { - /// Root a JSTraceable thing for the life of this RootedTraceable + /// DomRoot a JSTraceable thing for the life of this RootedTraceable pub fn new(traceable: &'a T) -> RootedTraceable<'a, T> { unsafe { RootedTraceableSet::add(traceable); @@ -741,7 +741,7 @@ impl<'a, T: JSTraceable + 'static> Drop for RootedTraceable<'a, T> { /// Roots any JSTraceable thing /// -/// If you have a valid DomObject, use Root. +/// If you have a valid DomObject, use DomRoot. /// If you have GC things like *mut JSObject or JSVal, use rooted!. /// If you have an arbitrary number of DomObjects to root, use rooted_vec!. /// If you know what you're doing, use this. @@ -757,7 +757,7 @@ unsafe impl<T: JSTraceable + 'static> JSTraceable for RootedTraceableBox<T> { } impl<T: JSTraceable + 'static> RootedTraceableBox<T> { - /// Root a JSTraceable thing for the life of this RootedTraceable + /// DomRoot a JSTraceable thing for the life of this RootedTraceable pub fn new(traceable: T) -> RootedTraceableBox<T> { let traceable = Box::into_raw(box traceable); unsafe { @@ -804,7 +804,7 @@ impl<T: JSTraceable + 'static> Drop for RootedTraceableBox<T> { /// A vector of items to be rooted with `RootedVec`. /// Guaranteed to be empty when not rooted. /// Usage: `rooted_vec!(let mut v);` or if you have an -/// iterator of `Root`s, `rooted_vec!(let v <- iterator);`. +/// iterator of `DomRoot`s, `rooted_vec!(let v <- iterator);`. #[allow(unrooted_must_root)] #[derive(JSTraceable)] #[allow_unrooted_interior] @@ -844,7 +844,7 @@ impl<'a, T: 'static + JSTraceable + DomObject> RootedVec<'a, Dom<T>> { /// Create a vector of items of type Dom<T> that is rooted for /// the lifetime of this struct pub fn from_iter<I>(root: &'a mut RootableVec<Dom<T>>, iter: I) -> Self - where I: Iterator<Item = Root<T>> + where I: Iterator<Item = DomRoot<T>> { unsafe { RootedTraceableSet::add(root); diff --git a/components/script/dom/bindings/weakref.rs b/components/script/dom/bindings/weakref.rs index 61a50a240b1..6ece47cea3b 100644 --- a/components/script/dom/bindings/weakref.rs +++ b/components/script/dom/bindings/weakref.rs @@ -13,7 +13,7 @@ use core::nonzero::NonZero; use dom::bindings::reflector::DomObject; -use dom::bindings::root::Root; +use dom::bindings::root::DomRoot; use dom::bindings::trace::JSTraceable; use heapsize::HeapSizeOf; use js::jsapi::{JSTracer, JS_GetReservedSlot, JS_SetReservedSlot}; @@ -84,9 +84,9 @@ impl<T: WeakReferenceable> WeakRef<T> { value.downgrade() } - /// Root a weak reference. Returns `None` if the object was already collected. - pub fn root(&self) -> Option<Root<T>> { - unsafe { &*self.ptr.get() }.value.get().map(Root::new) + /// DomRoot a weak reference. Returns `None` if the object was already collected. + pub fn root(&self) -> Option<DomRoot<T>> { + unsafe { &*self.ptr.get() }.value.get().map(DomRoot::new) } /// Return whether the weakly-referenced object is still alive. @@ -179,9 +179,9 @@ impl<T: WeakReferenceable> MutableWeakRef<T> { } } - /// Root a mutable weak reference. Returns `None` if the object + /// DomRoot a mutable weak reference. Returns `None` if the object /// was already collected. - pub fn root(&self) -> Option<Root<T>> { + pub fn root(&self) -> Option<DomRoot<T>> { unsafe { &*self.cell.get() }.as_ref().and_then(WeakRef::root) } } |