feat: building
This commit is contained in:
@@ -1,16 +1,35 @@
|
||||
use boa_engine::{Context, JsValue};
|
||||
use boa_engine::property::Attribute;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub(crate) struct EvalResult {
|
||||
data: Option<JsValue>,
|
||||
data: Option<Value>,
|
||||
error: Option<String>,
|
||||
}
|
||||
|
||||
impl EvalResult {
|
||||
fn ok(data: JsValue) -> Self {
|
||||
Self {
|
||||
data: Some(data),
|
||||
error: None,
|
||||
match data {
|
||||
JsValue::Undefined => {
|
||||
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 {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
|
||||
mod mem;
|
||||
mod engine;
|
||||
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe fn eval(ptr: *mut u8, len: usize) -> *mut u8 {
|
||||
// let eval_result = engine::inner_eval()
|
||||
unimplemented!()
|
||||
pub unsafe fn eval(ptr: *mut u8, len: usize) -> (*mut u8, usize) {
|
||||
let js = mem::read_string(ptr, len);
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user