Struct neon::handle::Root [−][src]
pub struct Root<T> { /* fields omitted */ }
Expand description
A thread-safe handle that holds a reference to a JavaScript object and prevents it from being garbage collected.
A Root<T>
may be sent across threads, but the referenced object may
only be accessed on the JavaScript thread that created it.
Implementations
Create a reference to a JavaScript object. The object will not be
garbage collected until the Root
is dropped. A Root<T>
may only
be dropped on the JavaScript thread that created it.
The caller should ensure Root::into_inner
or Root::drop
is called
to properly dispose of the Root<T>
. If the value is dropped without
calling one of these methods:
- N-API < 6, Neon will
panic
to notify of the leak - N-API >= 6, Neon will drop from a global queue at a runtime cost
Clone a reference to the contained JavaScript object. This method can be considered identical to the following:
let inner = root.into_inner(&mut cx);
let cloned = inner.root(&mut cx);
let root = inner.root(&mut cx);
Safely drop a Root<T>
without returning the referenced JavaScript
object.
Return the referenced JavaScript object and allow it to be garbage collected