Skip to content

feat(runtime): expand process extension with platform, arch, argv, chdir, exit, and env Proxy - #5694

Open
kernelcraft2099 wants to merge 2 commits into
boa-dev:mainfrom
kernelcraft2099:feat/process-apis
Open

kernelcraft2099 wants to merge 2 commits into
boa-dev:mainfrom
kernelcraft2099:feat/process-apis

Conversation

@kernelcraft2099

@kernelcraft2099 kernelcraft2099 commented Nov 26, 2026 •

Copy link
Copy Markdown

This Pull Request fixes/closes #5692.

It changes the following:

Summary

Expands Boa's process runtime extension (boa_runtime::process) to provide essential Node.js-compatible process APIs, allowing JavaScript scripts and CLI tools to inspect the host environment, manage the working directory, read arguments, and terminate execution.

Closes #5692

Changes

  • ProcessProvider & StdProcessProvider (core/runtime/src/process/mod.rs):
    • Added platform() mapping std::env::consts::OS to Node.js platform identifiers (win32, darwin, linux, etc.).
    • Added arch() mapping std::env::consts::ARCH to Node.js architecture names (x64, ia32, arm64, etc.).
    • Added argv() exposing std::env::args() as a JsArray.
    • Added chdir(dir) using std::env::set_current_dir with JsNativeError::typ error propagation.
    • Added exit(code) delegating to std::process::exit(code) (defaulting to 0 when omitted or undefined).
    • Added set_env and remove_env trait hooks on ProcessProvider.
  • process.env Proxy wrapper:
    • Wrapped process.env in a JsProxy (create_env_proxy) with set and deleteProperty traps so property assignments and deletions behave cleanly on the environment object.
  • Tests (core/runtime/src/process/tests.rs):
    • Added unit tests covering platform, arch, argv, cwd, chdir, exit, and env mutations using a mock ProcessProvider.

Verification

  • cargo test -p boa_runtime --features process
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo fmt -- --check

Notes for Reviewers

  • Currently, process.env traps update the underlying JS target object. Let me know if you would also like set_trap and delete_trap to forward mutations through ProcessProvider::set_env / remove_env to mutate host process environment variables directly.

@kernelcraft2099
kernelcraft2099 requested a review from a team as a code owner November 26, 2026 10:28
@github-actions github-actions Bot added C-Tests Issues and PRs related to the tests. C-Runtime Issues and PRs related to Boa's runtime features Waiting On Review Waiting on reviews from the maintainers labels Nov 26, 2026
@github-actions github-actions Bot added this to the v0.23 milestone Nov 26, 2026
/// Get environment variables so as to allow env property (`process.env`)
fn env(&self) -> impl IntoIterator<Item = (JsString, JsString)>;
fn env(&self) -> impl IntoIterator<Item = (JsString, JsString)> {
std::env::vars().map(|(k, v)| (js_string!(k), js_string!(v)))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think you need put the implement in the impl block of StdProcessProvider.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

StdProcessProvider methods were moved into impl ProcessProvider for StdProcessProvider and the cwd change was reverted in 7e1cc0c

"aix" => "aix",
other => other,
};
js_string!(platform)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe move it into the impl block of StdProcessProvider is a better idea?

"mips64" => "mipsel",
other => other,
};
js_string!(arch)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

How about moving it into the impl block of StdProcessProvider?


/// Get command-line arguments (`process.argv`)
fn argv(&self) -> impl IntoIterator<Item = JsString> {
std::env::args().map(|arg| js_string!(arg))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same.

/// # Errors
/// Returns an error if the environment variable cannot be set.
fn set_env(&self, key: &JsString, value: &JsString) -> JsResult<()> {
// SAFETY: Single-threaded JS context execution in default StdProcessProvider

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same.

Comment thread core/runtime/src/process/mod.rs Outdated
let path = std::env::current_dir().map_err(|e| {
JsNativeError::typ()
.with_message(format!("Failed to get current working directory: {e}"))
})?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why we need to change this?

@PeterlitsZo

Copy link
Copy Markdown

Could you please update your message to have a better format?


截屏2026-11-27 16 08 33

You can add a newline here.


截屏2026-11-27 16 08 53

You can just use #5692.


截屏2026-11-27 16 09 26

You can remove those empty items.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-Runtime Issues and PRs related to Boa's runtime features C-Tests Issues and PRs related to the tests. Waiting On Review Waiting on reviews from the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expand ProcessExtension with essential process APIs

2 participants