feat: building

This commit is contained in:
2023-01-21 00:23:37 +08:00
parent 557b4cb21f
commit f3fda56f06
2 changed files with 28 additions and 9 deletions

View File

@@ -1,16 +1,35 @@
use boa_engine::{Context, JsValue}; use boa_engine::{Context, JsValue};
use boa_engine::property::Attribute; use boa_engine::property::Attribute;
use serde::{Deserialize, Serialize};
use serde_json::Value;
#[derive(Debug, Serialize, Deserialize)]
pub(crate) struct EvalResult { pub(crate) struct EvalResult {
data: Option<JsValue>, data: Option<Value>,
error: Option<String>, error: Option<String>,
} }
impl EvalResult { impl EvalResult {
fn ok(data: JsValue) -> Self { fn ok(data: JsValue) -> Self {
Self { match data {
data: Some(data), JsValue::Undefined => {
error: None, return Self {
data: None,
error: None,
};
}
_ => {}
}
let mut context = Context::default();
match data.to_json(&mut context) {
Err(e) => Self {
data: None,
error: Some(format!("{}", e)),
},
Ok(data_json) => Self {
data: Some(data_json),
error: None,
}
} }
} }
fn err(error: String) -> Self { fn err(error: String) -> Self {

View File

@@ -1,11 +1,11 @@
mod mem; mod mem;
mod engine; mod engine;
#[no_mangle] #[no_mangle]
pub unsafe fn eval(ptr: *mut u8, len: usize) -> *mut u8 { pub unsafe fn eval(ptr: *mut u8, len: usize) -> (*mut u8, usize) {
// let eval_result = engine::inner_eval() let js = mem::read_string(ptr, len);
unimplemented!() let eval_result = engine::inner_eval(&js);
let eval_result_json_string = serde_json::to_string(&eval_result).expect("SHOULD NOT HAPPEN");
mem::malloc_and_write_string(&eval_result_json_string)
} }