Skip to content

feat(worker_threads) support argv and execArgv options - #7962

Merged
Jarred-Sumner merged 2 commits into
oven-sh:mainfrom
otgerrogla:worker-threads
Jan 3, 2024
Merged

Jarred-Sumner merged 2 commits into
oven-sh:mainfrom
otgerrogla:worker-threads

Conversation

@otgerrogla

@otgerrogla otgerrogla commented Jan 3, 2024 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Collaborator

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

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