feat: update boa_engine

This commit is contained in:
2022-12-31 00:01:47 +08:00
parent 2a3d63d1e8
commit a0359637e2
3 changed files with 455 additions and 92 deletions

View File

@@ -1,22 +1,28 @@
use boa::{Context, Result, Value};
use boa_engine::{Context, JsResult, JsValue};
use boa_engine::property::Attribute;
fn main() {
let mut context = Context::new();
context.register_global_function("print", 0, print).unwrap();
let mut context = Context::default();
// context.set_trace(true);
context.register_global_property("MY_PROJECT_VERSION", "1.0.0", Attribute::all());
context.register_global_function("print", 0, print);
let script = r##"
function helloworld() {
console.log('hello world');
console.log('hello world', MY_PROJECT_VERSION);
print(1, 2, 3);
}
helloworld();
for (var i = 0; i < 10; i++) {}
// while(true) {}
"hello world!!!"
"##;
let v = context.eval(script).expect("Eval failed!");
println!("{:?}", v);
match context.eval(script) {
Ok(res) => println!("{}", res.to_string(&mut context).unwrap()),
Err(e) => eprintln!("Uncaught {}", e.display()),
};
}
fn print(_: &Value, args: &[Value], _: &mut Context) -> Result<Value> {
fn print(_this: &JsValue, args: &[JsValue], _context: &mut Context) -> JsResult<JsValue> {
println!("[PRINT] {:?}", args);
Ok(Value::Undefined)
Ok(JsValue::Undefined)
}