worker: allow execArgv and eval in combination
It was likely an oversight that `execArgv` was only read when no filename/URL was provided. PR-URL: https://github.com/nodejs/node/pull/26533 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
171b2707d3
commit
3ad8f61236
@ -439,14 +439,16 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) {
|
||||
std::vector<std::string> exec_argv_out;
|
||||
bool has_explicit_exec_argv = false;
|
||||
|
||||
CHECK_EQ(args.Length(), 2);
|
||||
// Argument might be a string or URL
|
||||
if (args.Length() > 0 && !args[0]->IsNullOrUndefined()) {
|
||||
if (!args[0]->IsNullOrUndefined()) {
|
||||
Utf8Value value(
|
||||
args.GetIsolate(),
|
||||
args[0]->ToString(env->context()).FromMaybe(v8::Local<v8::String>()));
|
||||
url.append(value.out(), value.length());
|
||||
}
|
||||
|
||||
if (args.Length() > 1 && args[1]->IsArray()) {
|
||||
if (args[1]->IsArray()) {
|
||||
v8::Local<v8::Array> array = args[1].As<v8::Array>();
|
||||
// The first argument is reserved for program name, but we don't need it
|
||||
// in workers.
|
||||
@ -497,7 +499,6 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!has_explicit_exec_argv)
|
||||
exec_argv_out = env->exec_argv();
|
||||
new Worker(env, args.This(), url, per_isolate_opts, std::move(exec_argv_out));
|
||||
|
@ -19,6 +19,13 @@ if (!process.env.HAS_STARTED_WORKER) {
|
||||
/Warning: some warning[\s\S]*at Object\.<anonymous>/.test(error)
|
||||
);
|
||||
}));
|
||||
|
||||
new Worker(
|
||||
"require('worker_threads').parentPort.postMessage(process.execArgv)",
|
||||
{ eval: true, execArgv: ['--trace-warnings'] })
|
||||
.on('message', common.mustCall((data) => {
|
||||
assert.deepStrictEqual(data, ['--trace-warnings']);
|
||||
}));
|
||||
} else {
|
||||
process.emitWarning('some warning');
|
||||
assert.deepStrictEqual(process.execArgv, ['--trace-warnings']);
|
||||
|
Loading…
x
Reference in New Issue
Block a user