Files
simple-rust-tests/__lang/boa/src/main.rs

29 lines
958 B
Rust

use boa_engine::{Context, JsResult, JsValue};
use boa_engine::property::Attribute;
fn main() {
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', MY_PROJECT_VERSION);
print(1, 2, 3);
}
helloworld();
for (var i = 0; i < 10; i++) {}
// while(true) {}
/(a+)+b/.test('a'.repeat(15) + 'c');
"hello world!!!"
"##;
match context.eval(script) {
Ok(res) => println!("{}", res.to_string(&mut context).unwrap()),
Err(e) => eprintln!("Uncaught {}", e.display()),
};
}
fn print(_this: &JsValue, args: &[JsValue], _context: &mut Context) -> JsResult<JsValue> {
println!("[PRINT] {:?}", args);
Ok(JsValue::Undefined)
}