Skip to content

Add process.cwd()#4603

Open
randomboi404 wants to merge 1 commit intoboa-dev:mainfrom
randomboi404:add-process-methods
Open

Add process.cwd()#4603
randomboi404 wants to merge 1 commit intoboa-dev:mainfrom
randomboi404:add-process-methods

Conversation

@randomboi404
Copy link
Contributor

It changes the following:

  1. Uses a provider pattern so as to allow custom ProcessProvider for embedded systems where using the default StdProcessProvider will not be proper.

  2. Adds process.cwd() so as to allow:

./boa
>> process.cwd()
"/root/boa"

@github-actions
Copy link

github-actions bot commented Feb 5, 2026

Test262 conformance changes

Test result main count PR count difference
Total 52,862 52,862 0
Passed 49,471 49,471 0
Ignored 2,249 2,249 0
Failed 1,142 1,142 0
Panics 0 0 0
Conformance 93.59% 93.59% 0.00%

@codecov
Copy link

codecov bot commented Feb 5, 2026

Codecov Report

❌ Patch coverage is 0% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.54%. Comparing base (6ddc2b4) to head (14a735e).
⚠️ Report is 644 commits behind head on main.

Files with missing lines Patch % Lines
core/runtime/src/process/mod.rs 0.00% 22 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4603      +/-   ##
==========================================
+ Coverage   47.24%   56.54%   +9.29%     
==========================================
  Files         476      548      +72     
  Lines       46892    60093   +13201     
==========================================
+ Hits        22154    33977   +11823     
- Misses      24738    26116    +1378     

☔ 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.

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.

Implementation wise looks great! I just have an API suggestion and a comment on the error thrown when calling current_dir().

///
/// # Errors
/// Returns an error if the environment variables cannot be obtained.
fn env(&self) -> JsResult<HashMap<String, String>>;
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest just using impl IntoIterator<(JsString, JsString)> as the return value here, to mirror what std::env::vars() returns. IMO we really don't need a fallible method here.

impl ProcessProvider for StdProcessProvider {
fn cwd(&self) -> JsResult<JsString> {
let path = std::env::current_dir()
.map_err(|e| JsError::from_opaque(js_string!(e.to_string()).into()))?;
Copy link
Member

Choose a reason for hiding this comment

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

It's not that useful to return an opaque error here; just use TypeError and pass e.to_string() as the message for the error, maybe with a nice error prefix to show that this error comes from calling std::env::current_dir()

Copy link
Member

@jedel1043 jedel1043 Feb 6, 2026

Choose a reason for hiding this comment

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

By the way you can easily format nice error messages with our js_error macro:

js_error!(TypeError: "nice error message. source: {error}", e.to_string());

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.

2 participants