Struct JsValue

Source
#[repr(C)]
pub struct JsValue(/* private fields */);

Implementations§

Source§

impl JsValue

Source

pub fn env(&self) -> NapiEnv

NapiEnv of this JsValue

Source

pub fn raw(&self) -> napi_value

raw napi_value of this JsValue

Source

pub fn is_object(&self) -> NapiResult<bool>

Source

pub fn as_object(&self) -> NapiResult<JsObject>

view it as an object, may fail if it is not an object value

Source

pub fn is_string(&self) -> NapiResult<bool>

Source

pub fn as_string(&self) -> NapiResult<JsString>

view it as a string, may fail if it is not a string value

Source

pub fn is_symbol(&self) -> NapiResult<bool>

Source

pub fn as_symbol(&self) -> NapiResult<JsSymbol>

view it as a symbol, may fail if it is not a symbol value

Source

pub fn is_array(&self) -> NapiResult<bool>

Source

pub fn as_array(&self) -> NapiResult<JsArray>

view it as an array, may fail if it is not an array value

Source

pub fn is_typedarray(&self) -> NapiResult<bool>

Source

pub fn as_typedarray(&self) -> NapiResult<JsTypedArray>

view it as a typed_array, may fail if it is not a typed_array value

Source

pub fn is_arraybuffer(&self) -> NapiResult<bool>

Source

pub fn as_arraybuffer(&self) -> NapiResult<JsArrayBuffer>

view it as an array_buffer, may fail if it is not an array_buffer value

Source

pub fn is_buffer<const N: usize>(&self) -> NapiResult<bool>

Source

pub fn as_buffer<const N: usize>(&self) -> NapiResult<JsBuffer<N>>

view it as a buffer, may fail if it is not a buffer value

Source

pub fn is_dataview(&self) -> NapiResult<bool>

Source

pub fn as_dataview(&self) -> NapiResult<JsDataView>

view it as a dataview, may fail if it is not a dataview value

Source

pub fn is_external<T>(&self) -> NapiResult<bool>

Source

pub fn as_external<T>(&self) -> NapiResult<JsExternal<T>>

view it as an external, may fail if it is not an external value

Source

pub fn is_function(&self) -> NapiResult<bool>

Source

pub fn as_function(&self) -> NapiResult<JsFunction>

view it as a number, may fail if it is not a number value

Source

pub fn is_number(&self) -> NapiResult<bool>

Source

pub fn as_number(&self) -> NapiResult<JsNumber>

view it as a number, may fail if it is not a number value

Source

pub fn is_bigint<T: Copy>(&self) -> NapiResult<bool>

Source

pub fn as_bigint<T: Copy>(&self) -> NapiResult<JsBigInt<T>>

view it as a bigint, may fail if it is not a bigint value

Source

pub fn is_boolean(&self) -> NapiResult<bool>

Source

pub fn as_boolean(&self) -> NapiResult<JsBoolean>

view it as a boolean, may fail if it is not a boolean value

Source

pub fn is_date(&self) -> NapiResult<bool>

Source

pub fn as_date(&self) -> NapiResult<JsDate>

view it as a date, may fail if it is not a date value

Trait Implementations§

Source§

impl Clone for JsValue

Source§

fn clone(&self) -> JsValue

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for JsValue

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl NapiValueCheck for JsValue

Source§

impl NapiValueT for JsValue

Source§

fn from_raw(env: NapiEnv, value: napi_value) -> JsValue

construct value from raw pointer
Source§

fn value(&self) -> JsValue

inner value
Source§

unsafe fn cast<T: NapiValueT>(&self) -> T

napi_value type cast Read more
Source§

fn cast_checked<T: NapiValueT>(&self) -> NapiResult<T>

Upcast to specified value
Source§

fn kind(&self) -> NapiResult<NapiValuetype>

Returns napi_ok if the API succeeded. Read more
Source§

fn coerce_to_bool(&self) -> NapiResult<JsBoolean>

This API implements the abstract operation ToBoolean() as defined in Section 7.1.2 of the ECMAScript Language Specification.
Source§

fn coerce_coerce_to_number(&self) -> NapiResult<JsNumber>

This API implements the abstract operation ToNumber() as defined in Section 7.1.3 of the ECMAScript Language Specification. This function potentially runs JS code if the passed-in value is an object.
Source§

fn coerce_to_object(&self) -> NapiResult<JsObject>

This API implements the abstract operation ToObject() as defined in Section 7.1.13 of the ECMAScript Language Specification.
Source§

fn coerce_to_string(&self) -> NapiResult<JsString>

This API implements the abstract operation ToString() as defined in Section 7.1.13 of the ECMAScript Language Specification. This function potentially runs JS code if the passed-in value is an object.
Source§

fn instance_of(&self, constructor: JsFunction) -> NapiResult<bool>

This API represents invoking the instanceof Operator on the object as defined in Section 12.10.4 of the ECMAScript Language Specification.
Source§

fn equals(&self, rhs: impl NapiValueT) -> NapiResult<bool>

This API represents the invocation of the Strict Equality algorithm as defined in Section 7.2.14 of the ECMAScript Language Specification.
Source§

fn env(&self) -> NapiEnv

the NapiEnv of current value
Source§

fn raw(&self) -> napi_value

the raw-handle of current value
Source§

fn null(&self) -> NapiResult<JsNull>

get null singleton
Source§

fn undefined(&self) -> NapiResult<JsUndefined>

get undefined singleton
Source§

fn global(&self) -> NapiResult<JsGlobal>

get global singleton
Source§

fn throw(&self) -> NapiResult<()>

value is throwable
Source§

fn define_properties<P>(&self, properties: P) -> NapiResult<()>

This method allows the efficient definition of multiple properties on a given object. The properties are defined using property descriptors (see napi_property_descriptor). Given an array of such property descriptors, this API will set the properties on the object one at a time, as defined by DefineOwnProperty() (described in Section 9.1.6 of the ECMA-262 specification).
Source§

fn gc<Finalizer>(&mut self, finalizer: Finalizer) -> NapiResult<NapiRef>
where Finalizer: FnOnce(NapiEnv) -> NapiResult<()>,

This is a hook which is fired when the value is gabage-collected. For napi >= 5, we use napi_add_finalizer, For napi < 5, we use napi_wrap.
Source§

fn finalizer<Finalizer>(&self, finalizer: Finalizer) -> NapiResult<NapiRef>
where Finalizer: FnOnce(NapiEnv) -> NapiResult<()>,

Adds a napi_finalize callback which will be called when the JavaScript object in js_object is ready for garbage collection. This API is similar to napi_wrap() except that: Read more
Source§

fn wrap<T>( &mut self, data: T, finalizer: impl FnOnce(NapiEnv, T) -> NapiResult<()>, ) -> NapiResult<NapiRef>

Wraps a native instance in a JavaScript object. The native instance can be retrieved later using napi_unwrap(). Read more
Source§

fn unwrap<T>(&self) -> NapiResult<Option<&mut T>>

Retrieves a native instance that was previously wrapped in a JavaScript object using napi_wrap(). Read more
Source§

fn remove_wrap<T>(&mut self) -> NapiResult<T>

Retrieves a native instance that was previously wrapped in the JavaScript object js_object using napi_wrap() and removes the wrapping. If a finalize callback was associated with the wrapping, it will no longer be called when the JavaScript object becomes garbage-collected.
Source§

fn type_tag_object(&self, tag: &NapiTypeTag) -> NapiResult<()>

Associates the value of the type_tag pointer with the JavaScript object. napi_check_object_type_tag() can then be used to compare the tag that was attached to the object with one owned by the addon to ensure that the object has the right type. If the object already has an associated type tag, this API will return napi_invalid_arg.
Source§

fn check_object_type_tag(&self, tag: &NapiTypeTag) -> NapiResult<bool>

Compares the pointer given as type_tag with any that can be found on js_object. If no tag is found on js_object or, if a tag is found but it does not match type_tag, then result is set to false. If a tag is found and it matches type_tag, then result is set to true.
Source§

impl Copy for JsValue

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromJsArgs for T
where T: NapiValueT,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToJsArgs for T
where T: NapiValueT,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.