Struct quickjs_wasm_rs::JSValueRef

source ·
pub struct JSValueRef<'a> { /* private fields */ }
Expand description

JSValueRef is a wrapper around a QuickJS JSValue with a reference to its associated JSContextRef.

This struct provides a safe interface for interacting with JavaScript values in the context of their associated QuickJS execution environment.

§Lifetime

The lifetime parameter 'a represents the lifetime of the reference to the JSContextRef. This ensures that the JSValueRef cannot outlive the context it is associated with, preventing potential use-after-free issues or other unsafe behavior.

Implementations§

source§

impl<'a> JSValueRef<'a>

source

pub fn call(&self, receiver: &Self, args: &[Self]) -> Result<Self>

Calls a JavaScript function with the specified receiver and args.

§Arguments
  • receiver: The object on which the function is called.
  • args: A slice of JSValueRef representing the arguments to be passed to the function.
source

pub fn as_i32_unchecked(&self) -> i32

Converts the JavaScript value to an i32 without checking its type.

source

pub fn as_u32_unchecked(&self) -> u32

Converts the JavaScript value to a u32 without checking its type.

source

pub fn as_f64_unchecked(&self) -> f64

Converts the JavaScript value to an f64 without checking its type.

source

pub fn as_big_int_unchecked(&self) -> Result<BigInt>

Converts the JavaScript value to a BigInt without checking its type.

source

pub fn is_number(&self) -> bool

Checks if the JavaScript value is a number.

Returns true if the value is a number (either represented as an f64 or an i32), otherwise returns false.

source

pub fn is_big_int(&self) -> bool

Checks if the JavaScript value is a BigInt.

Returns true if the value is a BigInt, otherwise returns false.

source

pub fn as_f64(&self) -> Result<f64>

Converts the JavaScript value to an f64 if it is a number, otherwise returns an error.

source

pub fn try_as_integer(&self) -> Result<i32>

Tries to convert the JavaScript value to an i32 if it is an integer, otherwise returns an error.

source

pub fn as_bool(&self) -> Result<bool>

Converts the JavaScript value to a bool if it is a boolean, otherwise returns an error.

source

pub fn as_str(&self) -> Result<&str>

Converts the JavaScript value to a string if it is a string.

source

pub fn as_str_lossy(&self) -> Cow<'_, str>

Converts the JavaScript value to a string, replacing any invalid UTF-8 sequences with the Unicode replacement character (U+FFFD).

source

pub fn as_bytes(&self) -> Result<&[u8]>

Converts the JavaScript value to a byte slice if it is an ArrayBuffer, otherwise returns an error.

source

pub fn as_bytes_mut(&self) -> Result<&mut [u8]>

Converts the JavaScript value to a mutable byte slice if it is an ArrayBuffer, otherwise returns an error.

source

pub fn properties(&self) -> Result<Properties<'a>>

Retrieves the properties of the JavaScript value.

source

pub fn is_repr_as_f64(&self) -> bool

Checks if the JavaScript value is represented as an f64.

source

pub fn is_repr_as_i32(&self) -> bool

Checks if the JavaScript value is represented as an i32.

source

pub fn is_str(&self) -> bool

Checks if the JavaScript value is a string.

source

pub fn is_bool(&self) -> bool

Checks if the JavaScript value is a boolean.

source

pub fn is_array(&self) -> bool

Checks if the JavaScript value is an array.

source

pub fn is_object(&self) -> bool

Checks if the JavaScript value is an object (excluding arrays).

source

pub fn is_array_buffer(&self) -> bool

Checks if the JavaScript value is an ArrayBuffer.

source

pub fn is_undefined(&self) -> bool

Checks if the JavaScript value is undefined.

source

pub fn is_null(&self) -> bool

Checks if the JavaScript value is null.

source

pub fn is_null_or_undefined(&self) -> bool

Checks if the JavaScript value is either null or undefined.

source

pub fn is_function(&self) -> bool

Checks if the JavaScript value is a function.

source

pub fn get_property(&self, key: impl Into<Vec<u8>>) -> Result<Self>

Retrieves the value of a property with the specified key from the JavaScript object.

source

pub fn set_property( &self, key: impl Into<Vec<u8>>, val: JSValueRef<'_> ) -> Result<()>

Sets the value of a property with the specified key on the JavaScript object to val.

source

pub fn get_indexed_property(&self, index: u32) -> Result<Self>

Retrieves the value of an indexed property from the JavaScript object. This is used for arrays.

source

pub fn append_property(&self, val: JSValueRef<'_>) -> Result<()>

Appends a property with the value val to the JavaScript object. This is used for arrays.

source

pub fn is_exception(&self) -> bool

Checks if the JavaScript value is an exception.

Trait Implementations§

source§

impl<'a> Clone for JSValueRef<'a>

source§

fn clone(&self) -> JSValueRef<'a>

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<'a> Debug for JSValueRef<'a>

source§

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

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

impl Display for JSValueRef<'_>

source§

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

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

impl<'de> From<JSValueRef<'de>> for Deserializer<'de>

source§

fn from(value: JSValueRef<'de>) -> Self

Converts to this type from the input type.
source§

impl Into<u64> for JSValueRef<'_>

source§

fn into(self) -> JSValueRaw

Converts this type into the (usually inferred) input type.
source§

impl TryFrom<&JSValueRef<'_>> for HashMap<String, JSValue>

§

type Error = Error

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

fn try_from(value: &JSValueRef<'_>) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<&JSValueRef<'_>> for String

§

type Error = Error

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

fn try_from(value: &JSValueRef<'_>) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<&JSValueRef<'_>> for Vec<JSValue>

§

type Error = Error

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

fn try_from(value: &JSValueRef<'_>) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<&JSValueRef<'_>> for Vec<u8>

§

type Error = Error

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

fn try_from(value: &JSValueRef<'_>) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<&JSValueRef<'_>> for bool

§

type Error = Error

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

fn try_from(value: &JSValueRef<'_>) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<&JSValueRef<'_>> for f64

§

type Error = Error

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

fn try_from(value: &JSValueRef<'_>) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<&JSValueRef<'_>> for i32

§

type Error = Error

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

fn try_from(value: &JSValueRef<'_>) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<&JSValueRef<'_>> for usize

§

type Error = Error

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

fn try_from(value: &JSValueRef<'_>) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<JSValueRef<'_>> for HashMap<String, JSValue>

§

type Error = Error

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

fn try_from(value: JSValueRef<'_>) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<JSValueRef<'_>> for String

§

type Error = Error

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

fn try_from(value: JSValueRef<'_>) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<JSValueRef<'_>> for Vec<JSValue>

§

type Error = Error

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

fn try_from(value: JSValueRef<'_>) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<JSValueRef<'_>> for Vec<u8>

§

type Error = Error

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

fn try_from(value: JSValueRef<'_>) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<JSValueRef<'_>> for bool

§

type Error = Error

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

fn try_from(value: JSValueRef<'_>) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<JSValueRef<'_>> for f64

§

type Error = Error

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

fn try_from(value: JSValueRef<'_>) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<JSValueRef<'_>> for i32

§

type Error = Error

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

fn try_from(value: JSValueRef<'_>) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<JSValueRef<'_>> for usize

§

type Error = Error

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

fn try_from(value: JSValueRef<'_>) -> Result<Self>

Performs the conversion.
source§

impl<'a> Copy for JSValueRef<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for JSValueRef<'a>

§

impl<'a> RefUnwindSafe for JSValueRef<'a>

§

impl<'a> !Send for JSValueRef<'a>

§

impl<'a> !Sync for JSValueRef<'a>

§

impl<'a> Unpin for JSValueRef<'a>

§

impl<'a> UnwindSafe for JSValueRef<'a>

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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.