pub struct NapiEscapableHandleScope(/* private fields */);
Expand description
When nesting scopes, there are cases where a handle from an inner scope needs to live beyond the lifespan of that scope. Node-API supports an ‘escapable scope’ in order to support this case. An escapable scope allows one handle to be ‘promoted’ so that it ‘escapes’ the current scope and the lifespan of the handle changes from the current scope to that of the outer scope.
The methods available to open/close escapable scopes are napi_open_escapable_handle_scope and napi_close_escapable_handle_scope.
The request to promote a handle is made through napi_escape_handle which can only be called once.
Implementations§
Source§impl NapiEscapableHandleScope
impl NapiEscapableHandleScope
pub fn env(&self) -> NapiEnv
pub fn raw(&self) -> napi_escapable_handle_scope
Sourcepub fn open(env: NapiEnv) -> NapiResult<NapiEscapableHandleScope>
pub fn open(env: NapiEnv) -> NapiResult<NapiEscapableHandleScope>
This API opens a new scope from which one object can be promoted to the outer scope.
Sourcepub fn close(&mut self) -> NapiResult<()>
pub fn close(&mut self) -> NapiResult<()>
This API closes the scope passed in. Scopes must be closed in the reverse order from which they were created. This API can be called even if there is a pending JavaScript exception.
Sourcepub fn escape<T: NapiValueT>(&mut self, escapee: T) -> NapiResult<T>
pub fn escape<T: NapiValueT>(&mut self, escapee: T) -> NapiResult<T>
This API promotes the handle to the JavaScript object so that it is valid for the lifetime of the outer scope. It can only be called once per scope. If it is called more than once an error will be returned.
This API can be called even if there is a pending JavaScript exception.
Trait Implementations§
Source§impl Clone for NapiEscapableHandleScope
impl Clone for NapiEscapableHandleScope
Source§fn clone(&self) -> NapiEscapableHandleScope
fn clone(&self) -> NapiEscapableHandleScope
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more