-
Notifications
You must be signed in to change notification settings - Fork 28.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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'], }); ``` PR-URL: #25467 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
- Loading branch information
Showing
11 changed files
with
167 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
// This test ensures that Workers have the ability to get | ||
// their own command line flags. | ||
|
||
const { Worker, isMainThread } = require('worker_threads'); | ||
const { StringDecoder } = require('string_decoder'); | ||
const decoder = new StringDecoder('utf8'); | ||
|
||
if (isMainThread) { | ||
const w = new Worker(__filename, { execArgv: ['--trace-warnings'] }); | ||
w.stderr.on('data', common.mustCall((chunk) => { | ||
const error = decoder.write(chunk); | ||
assert.ok( | ||
/Warning: some warning[\s\S]*at Object\.<anonymous>/.test(error) | ||
); | ||
})); | ||
} else { | ||
process.emitWarning('some warning'); | ||
} |