Skip to content

Various quality of life improvements to the CLI#4414

Merged
hansl merged 2 commits intoboa-dev:mainfrom
hansl:cli-expr
Sep 9, 2025
Merged

Various quality of life improvements to the CLI#4414
hansl merged 2 commits intoboa-dev:mainfrom
hansl:cli-expr

Conversation

@hansl
Copy link
Contributor

@hansl hansl commented Sep 8, 2025

Allow an expression to be passed from the arguments (using -e). This makes it easier to just run a single expression and returning.

Additionally, if the value returned by a file is undefined, don't show it. It gets confusing to see a list of "undefined" on the command line when running a bunch of modules in batch.

Another change is merging the error printing code so the output is more consistent. As well, I added distinction between an error thrown from a statement versus from a job, so the user can see where it's coming from.

Added support for timeout and generic jobs in the CLI. Now we can use setTimeout or any generic jobs. The CLI will always wait for all jobs to be completed before exiting, which makes setInterval a bit awkward if it has no end conditin.

Finally, fixed a bug in setTimeout where errors were not propagated properly.

Allow an expression to be passed from the arguments (using -e). This
makes it easier to just run a single expression and returning.

Additionally, if the value returned by a _file_ is undefined, don't
show it. It gets confusing to see a list of "undefined" on the command
line when running a bunch of modules in batch.

Another change is merging the error printing code so the output is
more consistent. As well, I added distinction between an error thrown
from a statement versus from a job, so the user can see where it's
coming from.

Added support for timeout and generic jobs in the CLI. Now we can use
setTimeout or any generic jobs. The CLI will always wait for all jobs
to be completed before exiting, which makes setInterval a bit awkward
if it has no end conditin.

Finally, fixed a bug in setTimeout where errors were not propagated
properly.
@hansl hansl requested a review from a team September 8, 2025 18:50
@codecov
Copy link

codecov bot commented Sep 8, 2025

Codecov Report

❌ Patch coverage is 1.42857% with 69 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.69%. Comparing base (6ddc2b4) to head (c4d5b77).
⚠️ Report is 523 commits behind head on main.

Files with missing lines Patch % Lines
cli/src/main.rs 0.00% 69 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4414      +/-   ##
==========================================
+ Coverage   47.24%   50.69%   +3.44%     
==========================================
  Files         476      501      +25     
  Lines       46892    51236    +4344     
==========================================
+ Hits        22154    25973    +3819     
- Misses      24738    25263     +525     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

cli/src/main.rs Outdated
Comment on lines +516 to +519
self.promise_jobs.borrow().is_empty()
&& self.async_jobs.borrow().is_empty()
&& self.timeout_jobs.borrow().is_empty()
&& self.generic_jobs.borrow().is_empty()
Copy link
Member

@jedel1043 jedel1043 Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for our current usage of the context since we don't use multiple contexts, but if we decide to add web workers in the future, it will break. Not calling context.has_pending_context_jobs() and context.enqueue_resolved_context_jobs() will completely skip resolving calls to Atomics.notify.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm about to add workers but they will use a separate Context, not just a new Realm. That's the only way to make them multi-threaded.

I'll add the context stuff, but I'm curious why aren't those already enqueued?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like those could be AsyncJobs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add the context stuff, but I'm curious why aren't those already enqueued?

Because having the context itself enqueue its own pending notify jobs was the simpler way to enable multi-threaded job enqueuing. The alternative was to modify the API for JobExecutor to take an Arc, but we would have to deal with Rust's strict semantics on non-Send, non-Sync jobs, and implementors of JobExecutor would need to use RwLock or some other multi-threaded state to keep track of all the jobs.

Copy link
Member

@jedel1043 jedel1043 Sep 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a whole, it seemed much simpler to have a multi-threaded flag on the context to enqueue its notify jobs, and have enqueue_resolved_context_jobs check that flag to see if there are pending notify jobs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like those could be AsyncJobs

Ohhhhh! Yeah, this made me realize it is possible to use an async oneshot channel to resolve an async job that does the same, which would nicely avoid having to manually track all futex waiters in the context

@hansl hansl enabled auto-merge September 9, 2025 00:14
Copy link
Member

@jedel1043 jedel1043 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@hansl hansl added this pull request to the merge queue Sep 9, 2025
Merged via the queue into boa-dev:main with commit 44de1e6 Sep 9, 2025
16 checks passed
@hansl hansl deleted the cli-expr branch September 9, 2025 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants