Skip to content

Commit

Permalink
phat_js: Add eval_async_code
Browse files Browse the repository at this point in the history
  • Loading branch information
kvinwang committed Dec 12, 2023
1 parent 02dc814 commit 4f2f1bc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion phat_js/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
9 changes: 8 additions & 1 deletion phat_js/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) -> JsValue {
pub fn eval_async_code(code: JsCode, args: Vec<String>) -> JsValue {
let code_bytes = match &code {
JsCode::Source(source) => source.as_bytes(),
JsCode::Bytecode(bytecode) => bytecode.as_slice(),
Expand All @@ -352,6 +352,13 @@ pub fn eval_async_js(code: JsCode, args: Vec<String>) -> 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!(
Expand Down

0 comments on commit 4f2f1bc

Please sign in to comment.