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.
37 lines
1012 B
37 lines
1012 B
#![deny(unused_qualifications, clippy::correctness, clippy::style)] |
|
#![warn(clippy::perf)] |
|
#![allow(clippy::cognitive_complexity)] |
|
|
|
use boa::{exec::Executor, forward_val, realm::Realm}; |
|
use std::{fs::read_to_string, path::PathBuf}; |
|
use structopt::StructOpt; |
|
|
|
/// CLI configuration for Boa. |
|
#[derive(Debug, StructOpt)] |
|
#[structopt(author, about)] |
|
struct Opt { |
|
/// The javascript file to be evaluated. |
|
#[structopt(name = "FILE", parse(from_os_str), default_value = "tests/js/test.js")] |
|
files: Vec<PathBuf>, |
|
/// Open a boa shell (WIP). |
|
#[structopt(short, long)] |
|
shell: bool, |
|
} |
|
|
|
pub fn main() -> Result<(), std::io::Error> { |
|
let args = Opt::from_args(); |
|
|
|
let realm = Realm::create(); |
|
let mut engine = Executor::new(realm); |
|
|
|
for file in args.files { |
|
let buffer = read_to_string(file)?; |
|
|
|
match forward_val(&mut engine, &buffer) { |
|
Ok(v) => print!("{}", v.to_string()), |
|
Err(v) => eprint!("{}", v.to_string()), |
|
} |
|
} |
|
|
|
Ok(()) |
|
}
|
|
|