diff --git a/Cargo.lock b/Cargo.lock index fa569ec..ccb9e72 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -791,7 +791,7 @@ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" [[package]] name = "phat_js" -version = "0.2.7" +version = "0.2.8" dependencies = [ "hex_fmt", "ink", diff --git a/phat_js/Cargo.toml b/phat_js/Cargo.toml index a71c489..67e1c04 100644 --- a/phat_js/Cargo.toml +++ b/phat_js/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "phat_js" -version = "0.2.7" +version = "0.2.8" edition = "2021" description = "Provide a function to call the JSDelegate in a phat contract cluster" license = "MIT" diff --git a/phat_js/lib.rs b/phat_js/lib.rs index 7dcd84a..2b53165 100755 --- a/phat_js/lib.rs +++ b/phat_js/lib.rs @@ -340,7 +340,7 @@ pub fn eval_all_with( /// let res = phat_js::eval_async_js(js_code, Vec::new()); /// assert_eq!(res, JsValue::String("42".into())); /// ``` -pub fn eval_async_js(code: JsCode, args: Vec) -> JsValue { +pub fn eval_async_code(code: JsCode, args: Vec) -> JsValue { let code_bytes = match &code { JsCode::Source(source) => source.as_bytes(), JsCode::Bytecode(bytecode) => bytecode.as_slice(), @@ -352,6 +352,13 @@ pub fn eval_async_js(code: JsCode, args: Vec) -> JsValue { pink::ext().js_eval(codes, args) } +/// Evaluate async JavaScript with SideVM QuickJS. +/// +/// Same as [`eval_async_code`], but takes a string as the JavaScript code. +pub fn eval_async_js(src: &str, args: &[String]) -> JsValue { + eval_async_code(JsCode::Source(src.into()), args.to_vec()) +} + fn polyfill_script(seed: impl AsRef<[u8]>) -> String { let seed = hex_fmt::HexFmt(seed); alloc::format!(