pub struct ModuleContext<'cx> { /* private fields */ }
Expand description
An execution context of module initialization.
Implementations§
Source§impl<'cx> ModuleContext<'cx>
impl<'cx> ModuleContext<'cx>
Sourcepub fn export_function<F, V>(&mut self, key: &str, f: F) -> NeonResult<()>
pub fn export_function<F, V>(&mut self, key: &str, f: F) -> NeonResult<()>
Convenience method for exporting a Neon function from a module.
Sourcepub fn export_value<T: Value>(
&mut self,
key: &str,
val: Handle<'_, T>,
) -> NeonResult<()>
pub fn export_value<T: Value>( &mut self, key: &str, val: Handle<'_, T>, ) -> NeonResult<()>
Exports a JavaScript value from a Neon module.
Sourcepub fn exports_object(&mut self) -> JsResult<'cx, JsObject>
pub fn exports_object(&mut self) -> JsResult<'cx, JsObject>
Produces a handle to a module’s exports object.
Trait Implementations§
Source§impl<'cx> Context<'cx> for ModuleContext<'cx>
impl<'cx> Context<'cx> for ModuleContext<'cx>
Source§fn lock<'b>(&'b mut self) -> Lock<'b, Self>where
'a: 'b,
fn lock<'b>(&'b mut self) -> Lock<'b, Self>where
'a: 'b,
Lock the JavaScript engine, returning an RAII guard that keeps the lock active as long as the guard is alive. Read more
Source§fn execute_scoped<'b, T, F>(&mut self, f: F) -> T
fn execute_scoped<'b, T, F>(&mut self, f: F) -> T
Executes a computation in a new memory management scope. Read more
Source§fn compute_scoped<'b, V, F>(&mut self, f: F) -> JsResult<'a, V>
fn compute_scoped<'b, V, F>(&mut self, f: F) -> JsResult<'a, V>
Executes a computation in a new memory management scope and computes a single result value that outlives the computation. Read more
fn try_catch<T, F>(&mut self, f: F) -> Result<T, Handle<'a, JsValue>>where
F: FnOnce(&mut Self) -> NeonResult<T>,
Source§fn boolean(&mut self, b: bool) -> Handle<'a, JsBoolean>
fn boolean(&mut self, b: bool) -> Handle<'a, JsBoolean>
Convenience method for creating a
JsBoolean
value.Source§fn number<T: Into<f64>>(&mut self, x: T) -> Handle<'a, JsNumber>
fn number<T: Into<f64>>(&mut self, x: T) -> Handle<'a, JsNumber>
Convenience method for creating a
JsNumber
value.Source§fn string<S: AsRef<str>>(&mut self, s: S) -> Handle<'a, JsString>
fn string<S: AsRef<str>>(&mut self, s: S) -> Handle<'a, JsString>
Convenience method for creating a
JsString
value. Read moreSource§fn try_string<S: AsRef<str>>(&mut self, s: S) -> StringResult<'a>
fn try_string<S: AsRef<str>>(&mut self, s: S) -> StringResult<'a>
Convenience method for creating a
JsString
value. Read moreSource§fn undefined(&mut self) -> Handle<'a, JsUndefined>
fn undefined(&mut self) -> Handle<'a, JsUndefined>
Convenience method for creating a
JsUndefined
value.Source§fn empty_object(&mut self) -> Handle<'a, JsObject>
fn empty_object(&mut self) -> Handle<'a, JsObject>
Convenience method for creating an empty
JsObject
value.Source§fn empty_array(&mut self) -> Handle<'a, JsArray>
fn empty_array(&mut self) -> Handle<'a, JsArray>
Convenience method for creating an empty
JsArray
value.Source§fn array_buffer(&mut self, size: usize) -> JsResult<'a, JsArrayBuffer>
fn array_buffer(&mut self, size: usize) -> JsResult<'a, JsArrayBuffer>
Convenience method for creating an empty
JsArrayBuffer
value.Source§fn buffer(&mut self, size: usize) -> JsResult<'a, JsBuffer>
fn buffer(&mut self, size: usize) -> JsResult<'a, JsBuffer>
Convenience method for creating an empty
JsBuffer
value.Source§fn date(
&mut self,
value: impl Into<f64>,
) -> Result<Handle<'a, JsDate>, DateError>
fn date( &mut self, value: impl Into<f64>, ) -> Result<Handle<'a, JsDate>, DateError>
Available on crate feature
napi-5
only.Convenience method for creating a
JsDate
value.Source§fn global<T: Value>(&mut self, name: &str) -> JsResult<'a, T>
fn global<T: Value>(&mut self, name: &str) -> JsResult<'a, T>
Convenience method for looking up a global property by name. Read more
Source§fn global_object(&mut self) -> Handle<'a, JsObject>
fn global_object(&mut self) -> Handle<'a, JsObject>
Produces a handle to the JavaScript global object.
Source§fn error<S: AsRef<str>>(&mut self, msg: S) -> JsResult<'a, JsError>
fn error<S: AsRef<str>>(&mut self, msg: S) -> JsResult<'a, JsError>
Creates a direct instance of the
Error
class.Source§fn type_error<S: AsRef<str>>(&mut self, msg: S) -> JsResult<'a, JsError>
fn type_error<S: AsRef<str>>(&mut self, msg: S) -> JsResult<'a, JsError>
Creates an instance of the
TypeError
class.Source§fn range_error<S: AsRef<str>>(&mut self, msg: S) -> JsResult<'a, JsError>
fn range_error<S: AsRef<str>>(&mut self, msg: S) -> JsResult<'a, JsError>
Creates an instance of the
RangeError
class.Source§fn throw_error<S: AsRef<str>, T>(&mut self, msg: S) -> NeonResult<T>
fn throw_error<S: AsRef<str>, T>(&mut self, msg: S) -> NeonResult<T>
Throws a direct instance of the
Error
class.Source§fn throw_type_error<S: AsRef<str>, T>(&mut self, msg: S) -> NeonResult<T>
fn throw_type_error<S: AsRef<str>, T>(&mut self, msg: S) -> NeonResult<T>
Throws an instance of the
TypeError
class.Source§fn throw_range_error<S: AsRef<str>, T>(&mut self, msg: S) -> NeonResult<T>
fn throw_range_error<S: AsRef<str>, T>(&mut self, msg: S) -> NeonResult<T>
Throws an instance of the
RangeError
class.Source§fn boxed<U: Finalize + 'static>(&mut self, v: U) -> Handle<'a, JsBox<U>>
fn boxed<U: Finalize + 'static>(&mut self, v: U) -> Handle<'a, JsBox<U>>
Convenience method for wrapping a value in a
JsBox
. Read moreSource§fn channel(&mut self) -> Channel
fn channel(&mut self) -> Channel
Available on crate feature
napi-4
only.Returns an unbounded channel for scheduling events to be executed on the JavaScript thread. Read more
Source§fn task<'cx, O, E>(&'cx mut self, execute: E) -> TaskBuilder<'cx, Self, E>
fn task<'cx, O, E>(&'cx mut self, execute: E) -> TaskBuilder<'cx, Self, E>
Creates a
TaskBuilder
which can be used to schedule the execute
callback to asynchronously execute on the
Node worker pool. Read moreSource§impl<'cx> Deref for ModuleContext<'cx>
impl<'cx> Deref for ModuleContext<'cx>
Source§impl<'cx> DerefMut for ModuleContext<'cx>
impl<'cx> DerefMut for ModuleContext<'cx>
Source§impl<'cx> From<ModuleContext<'cx>> for Cx<'cx>
impl<'cx> From<ModuleContext<'cx>> for Cx<'cx>
Source§fn from(cx: ModuleContext<'cx>) -> Self
fn from(cx: ModuleContext<'cx>) -> Self
Converts to this type from the input type.
impl<'cx> UnwindSafe for ModuleContext<'cx>
Auto Trait Implementations§
impl<'cx> Freeze for ModuleContext<'cx>
impl<'cx> RefUnwindSafe for ModuleContext<'cx>
impl<'cx> !Send for ModuleContext<'cx>
impl<'cx> !Sync for ModuleContext<'cx>
impl<'cx> Unpin for ModuleContext<'cx>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more