From 3980026708589eb896c016f899fc81adcb968f2a Mon Sep 17 00:00:00 2001 From: Yael Hermon Date: Fri, 4 Jan 2019 20:02:25 +0200 Subject: [PATCH 1/3] worker: enable passing command line flags This PR adds the ability to provide Workers with their own execArgv flags in replacement of the main thread's execArgv. Only per-Isolate/per-Environment options are allowed. Per-Process options and V8 flags are not allowed. Passing an empty execArgv array will reset per-Isolate and per-Environment options of the Worker to their defaults. If execArgv option is not passed, the Worker will get the same flags as the main thread. Usage example: ``` const worker = new Worker(__filename, { execArgv: ['--trace-warnings'], }); ``` --- doc/api/errors.md | 6 ++ doc/api/worker_threads.md | 7 +- lib/internal/errors.js | 3 + lib/internal/validators.js | 8 ++- lib/internal/worker.js | 12 +++- src/env-inl.h | 5 ++ src/env.h | 1 + src/node_worker.cc | 72 +++++++++++++++++-- src/node_worker.h | 5 +- test/parallel/test-internal-errors.js | 10 +++ test/parallel/test-worker-execargv-invalid.js | 35 +++++++++ test/parallel/test-worker-execargv.js | 22 ++++++ 12 files changed, 171 insertions(+), 15 deletions(-) create mode 100644 test/parallel/test-worker-execargv-invalid.js create mode 100644 test/parallel/test-worker-execargv.js diff --git a/doc/api/errors.md b/doc/api/errors.md index 610060a15106cd..3fb129fd85a6c0 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -1869,6 +1869,12 @@ The fulfilled value of a linking promise is not a `vm.SourceTextModule` object. The current module's status does not allow for this operation. The specific meaning of the error depends on the specific function. + +### ERR_WORKER_INVALID_EXEC_ARGV + +The `execArgv` option passed to the `Worker` constructor contains +invalid flags. + ### ERR_WORKER_PATH diff --git a/doc/api/worker_threads.md b/doc/api/worker_threads.md index 78f35412c32a65..c8d55992be5004 100644 --- a/doc/api/worker_threads.md +++ b/doc/api/worker_threads.md @@ -316,13 +316,14 @@ if (isMainThread) { occur as described in the [HTML structured clone algorithm][], and an error will be thrown if the object cannot be cloned (e.g. because it contains `function`s). - * stdin {boolean} If this is set to `true`, then `worker.stdin` will + * `stdin` {boolean} If this is set to `true`, then `worker.stdin` will provide a writable stream whose contents will appear as `process.stdin` inside the Worker. By default, no data is provided. - * stdout {boolean} If this is set to `true`, then `worker.stdout` will + * `stdout` {boolean} If this is set to `true`, then `worker.stdout` will not automatically be piped through to `process.stdout` in the parent. - * stderr {boolean} If this is set to `true`, then `worker.stderr` will + * `stderr` {boolean} If this is set to `true`, then `worker.stderr` will not automatically be piped through to `process.stderr` in the parent. + * `execArgv` {string[]} List of node CLI options passed to the worker. ### Event: 'error'