Struct napi::bindgen_prelude::JsFunction
source · pub struct JsFunction(_);
Implementations§
source§impl JsFunction
impl JsFunction
See Working with JavaScript Functions.
Example:
use napi::{JsFunction, CallContext, JsNull, Result};
#[js_function(1)]
pub fn call_function(ctx: CallContext) -> Result<JsNull> {
let js_func = ctx.get::<JsFunction>(0)?;
let js_string = ctx.env.create_string("hello".as_ref())?.into_unknown()?;
js_func.call(None, &[js_string])?;
Ok(ctx.env.get_null()?)
}
sourcepub fn call<V>(&self, this: Option<&JsObject>, args: &[V]) -> Result<JsUnknown>where
V: NapiRaw,
pub fn call<V>(&self, this: Option<&JsObject>, args: &[V]) -> Result<JsUnknown>where V: NapiRaw,
sourcepub fn call_without_args(&self, this: Option<&JsObject>) -> Result<JsUnknown>
pub fn call_without_args(&self, this: Option<&JsObject>) -> Result<JsUnknown>
napi_call_function
The same with call
, but without arguments
sourcepub fn new_instance<V>(&self, args: &[V]) -> Result<JsObject>where
V: NapiRaw,
pub fn new_instance<V>(&self, args: &[V]) -> Result<JsObject>where V: NapiRaw,
https://nodejs.org/api/n-api.html#n_api_napi_new_instance
This method is used to instantiate a new JavaScript
value using a given JsFunction
that represents the constructor for the object.
pub fn create_threadsafe_function<T, V, F, ES>( &self, max_queue_size: usize, callback: F ) -> Result<ThreadsafeFunction<T, ES>>where T: 'static, V: ToNapiValue, F: 'static + Send + FnMut(ThreadSafeCallContext<T>) -> Result<Vec<V>>, ES: T,
source§impl JsFunction
impl JsFunction
pub fn into_unknown(self) -> JsUnknown
pub fn coerce_to_bool(self) -> Result<JsBoolean>
pub fn coerce_to_number(self) -> Result<JsNumber>
pub fn coerce_to_string(self) -> Result<JsString>
pub fn coerce_to_object(self) -> Result<JsObject>
pub fn is_date(&self) -> Result<bool>
pub fn is_promise(&self) -> Result<bool>
pub fn is_error(&self) -> Result<bool>
pub fn is_typedarray(&self) -> Result<bool>
pub fn is_dataview(&self) -> Result<bool>
pub fn is_array(&self) -> Result<bool>
pub fn is_buffer(&self) -> Result<bool>
pub fn instanceof<Constructor>(&self, constructor: Constructor) -> Result<bool>where Constructor: NapiRaw,
Trait Implementations§
source§impl<'env> NapiRaw for &'env JsFunction
impl<'env> NapiRaw for &'env JsFunction
unsafe fn raw(&self) -> napi_value
source§impl NapiRaw for JsFunction
impl NapiRaw for JsFunction
unsafe fn raw(&self) -> napi_value
source§impl NapiValue for JsFunction
impl NapiValue for JsFunction
unsafe fn from_raw(env: napi_env, value: napi_value) -> Result<JsFunction>
unsafe fn from_raw_unchecked(env: napi_env, value: napi_value) -> JsFunction
source§impl TryFrom<JsUnknown> for JsFunction
impl TryFrom<JsUnknown> for JsFunction
source§impl TypeName for JsFunction
impl TypeName for JsFunction
source§impl ValidateNapiValue for JsFunction
impl ValidateNapiValue for JsFunction
source§unsafe fn validate(env: napi_env, napi_val: napi_value) -> Result<napi_value>
unsafe fn validate(env: napi_env, napi_val: napi_value) -> Result<napi_value>
Safety Read more