JSValue

Struct JSValue 

Source
pub struct JSValue<'a> { /* private fields */ }
Expand description

A JavaScript value.

This is the basic type for managing values in JavaScriptCore. It can represent any JavaScript value, including undefined, null, booleans, numbers, strings, symbols, objects, and arrays.

Implementations§

Source§

impl<'a> JSValue<'a>

Source

pub fn new_undefined(ctx: &'a JSContext) -> Self

Creates a Javascript undefined value.

Source

pub fn new_null(ctx: &'a JSContext) -> Self

Creates a Javascript null value.

Source

pub fn new_boolean(ctx: &'a JSContext, value: bool) -> Self

Creates a Javascript boolean value.

Source

pub fn new_number(ctx: &'a JSContext, value: f64) -> Self

Creates a Javascript numeric value.

Source

pub fn new_symbol(ctx: &'a JSContext, description: &str) -> Self

Creates a unique Javascript symbol object.

description is a string that describes the symbol.

Source

pub fn from_jsstring(ctx: &'a JSContext, value: JSString) -> Self

Converts a Javascript string object to a Javascript value.

Source

pub fn new_string(ctx: &'a JSContext, value: &str) -> Self

Creates a Javascript string value from a Rust string.

If you have already JSString object, use JSValue::from_jsstring instead.

Source

pub fn new_from_json(ctx: &'a JSContext, value: &str) -> Option<Self>

Creates a JavaScript value from a JSON formatted string.

Returns None if the JSON string is invalid.

Source§

impl JSValue<'_>

Source

pub fn get_type(&self) -> JSType

Returns a JavaScript value’s type.

Source

pub fn is_undefined(&self) -> bool

Returns true if the value is undefined.

Source

pub fn is_null(&self) -> bool

Returns true if the value is null.

Source

pub fn is_date(&self) -> bool

Returns true if the value is a JavaScript date object.

Source

pub fn is_array(&self) -> bool

Returns true if the value is a JavaScript array.

Source

pub fn is_symbol(&self) -> bool

Returns true if the value’s type is the symbol type

Source

pub fn is_object(&self) -> bool

Returns true if the value is an object.

Source

pub fn is_string(&self) -> bool

Returns true if the value is a string.

Source

pub fn is_number(&self) -> bool

Returns true if the value is a number.

Source

pub fn is_boolean(&self) -> bool

Returns true if the value is a boolean.

Source

pub fn is_typed_array(&self) -> bool

Returns true if the value is a Typed Array.

Source§

impl<'a> JSValue<'a>

Source

pub fn as_object(&self) -> Result<JSObject<'a>, JSValue<'a>>

Converts a JavaScript value to object.

Returns an Err if an exception is thrown.

Source

pub fn as_string(&self) -> Result<JSString, JSValue<'a>>

Converts a JavaScript value to string.

Returns an Err if an exception is thrown.

Source

pub fn as_number(&self) -> Result<f64, JSValue<'a>>

Converts a JavaScript value to number.

Returns an Err if an exception is thrown.

Source

pub fn as_boolean(&self) -> bool

Converts a JavaScript value to boolean.

Source

pub fn as_typed_array(&self) -> Result<JSTypedArray<'a>, JSValue<'a>>

Converts a JavaScript value to a typed array.

Returns an Err if the value is not a typed array, or if an exception is thrown.

Source

pub fn to_json_string(&self) -> Result<JSString, JSValue<'a>>

Converts a JavaScript value to JSON serialized representation of a JS value.

Returns an Err if an exception is thrown.

Trait Implementations§

Source§

impl<'a> AsRef<JSValue<'a>> for JSObject<'a>

Source§

fn as_ref(&self) -> &JSValue<'a>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a> AsRef<JSValue<'a>> for JSTypedArray<'a>

Source§

fn as_ref(&self) -> &JSValue<'a>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for JSValue<'_>

Source§

fn clone(&self) -> Self

Returns a duplicate 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 Drop for JSValue<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for JSValue<'a>

§

impl<'a> RefUnwindSafe for JSValue<'a>

§

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

§

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

§

impl<'a> Unpin for JSValue<'a>

§

impl<'a> UnwindSafe for JSValue<'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> 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, 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,

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.