Struct quickjs_rusty::value::OwnedJsValue
source · pub struct OwnedJsValue { /* private fields */ }
Expand description
OwnedJsValue wraps a Javascript value owned by the QuickJs runtime.
Guarantees cleanup of resources by dropping the value from the runtime.
Implementations§
source§impl OwnedJsValue
impl OwnedJsValue
pub fn context(&self) -> *mut JSContext
sourcepub fn new(context: *mut JSContext, value: JSValue) -> Self
pub fn new(context: *mut JSContext, value: JSValue) -> Self
Create a new OwnedJsValue
from a JsValue
.
This will NOT increase the ref count of the underlying value. So
you have to manage memory yourself. Be careful when using this.
sourcepub fn own(context: *mut JSContext, value: &JSValue) -> Self
pub fn own(context: *mut JSContext, value: &JSValue) -> Self
Create a new OwnedJsValue
from a JsValue
.
This will increase the ref count of the underlying value.
pub fn tag(&self) -> JsTag
sourcepub unsafe fn as_inner(&self) -> &JSValue
pub unsafe fn as_inner(&self) -> &JSValue
Get the inner JSValue without increasing ref count.
Unsafe because the caller must ensure proper memory management.
sourcepub unsafe fn extract(self) -> JSValue
pub unsafe fn extract(self) -> JSValue
Extract the underlying JSValue.
Unsafe because the caller must ensure memory management. (eg JS_FreeValue)
sourcepub fn replace(&mut self, new: JSValue)
pub fn replace(&mut self, new: JSValue)
Replace the underlying JSValue. This will decrease the ref count of the old value but remain the ref count of the new value.
sourcepub fn is_undefined(&self) -> bool
pub fn is_undefined(&self) -> bool
Check if this value is undefined
.
sourcepub fn is_exception(&self) -> bool
pub fn is_exception(&self) -> bool
Check if this value is a Javascript exception.
sourcepub fn is_function(&self) -> bool
pub fn is_function(&self) -> bool
Check if this value is a Javascript function.
sourcepub fn is_promise(&self) -> bool
pub fn is_promise(&self) -> bool
Check if this value is a Javascript promise.
sourcepub fn is_compiled_function(&self) -> bool
pub fn is_compiled_function(&self) -> bool
Check if this value is a bytecode compiled function.
sourcepub fn to_bool(&self) -> Result<bool, ValueError>
pub fn to_bool(&self) -> Result<bool, ValueError>
Convert this value into a bool
sourcepub fn to_int(&self) -> Result<i32, ValueError>
pub fn to_int(&self) -> Result<i32, ValueError>
Convert this value into an i32
sourcepub fn to_float(&self) -> Result<f64, ValueError>
pub fn to_float(&self) -> Result<f64, ValueError>
Convert this value into an f64
sourcepub fn to_string(&self) -> Result<String, ValueError>
pub fn to_string(&self) -> Result<String, ValueError>
Convert this value into a string
pub fn to_array(&self) -> Result<OwnedJsArray, ValueError>
sourcepub fn try_into_object(self) -> Result<OwnedJsObject, ValueError>
pub fn try_into_object(self) -> Result<OwnedJsObject, ValueError>
Try convert this value into a object
pub fn to_date(&self) -> Result<DateTime<Utc>, ValueError>
pub fn to_bigint(&self) -> Result<BigInt, ValueError>
sourcepub fn try_into_function(self) -> Result<JsFunction, ValueError>
pub fn try_into_function(self) -> Result<JsFunction, ValueError>
Try convert this value into a function
sourcepub fn try_into_promise(self) -> Result<OwnedJsPromise, ValueError>
pub fn try_into_promise(self) -> Result<OwnedJsPromise, ValueError>
Try convert this value into a function
sourcepub fn try_into_compiled_function(
self,
) -> Result<JsCompiledFunction, ValueError>
pub fn try_into_compiled_function( self, ) -> Result<JsCompiledFunction, ValueError>
Try convert this value into a compiled function
sourcepub fn try_into_module(self) -> Result<JsModule, ValueError>
pub fn try_into_module(self) -> Result<JsModule, ValueError>
Try convert this value into a module
sourcepub fn js_to_string(&self) -> Result<String, ExecutionError>
pub fn js_to_string(&self) -> Result<String, ExecutionError>
Call the Javascript .toString()
method on this value.
sourcepub fn to_json_string(&self, space: u8) -> Result<String, ExecutionError>
pub fn to_json_string(&self, space: u8) -> Result<String, ExecutionError>
Call the Javascript JSON.stringify()
method on this value.
Trait Implementations§
source§impl Clone for OwnedJsValue
impl Clone for OwnedJsValue
source§impl Debug for OwnedJsValue
impl Debug for OwnedJsValue
source§impl Drop for OwnedJsValue
impl Drop for OwnedJsValue
source§impl<T> From<(*mut JSContext, T)> for OwnedJsValuewhere
T: ToOwnedJsValue,
impl<T> From<(*mut JSContext, T)> for OwnedJsValuewhere
T: ToOwnedJsValue,
source§impl PartialEq for OwnedJsValue
impl PartialEq for OwnedJsValue
source§impl ToOwnedJsValue for OwnedJsValue
impl ToOwnedJsValue for OwnedJsValue
for some cases like HashMap<String, OwnedJsValue>
source§impl TryFrom<OwnedJsValue> for BigInt
impl TryFrom<OwnedJsValue> for BigInt
§type Error = ValueError
type Error = ValueError
source§impl TryFrom<OwnedJsValue> for BigInt
impl TryFrom<OwnedJsValue> for BigInt
§type Error = ValueError
type Error = ValueError
source§impl TryFrom<OwnedJsValue> for DateTime<Utc>
impl TryFrom<OwnedJsValue> for DateTime<Utc>
§type Error = ValueError
type Error = ValueError
source§impl<K: From<String> + PartialEq + Eq + Hash, V: TryFrom<OwnedJsValue, Error = ValueError>> TryFrom<OwnedJsValue> for HashMap<K, V>
impl<K: From<String> + PartialEq + Eq + Hash, V: TryFrom<OwnedJsValue, Error = ValueError>> TryFrom<OwnedJsValue> for HashMap<K, V>
§type Error = ValueError
type Error = ValueError
source§impl TryFrom<OwnedJsValue> for JsCompiledFunction
impl TryFrom<OwnedJsValue> for JsCompiledFunction
§type Error = ValueError
type Error = ValueError
source§impl TryFrom<OwnedJsValue> for JsFunction
impl TryFrom<OwnedJsValue> for JsFunction
§type Error = ValueError
type Error = ValueError
source§impl TryFrom<OwnedJsValue> for JsModule
impl TryFrom<OwnedJsValue> for JsModule
§type Error = ValueError
type Error = ValueError
source§impl TryFrom<OwnedJsValue> for OwnedJsArray
impl TryFrom<OwnedJsValue> for OwnedJsArray
§type Error = ValueError
type Error = ValueError
source§impl TryFrom<OwnedJsValue> for OwnedJsObject
impl TryFrom<OwnedJsValue> for OwnedJsObject
§type Error = ValueError
type Error = ValueError
source§impl TryFrom<OwnedJsValue> for OwnedJsPromise
impl TryFrom<OwnedJsValue> for OwnedJsPromise
§type Error = ValueError
type Error = ValueError
source§impl TryFrom<OwnedJsValue> for String
impl TryFrom<OwnedJsValue> for String
§type Error = ValueError
type Error = ValueError
source§impl<T: TryFrom<OwnedJsValue, Error = ValueError>> TryFrom<OwnedJsValue> for Vec<T>
impl<T: TryFrom<OwnedJsValue, Error = ValueError>> TryFrom<OwnedJsValue> for Vec<T>
§type Error = ValueError
type Error = ValueError
source§impl TryFrom<OwnedJsValue> for bool
impl TryFrom<OwnedJsValue> for bool
§type Error = ValueError
type Error = ValueError
source§impl TryFrom<OwnedJsValue> for f64
impl TryFrom<OwnedJsValue> for f64
§type Error = ValueError
type Error = ValueError
source§impl TryFrom<OwnedJsValue> for i128
impl TryFrom<OwnedJsValue> for i128
§type Error = ValueError
type Error = ValueError
source§impl TryFrom<OwnedJsValue> for i32
impl TryFrom<OwnedJsValue> for i32
§type Error = ValueError
type Error = ValueError
source§impl TryFrom<OwnedJsValue> for i64
impl TryFrom<OwnedJsValue> for i64
§type Error = ValueError
type Error = ValueError
source§impl TryFrom<OwnedJsValue> for u128
impl TryFrom<OwnedJsValue> for u128
§type Error = ValueError
type Error = ValueError
source§impl TryFrom<OwnedJsValue> for u64
impl TryFrom<OwnedJsValue> for u64
§type Error = ValueError
type Error = ValueError
impl Send for OwnedJsValue
impl Sync for OwnedJsValue
Auto Trait Implementations§
impl Freeze for OwnedJsValue
impl RefUnwindSafe for OwnedJsValue
impl Unpin for OwnedJsValue
impl UnwindSafe for OwnedJsValue
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)