From 8a08fff0b4c9952bb8e407301408cac179c1a974 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 19 Jan 2015 22:56:45 +0100 Subject: [PATCH 1/2] Remove OptionalSettable. It was obsoleted by MutNullableJS. --- components/script/dom/bindings/js.rs | 13 ------------- components/script/dom/document.rs | 2 +- components/script/dom/mouseevent.rs | 2 +- components/script/dom/node.rs | 2 +- components/script/dom/uievent.rs | 2 +- 5 files changed, 4 insertions(+), 17 deletions(-) diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs index ac8da0f8ba6..e3d7247da5a 100644 --- a/components/script/dom/bindings/js.rs +++ b/components/script/dom/bindings/js.rs @@ -42,7 +42,6 @@ //! - `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::trace::JSTraceable; @@ -367,18 +366,6 @@ impl Assignable for Temporary { } } -/// 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); -} - -impl, U: Reflectable> OptionalSettable for Cell>> { - fn assign(&self, val: Option) { - self.set(val.map(|val| unsafe { val.get_js() })); - } -} - /// Root a rootable `Option` type (used for `Option>`) pub trait OptionalRootable { diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 22334b3b2a1..f01dc20a7e1 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -23,7 +23,7 @@ use dom::bindings::error::{ErrorResult, Fallible}; use dom::bindings::error::Error::{NotSupported, InvalidCharacter}; use dom::bindings::error::Error::{HierarchyRequest, NamespaceError}; use dom::bindings::global::GlobalRef; -use dom::bindings::js::{MutNullableJS, JS, JSRef, Temporary, OptionalSettable, TemporaryPushable}; +use dom::bindings::js::{MutNullableJS, JS, JSRef, Temporary, TemporaryPushable}; use dom::bindings::js::{OptionalRootable, RootedReference}; use dom::bindings::utils::reflect_dom_object; use dom::bindings::utils::xml_name_type; diff --git a/components/script/dom/mouseevent.rs b/components/script/dom/mouseevent.rs index 76c785ee4eb..11a45bbc208 100644 --- a/components/script/dom/mouseevent.rs +++ b/components/script/dom/mouseevent.rs @@ -8,7 +8,7 @@ use dom::bindings::codegen::Bindings::UIEventBinding::UIEventMethods; use dom::bindings::codegen::InheritTypes::{EventCast, UIEventCast, MouseEventDerived}; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; -use dom::bindings::js::{MutNullableJS, JSRef, RootedReference, Temporary, OptionalSettable}; +use dom::bindings::js::{MutNullableJS, JSRef, RootedReference, Temporary}; use dom::bindings::utils::reflect_dom_object; use dom::event::{Event, EventTypeId}; use dom::eventtarget::EventTarget; diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index fb336efd85b..83c14208cbb 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -24,7 +24,7 @@ use dom::bindings::error::Fallible; use dom::bindings::error::Error::{NotFound, HierarchyRequest, Syntax}; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, JSRef, RootedReference, Temporary, Root}; -use dom::bindings::js::{OptionalSettable, TemporaryPushable, OptionalRootedRootable}; +use dom::bindings::js::{TemporaryPushable, OptionalRootedRootable}; use dom::bindings::js::{ResultRootable, OptionalRootable, MutNullableJS}; use dom::bindings::trace::JSTraceable; use dom::bindings::utils::{Reflectable, reflect_dom_object}; diff --git a/components/script/dom/uievent.rs b/components/script/dom/uievent.rs index dc6dbb8c756..33c539dd150 100644 --- a/components/script/dom/uievent.rs +++ b/components/script/dom/uievent.rs @@ -8,7 +8,7 @@ use dom::bindings::codegen::Bindings::UIEventBinding::UIEventMethods; use dom::bindings::codegen::InheritTypes::{EventCast, UIEventDerived}; use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; -use dom::bindings::js::{MutNullableJS, JSRef, RootedReference, Temporary, OptionalSettable}; +use dom::bindings::js::{MutNullableJS, JSRef, RootedReference, Temporary}; use dom::bindings::utils::reflect_dom_object; use dom::event::{Event, EventTypeId}; From e239bd964421045a9c339caa89ee1b9216fc1889 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 19 Jan 2015 23:09:00 +0100 Subject: [PATCH 2/2] Document js.rs. --- components/script/dom/bindings/js.rs | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs index e3d7247da5a..40230e9198e 100644 --- a/components/script/dom/bindings/js.rs +++ b/components/script/dom/bindings/js.rs @@ -44,6 +44,8 @@ //! - `TemporaryPushable`: allows mutating vectors of `JS` with new elements of `JSRef`/`Temporary` //! - `RootedReference`: makes obtaining an `Option>` from an `Option>` easy +#![deny(missing_docs)] + use dom::bindings::trace::JSTraceable; use dom::bindings::utils::{Reflector, Reflectable}; use dom::node::Node; @@ -112,6 +114,8 @@ impl Temporary { self.inner.clone() } + /// Returns `self` as a `Temporary` of another type. For use by + /// `InheritTypes` only. //XXXjdm It would be lovely if this could be private. pub unsafe fn transmute(self) -> Temporary { mem::transmute(self) @@ -173,6 +177,7 @@ impl JS { } impl, U: Reflectable> JS { + /// Create a `JS` from any JS-managed pointer. pub fn from_rooted(root: T) -> JS { unsafe { root.get_js() @@ -190,6 +195,10 @@ impl Reflectable for JS { } } +/// A trait to be implemented for JS-managed types that can be stored in +/// mutable member fields. +/// +/// Do not implement this trait yourself. pub trait HeapGCValue: JSTraceable { } @@ -209,16 +218,20 @@ pub struct MutHeap { } impl MutHeap { + /// Create a new `MutHeap`. pub fn new(initial: T) -> MutHeap { MutHeap { val: Cell::new(initial), } } + /// Set this `MutHeap` to the given value, calling write barriers as + /// appropriate. pub fn set(&self, val: T) { self.val.set(val) } + /// Set the value in this `MutHeap`, calling read barriers as appropriate. pub fn get(&self) -> T { self.val.get() } @@ -234,6 +247,7 @@ pub struct MutNullableJS { } impl, U: Reflectable> MutNullableJS { + /// Create a new `MutNullableJS` pub fn new(initial: Option) -> MutNullableJS { MutNullableJS { ptr: Cell::new(initial.map(|initial| { @@ -279,6 +293,8 @@ impl MutNullableJS { self.ptr.get() } + /// 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: || -> Temporary) -> Temporary { match self.get() { Some(inner) => inner, @@ -308,11 +324,13 @@ impl JS { } impl JS { + /// Return `self` as a `JS` of another type. //XXXjdm It would be lovely if this could be private. pub unsafe fn transmute(self) -> JS { mem::transmute(self) } + /// Return `self` as a `JS` of another type. pub unsafe fn transmute_copy(&self) -> JS { mem::transmute_copy(self) } @@ -321,6 +339,8 @@ impl JS { /// Get an `Option>` out of an `Option>` pub trait RootedReference { + /// Obtain a safe optional reference to the wrapped JS owned-value that + /// cannot outlive the lifetime of this root. fn r<'a>(&'a self) -> Option>; } @@ -332,6 +352,8 @@ impl RootedReference for Option> { /// Get an `Option>>` out of an `Option>>` pub trait OptionalRootedReference { + /// Obtain a safe optional optional reference to the wrapped JS owned-value + /// that cannot outlive the lifetime of this root. fn r<'a>(&'a self) -> Option>>; } @@ -345,6 +367,7 @@ impl OptionalRootedReference for Option>> { /// which in general is an unsafe operation since they can outlive the rooted lifetime of the /// original value. pub trait Assignable { + /// Extract an unrooted `JS`. unsafe fn get_js(&self) -> JS; } @@ -369,6 +392,7 @@ impl Assignable for Temporary { /// Root a rootable `Option` type (used for `Option>`) pub trait OptionalRootable { + /// Root the inner value, if it exists. fn root(self) -> Option>; } @@ -380,6 +404,7 @@ impl OptionalRootable for Option> { /// Return an unrooted type for storing in optional DOM fields pub trait OptionalUnrootable { + /// Returns a `JS` for the inner value, if it exists. fn unrooted(&self) -> Option>; } @@ -391,6 +416,7 @@ impl<'a, T: Reflectable> OptionalUnrootable for Option> { /// Root a rootable `Option` type (used for `Option>`) pub trait OptionalRootedRootable { + /// Root the inner value, if it exists. fn root(&self) -> Option>; } @@ -402,6 +428,7 @@ impl OptionalRootedRootable for Option> { /// Root a rootable `Option