feat: rm run_js
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
mod qjs;
|
||||
mod sig;
|
||||
|
||||
@@ -9,9 +7,6 @@ pub use sig::*; // TODO
|
||||
fn main() {
|
||||
let context = QuickJSContext::new().unwrap();
|
||||
|
||||
let mut map = HashMap::new();
|
||||
map.insert("name", "hatter");
|
||||
|
||||
let script = r##"
|
||||
function __EXPORT(f) { eval('__PUBLIC_' + f + '=' + f); }
|
||||
|
||||
@@ -36,8 +31,10 @@ fn main() {
|
||||
"##;
|
||||
|
||||
context.init(script).unwrap();
|
||||
let r = context.run_js(&map);
|
||||
println!("{:?}", r);
|
||||
// let mut map = HashMap::new();
|
||||
// map.insert("name", "hatter");
|
||||
// let r = context.run_js(&map);
|
||||
// println!("{:?}", r);
|
||||
let r = context.call_fn("getName", "[1, 'hatter', 'jiang']");
|
||||
println!("{:?}", r);
|
||||
let r = context.call_fn("helloAb", "['hatter', 'jiang']");
|
||||
|
||||
@@ -20,13 +20,13 @@ impl QuickJSContext {
|
||||
self.context.eval(js).map_err(|e| e.into())
|
||||
}
|
||||
|
||||
pub fn run_js<T>(&self, p: &T) -> XResult<JsValue> where T: ?Sized + Serialize {
|
||||
let p_json = match serde_json::to_string(p) {
|
||||
Err(e) => return Err(e.into()),
|
||||
Ok(p) => p,
|
||||
};
|
||||
self.context.eval(&format!("main({})", p_json)).map_err(|e| e.into())
|
||||
}
|
||||
// pub fn run_js<T>(&self, p: &T) -> XResult<JsValue> where T: ?Sized + Serialize {
|
||||
// let p_json = match serde_json::to_string(p) {
|
||||
// Err(e) => return Err(e.into()),
|
||||
// Ok(p) => p,
|
||||
// };
|
||||
// self.context.eval(&format!("main({})", p_json)).map_err(|e| e.into())
|
||||
// }
|
||||
|
||||
pub fn call_fn(&self, fun: &str, params: &str) -> XResult<JsValue> {
|
||||
if !params.trim().starts_with("[") {
|
||||
|
||||
Reference in New Issue
Block a user