Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(worker_threads) support argv and execArgv options #7962

Merged
merged 2 commits into from
Jan 3, 2024

Conversation

otgerrogla
Copy link
Contributor

@otgerrogla otgerrogla commented Jan 3, 2024

What does this PR do?

Adds support for arguments to NodeJS worker_threads and web Worker constructor options:

  • argv: set the additional arguments that worker threads see at process.argv/Bun.argv after argv[0] (executable path) and argv[1] (main script path).
  • execArgv: bun does not use it, but added for compatibility. When the option is set, workers threads see the given string array values at process.execArgv, otherwise the value of this defaults to the one of the main thread.

Also fixes a small bug where worker threads always had "bun" as 3rd arg (argv[2]). Now when argv option is not specified, threads only see argv[0] and argv[1] in process.argv.

Closes #4130

  • Documentation or TypeScript types (it's okay to leave the rest blank in this case)
  • Code changes

How did you verify your code works?

I wrote automated tests

  • I checked the lifetime of memory allocated to verify it's (1) freed and (2) only freed when it should be
  • I included a test for the new code, or an existing test covers it
  • JSValue used outside outside of the stack is either wrapped in a JSC.Strong or is JSValueProtect'ed
  • I wrote TypeScript/JavaScript tests and they pass locally (bun-debug test test-file-name.test)

@otgerrogla otgerrogla changed the title feat(worker_threads) support exec and execArgv options feat(worker_threads) support argv and execArgv options Jan 3, 2024
@Jarred-Sumner
Copy link
Collaborator

This looks great. Thank you for this. Let's let the tests run and merge if the worker tests pass

@Jarred-Sumner
Copy link
Collaborator

I made the macOS CI runners bigger to hopefully fix the CI issue

@Jarred-Sumner Jarred-Sumner merged commit 2946bac into oven-sh:main Jan 3, 2024
20 of 21 checks passed
ryoppippi pushed a commit to ryoppippi/bun that referenced this pull request Feb 1, 2024
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
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.

worker_threads.Worker missing argv and execArgv option
2 participants