Struct quickjs_runtime::esvalue::EsFunction
source · [−]pub struct EsFunction { /* private fields */ }
Expand description
Implementations
sourceimpl EsFunction
impl EsFunction
sourcepub fn new<R>(name: &'static str, method: R, async_function: bool) -> Self where
R: Fn(Vec<EsValueFacade>) -> Result<EsValueFacade, String> + Send + 'static,
pub fn new<R>(name: &'static str, method: R, async_function: bool) -> Self where
R: Fn(Vec<EsValueFacade>) -> Result<EsValueFacade, String> + Send + 'static,
create a new Function based on a method
sourcepub fn new_async<R, F>(name: &'static str, method: R) -> Self where
F: Future<Output = Result<EsValueFacade, String>> + Send + 'static,
R: Fn(Vec<EsValueFacade>) -> F + Send + 'static,
pub fn new_async<R, F>(name: &'static str, method: R) -> Self where
F: Future<Output = Result<EsValueFacade, String>> + Send + 'static,
R: Fn(Vec<EsValueFacade>) -> F + Send + 'static,
create a new Function based on a method
Example
use quickjs_runtime::esvalue::{EsFunction, EsValueConvertible, ES_NULL, EsValueFacade};
use quickjs_runtime::builder::QuickJsRuntimeBuilder;
use hirofa_utils::js_utils::Script;
async fn do_something(args: Vec<EsValueFacade>) -> Result<EsValueFacade, String> {
Ok(123.to_es_value_facade())
}
let func_esvf = EsFunction::new_async("my_callback", do_something).to_es_value_facade();
let rt = QuickJsRuntimeBuilder::new().build();
rt.eval_sync(Script::new("new_async.es", "this.test_func = function(cb){return cb();};")).ok().expect("func invo failed");
let func_res = rt.call_function_sync(vec![], "test_func", vec![func_esvf]).ok().expect("func invo failed2");
let ret = func_res.get_promise_result_sync().ok().expect("do_something returned err");
assert_eq!(ret.get_i32(), 123);
Trait Implementations
sourceimpl EsValueConvertible for EsFunction
impl EsValueConvertible for EsFunction
fn as_js_value(
&mut self,
q_ctx: &QuickJsRealmAdapter
) -> Result<JSValueRef, JsError>
fn to_es_value_facade(self) -> EsValueFacade where
Self: Sized + Send + 'static,
fn is_null(&self) -> bool
fn is_undefined(&self) -> bool
fn is_bool(&self) -> bool
fn get_bool(&self) -> bool
fn is_str(&self) -> bool
fn get_str(&self) -> &str
fn is_i32(&self) -> bool
fn get_i32(&self) -> i32
fn is_f64(&self) -> bool
fn get_f64(&self) -> f64
fn is_function(&self) -> bool
fn invoke_function_sync(
&self,
_args: Vec<EsValueFacade>
) -> Result<EsValueFacade, JsError>
fn invoke_function(
&self,
_args: Vec<EsValueFacade>
) -> EsValueFacadeFuture<EsValueFacade, JsError>
fn invoke_function_batch_sync(
&self,
_args: Vec<Vec<EsValueFacade>>
) -> Vec<Result<EsValueFacade, JsError>>
fn invoke_function_batch(
&self,
_args: Vec<Vec<EsValueFacade>>
) -> Result<(), JsError>
fn is_promise(&self) -> bool
fn get_promise_result_sync(&self) -> Result<EsValueFacade, EsValueFacade>
fn get_promise_result(
&self
) -> EsValueFacadeFuture<EsValueFacade, EsValueFacade>
fn add_promise_reactions(
&self,
_then: PromiseReactionType,
_catch: PromiseReactionType,
_finally: Option<Box<dyn Fn() + Send + 'static>>
) -> Result<(), JsError>
fn is_object(&self) -> bool
fn get_object(&self) -> Result<HashMap<String, EsValueFacade>, JsError>
fn is_array(&self) -> bool
fn get_array(&self) -> Result<Vec<EsValueFacade>, JsError>
fn supports_stringify(&self) -> bool
fn stringify(&self) -> Result<String, JsError>
fn is_error(&self) -> bool
fn get_error(&self) -> JsError
Auto Trait Implementations
impl RefUnwindSafe for EsFunction
impl Send for EsFunction
impl Sync for EsFunction
impl Unpin for EsFunction
impl UnwindSafe for EsFunction
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