mirror of https://github.com/boa-dev/boa.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
793 B
26 lines
793 B
use boa::{parse, Executable, Interpreter, Realm}; |
|
use wasm_bindgen::prelude::*; |
|
|
|
#[wasm_bindgen] |
|
pub fn evaluate(src: &str) -> Result<String, JsValue> { |
|
// 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()) |
|
}
|
|
|