Skip to content

Commit

Permalink
Merge branch 'main' into impl-temporal-to-string-methods
Browse files Browse the repository at this point in the history
  • Loading branch information
nekevss committed Jan 15, 2025
2 parents daccbd3 + ca86fdf commit f025a72
Show file tree
Hide file tree
Showing 28 changed files with 829 additions and 474 deletions.
64 changes: 36 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ boa_string = { version = "~0.20.0", path = "core/string" }

# Shared deps
arbitrary = "1"
bitflags = "2.5.0"
clap = "4.5.23"
bitflags = "2.7.0"
clap = "4.5.26"
colored = "2.2.0"
cow-utils = "0.1.3"
fast-float2 = "0.2.3"
hashbrown = "0.15.2"
indexmap = { version = "2.7.0", default-features = false }
Expand Down Expand Up @@ -90,7 +91,7 @@ isahc = "1.7.2"
rustyline = { version = "15.0.0", default-features = false }
dhat = "0.3.3"
quote = "1.0.38"
syn = { version = "2.0.95", default-features = false }
syn = { version = "2.0.96", default-features = false }
proc-macro2 = "1.0"
synstructure = "0.13"
measureme = "12.0.0"
Expand All @@ -101,7 +102,7 @@ rand = "0.8.5"
num-integer = "0.1.46"
ryu-js = "1.0.1"
tap = "1.0.1"
thiserror = { version = "2.0.9", default-features = false }
thiserror = { version = "2.0.11", default-features = false }
dashmap = "6.1.0"
num_enum = "0.7.3"
itertools = { version = "0.13.0", default-features = false }
Expand All @@ -116,10 +117,10 @@ temporal_rs = { git = "https://github.com/boa-dev/temporal.git", rev = "53fc1fc1
web-time = "1.1.0"
criterion = "0.5.1"
float-cmp = "0.10.0"
futures-lite = "2.5.0"
futures-lite = "2.6.0"
test-case = "3.3.1"
url = "2.5.4"
tokio = { version = "1.42.0", default-features = false }
tokio = { version = "1.43.0", default-features = false }
futures-concurrency = "7.6.2"


Expand Down
62 changes: 40 additions & 22 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ mod helper;
use boa_engine::{
builtins::promise::PromiseState,
context::ContextBuilder,
job::{FutureJob, JobQueue, NativeJob},
job::{Job, JobExecutor, NativeAsyncJob, PromiseJob},
module::{Module, SimpleModuleLoader},
optimizer::OptimizerOptions,
script::Script,
vm::flowgraph::{Direction, Graph},
Context, JsError, Source,
Context, JsError, JsResult, Source,
};
use boa_parser::source::ReadChar;
use clap::{Parser, ValueEnum, ValueHint};
Expand Down Expand Up @@ -292,7 +292,7 @@ fn evaluate_file(
);

let promise = module.load_link_evaluate(context);
context.run_jobs();
context.run_jobs().map_err(|err| err.into_erased(context))?;
let result = promise.state();

return match result {
Expand All @@ -308,9 +308,9 @@ fn evaluate_file(
Ok(v) => println!("{}", v.display()),
Err(v) => eprintln!("Uncaught {v}"),
}
context.run_jobs();

Ok(())
context
.run_jobs()
.map_err(|err| err.into_erased(context).into())
}

fn evaluate_files(args: &Opt, context: &mut Context, loader: &SimpleModuleLoader) {
Expand All @@ -336,10 +336,10 @@ fn main() -> Result<()> {

let args = Opt::parse();

let queue = Rc::new(Jobs::default());
let executor = Rc::new(Executor::default());
let loader = Rc::new(SimpleModuleLoader::new(&args.root).map_err(|e| eyre!(e.to_string()))?);
let mut context = ContextBuilder::new()
.job_queue(queue)
.job_executor(executor)
.module_loader(loader.clone())
.build()
.map_err(|e| eyre!(e.to_string()))?;
Expand Down Expand Up @@ -425,7 +425,9 @@ fn main() -> Result<()> {
eprintln!("{}: {}", "Uncaught".red(), v.to_string().red());
}
}
context.run_jobs();
if let Err(err) = context.run_jobs() {
eprintln!("{err}");
};
}
}

Expand Down Expand Up @@ -453,29 +455,45 @@ fn add_runtime(context: &mut Context) {
}

#[derive(Default)]
struct Jobs(RefCell<VecDeque<NativeJob>>);
struct Executor {
promise_jobs: RefCell<VecDeque<PromiseJob>>,
async_jobs: RefCell<VecDeque<NativeAsyncJob>>,
}

impl JobQueue for Jobs {
fn enqueue_promise_job(&self, job: NativeJob, _: &mut Context) {
self.0.borrow_mut().push_back(job);
impl JobExecutor for Executor {
fn enqueue_job(&self, job: Job, _: &mut Context) {
match job {
Job::PromiseJob(job) => self.promise_jobs.borrow_mut().push_back(job),
Job::AsyncJob(job) => self.async_jobs.borrow_mut().push_back(job),
job => eprintln!("unsupported job type {job:?}"),
}
}

fn run_jobs(&self, context: &mut Context) {
fn run_jobs(&self, context: &mut Context) -> JsResult<()> {
loop {
let jobs = std::mem::take(&mut *self.0.borrow_mut());
if jobs.is_empty() {
return;
if self.promise_jobs.borrow().is_empty() && self.async_jobs.borrow().is_empty() {
return Ok(());
}

let jobs = std::mem::take(&mut *self.promise_jobs.borrow_mut());
for job in jobs {
if let Err(e) = job.call(context) {
eprintln!("Uncaught {e}");
}
}
}
}

fn enqueue_future_job(&self, future: FutureJob, _: &mut Context) {
let job = pollster::block_on(future);
self.0.borrow_mut().push_back(job);
let async_jobs = std::mem::take(&mut *self.async_jobs.borrow_mut());
for async_job in async_jobs {
if let Err(err) = pollster::block_on(async_job.call(&RefCell::new(context))) {
eprintln!("Uncaught {err}");
}
let jobs = std::mem::take(&mut *self.promise_jobs.borrow_mut());
for job in jobs {
if let Err(e) = job.call(context) {
eprintln!("Uncaught {e}");
}
}
}
}
}
}
3 changes: 3 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
doc-valid-idents = ['ECMAScript', 'JavaScript', 'SpiderMonkey', 'GitHub']
allow-print-in-tests = true
disallowed-methods = [
{ path = "str::to_ascii_uppercase", reason = "To avoid memory allocation, use `cow_utils::CowUtils::cow_to_ascii_uppercase` instead." },
]
1 change: 1 addition & 0 deletions core/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ boa_macros.workspace = true
boa_ast.workspace = true
boa_parser.workspace = true
boa_string.workspace = true
cow-utils.workspace = true
serde = { workspace = true, features = ["derive", "rc"] }
serde_json.workspace = true
rand.workspace = true
Expand Down
Loading

0 comments on commit f025a72

Please sign in to comment.