diff --git a/src/components/script/dom/bindings/js.rs b/src/components/script/dom/bindings/js.rs index 19f2d22e77a..ab67d314772 100644 --- a/src/components/script/dom/bindings/js.rs +++ b/src/components/script/dom/bindings/js.rs @@ -9,38 +9,38 @@ //! //! Here is a brief overview of the important types: //! -//! - JSRef: a freely-copyable reference to a rooted value. -//! - JS: a pointer to JS-owned memory that can automatically be traced by the GC when +//! - `JSRef`: a freely-copyable reference to a rooted value. +//! - `JS`: a pointer to JS-owned memory that can automatically be traced by the GC when //! encountered as a field of a Rust structure. -//! - Temporary: a value that will remain rooted for the duration of its lifetime. +//! - `Temporary`: a value that will remain rooted for the duration of its lifetime. //! //! The rule of thumb is as follows: //! -//! - All methods return Temporary, to ensure the value remains alive until it is stored +//! - All methods return `Temporary`, to ensure the value remains alive until it is stored //! somewhere that is reachable by the GC. -//! - All functions take &JSRef arguments, to ensure that they will remain uncollected for +//! - All functions take `&JSRef` arguments, to ensure that they will remain uncollected for //! the duration of their usage. -//! - All types contain JS fields and derive the Encodable trait, to ensure that they are +//! - All types contain `JS` fields and derive the `Encodable` trait, to ensure that they are //! transitively marked as reachable by the GC if the enclosing value is reachable. -//! - All methods for type T are implemented for JSRef, to ensure that the self value +//! - All methods for type `T` are implemented for `JSRef`, to ensure that the self value //! will not be collected for the duration of the method call. //! -//! Both Temporary and JS do not allow access to their inner value without explicitly -//! creating a stack-based root via the `root` method. This returns a Root, which causes -//! the JS-owned value to be uncollectable for the duration of the Root type's lifetime. -//! A JSRef can be obtained from a Root either by dereferencing the Root (`*rooted`) -//! or explicitly calling the `root_ref` method. These JSRef values are not allowed to -//! outlive their originating Root, to ensure that all interactions with the enclosed value +//! Both `Temporary` and `JS` do not allow access to their inner value without explicitly +//! creating a stack-based root via the `root` method. This returns a `Root`, which causes +//! the JS-owned value to be uncollectable for the duration of the `Root` object's lifetime. +//! A `JSRef` can be obtained from a `Root` either by dereferencing the `Root` (`*rooted`) +//! or explicitly calling the `root_ref` method. These `JSRef` values are not allowed to +//! outlive their originating `Root`, to ensure that all interactions with the enclosed value //! only occur when said value is uncollectable, and will cause static lifetime errors if //! misused. //! //! Other miscellaneous helper traits: //! -//! - OptionalRootable and OptionalRootedRootable: make rooting Option values easy via a `root` method -//! - ResultRootable: make rooting successful Result values easy -//! - TemporaryPushable: allows mutating vectors of JS with new elements of JSRef/Temporary -//! - OptionalSettable: allows assigning Option values of JSRef/Temporary to fields of Option> -//! - RootedReference: makes obtaining an Option> from an Option> easy +//! - `OptionalRootable` and `OptionalRootedRootable`: make rooting `Option` values easy via a `root` method +//! - `ResultRootable`: make rooting successful `Result` values easy +//! - `TemporaryPushable`: allows mutating vectors of `JS` with new elements of `JSRef`/`Temporary` +//! - `OptionalSettable`: allows assigning `Option` values of `JSRef`/`Temporary` to fields of `Option>` +//! - `RootedReference`: makes obtaining an `Option>` from an `Option>` easy use dom::bindings::utils::{Reflector, Reflectable}; use dom::node::Node; @@ -55,8 +55,8 @@ use std::mem; /// A type that represents a JS-owned value that is rooted for the lifetime of this value. /// Importantly, it requires explicit rooting in order to interact with the inner value. -/// Can be assigned into JS-owned member fields (ie. JS types) safely via the -/// `JS::assign` method or `OptionalSettable::assign` (for Option> fields). +/// Can be assigned into JS-owned member fields (i.e. `JS` types) safely via the +/// `JS::assign` method or `OptionalSettable::assign` (for `Option>` fields). pub struct Temporary { inner: JS, /// On-stack JS pointer to assuage conservative stack scanner @@ -70,7 +70,7 @@ impl Eq for Temporary { } impl Temporary { - /// Create a new Temporary value from a JS-owned value. + /// Create a new `Temporary` value from a JS-owned value. pub fn new(inner: JS) -> Temporary { Temporary { inner: inner, @@ -78,7 +78,7 @@ impl Temporary { } } - /// Create a new Temporary value from a rooted value. + /// Create a new `Temporary` value from a rooted value. pub fn from_rooted<'a>(root: &JSRef<'a, T>) -> Temporary { Temporary::new(root.unrooted()) } @@ -122,7 +122,7 @@ impl Clone for JS { } impl JS { - /// Create a new JS-owned value wrapped from an address known to be a Node pointer. + /// Create a new JS-owned value wrapped from an address known to be a `Node` pointer. pub unsafe fn from_trusted_node_address(inner: TrustedNodeAddress) -> JS { let TrustedNodeAddress(addr) = inner; JS { @@ -210,7 +210,7 @@ impl JS { } -/// Get an Option> out of an Option> +/// Get an `Option>` out of an `Option>` pub trait RootedReference { fn root_ref<'a>(&'a self) -> Option>; } @@ -221,7 +221,7 @@ impl<'a, 'b, T: Reflectable> RootedReference for Option> { } } -/// Get an Option>> out of an Option>> +/// Get an `Option>>` out of an `Option>>` pub trait OptionalRootedReference { fn root_ref<'a>(&'a self) -> Option>>; } @@ -232,7 +232,7 @@ impl<'a, 'b, T: Reflectable> OptionalRootedReference for Option value from a variety of rooting-related containers, +/// Trait that allows extracting a `JS` value from a variety of rooting-related containers, /// which in general is an unsafe operation since they can outlive the rooted lifetime of the /// original value. /*definitely not public*/ trait Assignable { @@ -257,8 +257,8 @@ impl Assignable for Temporary { } } -/// Assign an optional rootable value (either of JS or Temporary) to an optional -/// field of a DOM type (ie. Option>) +/// Assign an optional rootable value (either of `JS` or `Temporary`) to an optional +/// field of a DOM type (ie. `Option>`) pub trait OptionalSettable { fn assign(&self, val: Option); } @@ -270,7 +270,7 @@ impl, U: Reflectable> OptionalSettable for Cell } -/// Root a rootable Option type (used for Option>) +/// Root a rootable `Option` type (used for `Option>`) pub trait OptionalRootable { fn root<'a, 'b>(self) -> Option>; } @@ -292,7 +292,7 @@ impl<'a, T: Reflectable> OptionalUnrootable for Option> { } } -/// Root a rootable Option type (used for Option>) +/// Root a rootable `Option` type (used for `Option>`) pub trait OptionalRootedRootable { fn root<'a, 'b>(&self) -> Option>; } @@ -303,7 +303,7 @@ impl OptionalRootedRootable for Option> { } } -/// Root a rootable Option