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>
impl<'a> JSValueRef<'a>
sourcepub fn call(&self, receiver: &Self, args: &[Self]) -> Result<Self>
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 ofJSValueRef
representing the arguments to be passed to the function.
sourcepub fn as_i32_unchecked(&self) -> i32
pub fn as_i32_unchecked(&self) -> i32
Converts the JavaScript value to an i32
without checking its type.
sourcepub fn as_u32_unchecked(&self) -> u32
pub fn as_u32_unchecked(&self) -> u32
Converts the JavaScript value to a u32
without checking its type.
sourcepub fn as_f64_unchecked(&self) -> f64
pub fn as_f64_unchecked(&self) -> f64
Converts the JavaScript value to an f64
without checking its type.
sourcepub fn as_big_int_unchecked(&self) -> Result<BigInt>
pub fn as_big_int_unchecked(&self) -> Result<BigInt>
Converts the JavaScript value to a BigInt
without checking its type.
sourcepub fn is_number(&self) -> bool
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
.
sourcepub fn is_big_int(&self) -> bool
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
.
sourcepub fn as_f64(&self) -> Result<f64>
pub fn as_f64(&self) -> Result<f64>
Converts the JavaScript value to an f64
if it is a number, otherwise returns an error.
sourcepub fn try_as_integer(&self) -> Result<i32>
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.
sourcepub fn as_bool(&self) -> Result<bool>
pub fn as_bool(&self) -> Result<bool>
Converts the JavaScript value to a bool
if it is a boolean, otherwise returns an error.
sourcepub fn as_str(&self) -> Result<&str>
pub fn as_str(&self) -> Result<&str>
Converts the JavaScript value to a string if it is a string.
sourcepub fn as_str_lossy(&self) -> Cow<'_, str>
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).
sourcepub fn as_bytes(&self) -> Result<&[u8]>
pub fn as_bytes(&self) -> Result<&[u8]>
Converts the JavaScript value to a byte slice if it is an ArrayBuffer, otherwise returns an error.
sourcepub fn as_bytes_mut(&self) -> Result<&mut [u8]>
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.
sourcepub fn properties(&self) -> Result<Properties<'a>>
pub fn properties(&self) -> Result<Properties<'a>>
Retrieves the properties of the JavaScript value.
sourcepub fn is_repr_as_f64(&self) -> bool
pub fn is_repr_as_f64(&self) -> bool
Checks if the JavaScript value is represented as an f64
.
sourcepub fn is_repr_as_i32(&self) -> bool
pub fn is_repr_as_i32(&self) -> bool
Checks if the JavaScript value is represented as an i32
.
sourcepub fn is_object(&self) -> bool
pub fn is_object(&self) -> bool
Checks if the JavaScript value is an object (excluding arrays).
sourcepub fn is_array_buffer(&self) -> bool
pub fn is_array_buffer(&self) -> bool
Checks if the JavaScript value is an ArrayBuffer.
sourcepub fn is_undefined(&self) -> bool
pub fn is_undefined(&self) -> bool
Checks if the JavaScript value is undefined.
sourcepub fn is_null_or_undefined(&self) -> bool
pub fn is_null_or_undefined(&self) -> bool
Checks if the JavaScript value is either null or undefined.
sourcepub fn is_function(&self) -> bool
pub fn is_function(&self) -> bool
Checks if the JavaScript value is a function.
sourcepub fn get_property(&self, key: impl Into<Vec<u8>>) -> Result<Self>
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.
sourcepub fn set_property(
&self,
key: impl Into<Vec<u8>>,
val: JSValueRef<'_>
) -> Result<()>
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
.
sourcepub fn get_indexed_property(&self, index: u32) -> Result<Self>
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.
sourcepub fn append_property(&self, val: JSValueRef<'_>) -> Result<()>
pub fn append_property(&self, val: JSValueRef<'_>) -> Result<()>
Appends a property with the value val
to the JavaScript object.
This is used for arrays.
sourcepub fn is_exception(&self) -> bool
pub fn is_exception(&self) -> bool
Checks if the JavaScript value is an exception.
Trait Implementations§
source§impl<'a> Clone for JSValueRef<'a>
impl<'a> Clone for JSValueRef<'a>
source§fn clone(&self) -> JSValueRef<'a>
fn clone(&self) -> JSValueRef<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more