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.
Safety:
This type is Send
and Sync
only for convenience, since OwnedJsValue
itself is just a wrapper around a raw pointer. But any operation on the underlying raw pointer is unsafe.
Make sure using it in a same thread.
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
for some cases like HashMap<String, OwnedJsValue>
impl ToOwnedJsValue for OwnedJsValue
for some cases like HashMap<String, OwnedJsValue>