Struct quickjs_runtime::esvalue::EsValueFacade
source · [−]pub struct EsValueFacade { /* private fields */ }
Implementations
sourceimpl EsValueFacade
impl EsValueFacade
sourcepub fn as_js_value(
&mut self,
q_ctx: &QuickJsRealmAdapter
) -> Result<JSValueRef, JsError>
pub fn as_js_value(
&mut self,
q_ctx: &QuickJsRealmAdapter
) -> Result<JSValueRef, JsError>
convert the value to a JSValueRef
sourcepub fn from_jsval(
q_ctx: &QuickJsRealmAdapter,
value_ref: &JSValueRef
) -> Result<Self, JsError>
pub fn from_jsval(
q_ctx: &QuickJsRealmAdapter,
value_ref: &JSValueRef
) -> Result<Self, JsError>
convert a JSValueRef to an EsValueFacade
sourcepub fn get_boolean(&self) -> bool
pub fn get_boolean(&self) -> bool
get the boolean value
sourcepub fn get_object(&self) -> Result<HashMap<String, EsValueFacade>, JsError>
pub fn get_object(&self) -> Result<HashMap<String, EsValueFacade>, JsError>
get the object value
sourcepub fn is_boolean(&self) -> bool
pub fn is_boolean(&self) -> bool
check if the value is a bool
sourcepub fn is_promise(&self) -> bool
pub fn is_promise(&self) -> bool
check if the value is a Promise
sourcepub fn is_function(&self) -> bool
pub fn is_function(&self) -> bool
check if the value is an function
sourcepub fn is_undefined(&self) -> bool
pub fn is_undefined(&self) -> bool
check if the value is undefined
sourcepub fn invoke_function_sync(
&self,
arguments: Vec<EsValueFacade>
) -> Result<EsValueFacade, JsError>
pub fn invoke_function_sync(
&self,
arguments: Vec<EsValueFacade>
) -> Result<EsValueFacade, JsError>
invoke the Function represented by this EsValueFacade
sourcepub async fn invoke_function(
&self,
arguments: Vec<EsValueFacade>
) -> Result<EsValueFacade, JsError>
pub async fn invoke_function(
&self,
arguments: Vec<EsValueFacade>
) -> Result<EsValueFacade, JsError>
invoke the Function represented by this EsValueFacade
sourcepub fn invoke_function_batch_sync(
&self,
arguments: Vec<Vec<EsValueFacade>>
) -> Vec<Result<EsValueFacade, JsError>>
pub fn invoke_function_batch_sync(
&self,
arguments: Vec<Vec<EsValueFacade>>
) -> Vec<Result<EsValueFacade, JsError>>
invoke a function multiple times with a different set of arguments
sourcepub fn invoke_function_batch(
&self,
arguments: Vec<Vec<EsValueFacade>>
) -> Result<(), JsError>
pub fn invoke_function_batch(
&self,
arguments: Vec<Vec<EsValueFacade>>
) -> Result<(), JsError>
invoke a function multiple times with a different set of arguments
sourcepub fn get_promise_result_sync(&self) -> Result<EsValueFacade, EsValueFacade>
pub fn get_promise_result_sync(&self) -> Result<EsValueFacade, EsValueFacade>
get the result of a Promise, this method blocks until the Promise is fulfilled. The Result will be an Ok if the Promise was resolved or an Err if the Promise was rejected
sourcepub fn get_promise_result(
&self
) -> impl Future<Output = Result<EsValueFacade, EsValueFacade>>
pub fn get_promise_result(
&self
) -> impl Future<Output = Result<EsValueFacade, EsValueFacade>>
wait for the result of a Promise async. The Result will be an Ok if the Promise was resolved or an Err if the Promise was rejected
Example
use quickjs_runtime::builder::QuickJsRuntimeBuilder;
use hirofa_utils::js_utils::Script;
use futures::executor::block_on;
use quickjs_runtime::esvalue::EsValueFacade;
pub async fn test_async(esvf: EsValueFacade) -> i32 {
let prom_res = esvf.get_promise_result().await;
let res_esvf = prom_res.ok().unwrap();
return res_esvf.get_i32();
}
let rt = QuickJsRuntimeBuilder::new().build();
let esvf = rt.eval_sync(Script::new("test_async_prom,es", "(new Promise((resolve, reject) => {setTimeout(() => {resolve(1360)}, 1000);}));")).ok().expect("script failed");
let i = block_on(test_async(esvf));
assert_eq!(i, 1360);
pub fn is_error(&self) -> bool
pub fn get_error(&self) -> JsError
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for EsValueFacade
impl Send for EsValueFacade
impl !Sync for EsValueFacade
impl Unpin for EsValueFacade
impl !UnwindSafe for EsValueFacade
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more