mirror of
https://github.com/nodejs/node.git
synced 2025-05-07 15:35:41 +00:00

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'], }); ``` PR-URL: https://github.com/nodejs/node/pull/25467 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
36 lines
852 B
JavaScript
36 lines
852 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { Worker } = require('worker_threads');
|
|
|
|
{
|
|
const expectedErr = common.expectsError({
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
type: TypeError
|
|
}, 2);
|
|
|
|
assert.throws(() => {
|
|
new Worker(__filename, { execArgv: 'hello' });
|
|
}, expectedErr);
|
|
assert.throws(() => {
|
|
new Worker(__filename, { execArgv: 6 });
|
|
}, expectedErr);
|
|
}
|
|
|
|
{
|
|
const expectedErr = common.expectsError({
|
|
code: 'ERR_WORKER_INVALID_EXEC_ARGV',
|
|
type: Error
|
|
}, 3);
|
|
assert.throws(() => {
|
|
new Worker(__filename, { execArgv: ['--foo'] });
|
|
}, expectedErr);
|
|
assert.throws(() => {
|
|
new Worker(__filename, { execArgv: ['--title=blah'] });
|
|
}, expectedErr);
|
|
assert.throws(() => {
|
|
new Worker(__filename, { execArgv: ['--redirect-warnings'] });
|
|
}, expectedErr);
|
|
}
|