Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/sh

target=$(rustc -vV | awk '/^host/ { print $2 }' | tr '[:lower:]' '[:upper:]' | tr '-' '_')
export CARGO_TARGET_${target}_RUSTFLAGS='-D warnings'

if ! command -v cargo-make >/dev/null 2>&1; then
echo "cargo-make is not installed. Install it with:"
echo " cargo install cargo-make"
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

21 changes: 20 additions & 1 deletion cli/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub(crate) struct Executor {
async_jobs: RefCell<VecDeque<NativeAsyncJob>>,
timeout_jobs: RefCell<BTreeMap<JsInstant, Vec<TimeoutJob>>>,
generic_jobs: RefCell<VecDeque<GenericJob>>,
finalization_registry_jobs: RefCell<VecDeque<NativeAsyncJob>>,

printer: SharedExternalPrinterLogger,
}
Expand All @@ -31,6 +32,7 @@ impl Executor {
async_jobs: RefCell::default(),
timeout_jobs: RefCell::default(),
generic_jobs: RefCell::default(),
finalization_registry_jobs: RefCell::default(),
printer,
}
}
Expand Down Expand Up @@ -96,6 +98,9 @@ impl JobExecutor for Executor {
.push(job);
}
Job::GenericJob(job) => self.generic_jobs.borrow_mut().push_back(job),
Job::FinalizationRegistryCleanupJob(job) => {
self.finalization_registry_jobs.borrow_mut().push_back(job);
}
job => self.printer.print(format!("unsupported job type {job:?}")),
}
}
Expand All @@ -106,12 +111,17 @@ impl JobExecutor for Executor {

async fn run_jobs_async(self: Rc<Self>, context: &RefCell<&mut Context>) -> JsResult<()> {
let mut group = FutureGroup::new();
let mut fr_group = FutureGroup::new();

loop {
for job in mem::take(&mut *self.async_jobs.borrow_mut()) {
group.insert(job.call(context));
}

for job in mem::take(&mut *self.finalization_registry_jobs.borrow_mut()) {
fr_group.insert(job.call(context));
}

if let Some(Err(e)) = future::poll_once(group.next()).await.flatten() {
self.printer.print(uncaught_job_error(&e));
}
Expand All @@ -120,7 +130,16 @@ impl JobExecutor for Executor {
// event loop is cancelled almost immediately after the channel with
// the reader gets closed.
if self.is_empty() && group.is_empty() {
return Ok(());
// Run finalizers with a lower priority than every other type of
// job.
if let Some(Err(e)) = future::poll_once(fr_group.next()).await.flatten() {
self.printer.print(uncaught_job_error(&e));
}

// Finalizers could enqueue new jobs, so we cannot just exit.
if self.is_empty() {
return Ok(());
}
}

{
Expand Down
7 changes: 2 additions & 5 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::logger::SharedExternalPrinterLogger;
use async_channel::Sender;
use boa_engine::JsValue;
use boa_engine::error::JsErasedError;
use boa_engine::job::{JobExecutor, NativeAsyncJob};
use boa_engine::job::NativeAsyncJob;
use boa_engine::{
Context, JsError, Source,
builtins::promise::PromiseState,
Expand All @@ -35,9 +35,7 @@ use color_eyre::{
};
use colored::Colorize;
use debug::init_boa_debug_object;
use futures_lite::future;
use rustyline::{EditMode, Editor, config::Config, error::ReadlineError};
use std::cell::RefCell;
use std::time::{Duration, Instant};
use std::{
fs::OpenOptions,
Expand Down Expand Up @@ -671,8 +669,7 @@ fn main() -> Result<()> {
});
context.enqueue_job(eval_loop.into());

let result = future::block_on(executor.run_jobs_async(&RefCell::new(context)))
.map_err(|e| e.into_erased(context));
let result = context.run_jobs().map_err(|e| e.into_erased(context));

handle.join().expect("failed to join thread");

Expand Down
1 change: 1 addition & 0 deletions core/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ aligned-vec.workspace = true
dynify = { workspace = true, features = ["macros"] }
futures-concurrency.workspace = true
oneshot = { workspace = true, features = ["async"] }
async-channel.workspace = true

# intl deps
boa_icu_provider = { workspace = true, features = ["std"], optional = true }
Expand Down
Loading
Loading