From 3bb550df0f7e63bee0bcbed894c216288a909bea Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Fri, 13 Jun 2014 15:01:54 -0400 Subject: [PATCH] servo: Merge #2653 - Make rustdoc handle the documentation in js.rs (from Ms2ger:docs); r=Ms2ger,metajack Source-Repo: https://github.com/servo/servo Source-Revision: 239fa77dd52a364634cdee0f4c1e762d602cecb7 --- .../src/components/script/dom/bindings/js.rs | 111 +++++++++--------- 1 file changed, 57 insertions(+), 54 deletions(-) diff --git a/servo/src/components/script/dom/bindings/js.rs b/servo/src/components/script/dom/bindings/js.rs index 81dda57e9ecf..2f32e3afed35 100644 --- a/servo/src/components/script/dom/bindings/js.rs +++ b/servo/src/components/script/dom/bindings/js.rs @@ -2,42 +2,45 @@ * 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/. */ -/// The DOM is made up of Rust types whose lifetime is entirely controlled by the whims of -/// the SpiderMonkey garbage collector. The types in this module are designed to ensure -/// that any interactions with said Rust types only occur on values that will remain alive -/// the entire time. -/// -/// 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 -/// encountered as a field of a Rust structure. -/// - 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 -/// somewhere that is reachable by the GC. -/// - 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 -/// 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 -/// 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 -/// 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 +//! The DOM is made up of Rust types whose lifetime is entirely controlled by the whims of +//! the SpiderMonkey garbage collector. The types in this module are designed to ensure +//! that any interactions with said Rust types only occur on values that will remain alive +//! the entire time. +//! +//! 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 +//! encountered as a field of a Rust structure. +//! - `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 +//! somewhere that is reachable by the GC. +//! - 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 +//! 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 +//! 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` 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 use dom::bindings::utils::{Reflector, Reflectable}; use dom::node::Node; @@ -52,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 @@ -67,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, @@ -75,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(JS::from_rooted(root)) } @@ -119,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 { @@ -201,7 +204,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>; } @@ -212,7 +215,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>>; } @@ -223,7 +226,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 { @@ -248,8 +251,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); } @@ -261,7 +264,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>; } @@ -283,7 +286,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>; } @@ -294,7 +297,7 @@ impl OptionalRootedRootable for Option> { } } -/// Root a rootable Option