use boa::{parse, Executable, Interpreter, Realm}; use wasm_bindgen::prelude::*; #[wasm_bindgen] pub fn evaluate(src: &str) -> Result { // Setup executor let realm = Realm::create(); let mut engine = Interpreter::new(realm); let expr = match parse(src) { Ok(res) => res, Err(e) => { return Err(format!( "Uncaught {}", engine .throw_syntax_error(e.to_string()) .expect_err("interpreter.throw_syntax_error() did not return an error") .display() ) .into()); } }; expr.run(&mut engine) .map_err(|e| JsValue::from(format!("Uncaught {}", e.display()))) .map(|v| v.display().to_string()) }