Expand description
Utilities for tracing JS-managed values.
The lifetime of DOM objects is managed by the SpiderMonkey Garbage
Collector. A rooted DOM object implementing the interface Foo
is traced
as follows:
- The GC calls
_trace
defined inFooBinding
during the marking phase. (This happens throughJSClass.trace
for non-proxy bindings, and throughProxyTraps.trace
otherwise.) _trace
callsFoo::trace()
(an implementation ofJSTraceable
). This is typically derived via a#[dom_struct]
(implies#[derive(JSTraceable)]
) annotation. Non-JS-managed types have an empty inlinetrace()
method, achieved viaunsafe_no_jsmanaged_fields!
or similar.- For all fields,
Foo::trace()
callstrace()
on the field. For example, for fields of typeDom<T>
,Dom<T>::trace()
callstrace_reflector()
. trace_reflector()
callsDom::TraceEdge()
with a pointer to theJSObject
for the reflector. This notifies the GC, which will add the object to the graph, and will trace that object as well.- When the GC finishes tracing, it
finalizes
any reflectors that were not reachable.
The unsafe_no_jsmanaged_fields!()
macro adds an empty implementation of
JSTraceable
to a datatype.
Structsยง
- Hash
MapTraced ๐Values HashMap wrapper, that has non-jsmanaged keys - NoTrace ๐Wrapper type for nop traceble
- Rootable
Vec ๐A vector of items to be rooted withRootedVec
. Guaranteed to be empty when not rooted. - Rooted
Traceable ๐Box Roots any JSTraceable thing - Rooted
Vec ๐A vector of items rooted for the lifetime โa.
Traitsยง
- Custom
Traceable ๐A trait to allow tracing only DOM sub-objects. - JSTraceable ๐A trait to allow tracing (only) DOM objects. Types that can be traced.
Functionsยง
- trace_
jsval ๐Trace aJSVal
. - trace_
object ๐Trace aJSObject
. - trace_
reflector ๐Trace theJSObject
held byreflector
. - trace_
script ๐Trace aJSScript
. - trace_
string ๐Trace aJSString
.