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>
impl<'a> JSValue<'a>
Sourcepub fn new_undefined(ctx: &'a JSContext) -> Self
pub fn new_undefined(ctx: &'a JSContext) -> Self
Creates a Javascript undefined
value.
Sourcepub fn new_boolean(ctx: &'a JSContext, value: bool) -> Self
pub fn new_boolean(ctx: &'a JSContext, value: bool) -> Self
Creates a Javascript boolean value.
Sourcepub fn new_number(ctx: &'a JSContext, value: f64) -> Self
pub fn new_number(ctx: &'a JSContext, value: f64) -> Self
Creates a Javascript numeric value.
Sourcepub fn new_symbol(ctx: &'a JSContext, description: &str) -> Self
pub fn new_symbol(ctx: &'a JSContext, description: &str) -> Self
Creates a unique Javascript symbol object.
description
is a string that describes the symbol.
Sourcepub fn from_jsstring(ctx: &'a JSContext, value: JSString) -> Self
pub fn from_jsstring(ctx: &'a JSContext, value: JSString) -> Self
Converts a Javascript string object to a Javascript value.
Sourcepub fn new_string(ctx: &'a JSContext, value: &str) -> Self
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§impl JSValue<'_>
impl JSValue<'_>
Sourcepub fn is_undefined(&self) -> bool
pub fn is_undefined(&self) -> bool
Returns true
if the value is undefined
.
Sourcepub fn is_boolean(&self) -> bool
pub fn is_boolean(&self) -> bool
Returns true
if the value is a boolean.
Sourcepub fn is_typed_array(&self) -> bool
pub fn is_typed_array(&self) -> bool
Returns true
if the value is a Typed Array.
Source§impl<'a> JSValue<'a>
impl<'a> JSValue<'a>
Sourcepub fn as_object(&self) -> Result<JSObject<'a>, JSValue<'a>>
pub fn as_object(&self) -> Result<JSObject<'a>, JSValue<'a>>
Converts a JavaScript value to object.
Returns an Err
if an exception is thrown.
Sourcepub fn as_string(&self) -> Result<JSString, JSValue<'a>>
pub fn as_string(&self) -> Result<JSString, JSValue<'a>>
Converts a JavaScript value to string.
Returns an Err
if an exception is thrown.
Sourcepub fn as_number(&self) -> Result<f64, JSValue<'a>>
pub fn as_number(&self) -> Result<f64, JSValue<'a>>
Converts a JavaScript value to number.
Returns an Err
if an exception is thrown.
Sourcepub fn as_boolean(&self) -> bool
pub fn as_boolean(&self) -> bool
Converts a JavaScript value to boolean.
Sourcepub fn as_typed_array(&self) -> Result<JSTypedArray<'a>, JSValue<'a>>
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.