Module script::dom::bindings::root

source ·
Expand description

Smart pointers for the JS-managed DOM objects.

The DOM is made up of DOM objects 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:

  • Root<T>: a stack-based rooted value.
  • 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 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 DomRoot<T>.

Structs§

  • A traced reference to a DOM object
  • A holder that allows to lazily initialize the value only once Dom<T>, using OnceCell Essentially a OnceCell<Dom<T>>.
  • An unrooted reference to a DOM object for use in layout. Layout*Helpers traits must be implemented on this.
  • A traced reference to a DOM object that may not be reflected yet.
  • A holder that provides interior mutability for GC-managed values such as Dom<T>. Essentially a Cell<Dom<T>>, but safer.
  • A holder that provides interior mutability for GC-managed values such as Dom<T>, with nullability represented by an enclosing Option wrapper. Essentially a Cell<Option<Dom<T>>>, but safer.
  • A rooted value.
  • A rooting mechanism for reflectors on the stack. LIFO is not required.

Constants§

Traits§

  • Get a slice of references to DOM objects.
  • StableTraceObject represents values that can be rooted through a stable address that will not change for their whole lifetime. It is an unsafe trait that requires implementors to ensure certain safety guarantees.

Functions§

Type Aliases§

  • A rooted reference to a DOM object.