Skip to content

Commit ae4f4b9

Browse files
committed
src: make sure pass the cli_options to worker
1 parent 4e9ce7c commit ae4f4b9

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

src/node_worker.cc

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -569,26 +569,30 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) {
569569
}
570570
}
571571
#endif // NODE_WITHOUT_NODE_OPTIONS
572-
}
573572

574-
if (args[2]->IsArray()) {
575-
Local<Array> array = args[2].As<Array>();
576573
// The first argument is reserved for program name, but we don't need it
577574
// in workers.
578575
std::vector<std::string> exec_argv = {""};
579-
uint32_t length = array->Length();
580-
for (uint32_t i = 0; i < length; i++) {
581-
Local<Value> arg;
582-
if (!array->Get(env->context(), i).ToLocal(&arg)) {
583-
return;
584-
}
585-
Local<String> arg_v8;
586-
if (!arg->ToString(env->context()).ToLocal(&arg_v8)) {
587-
return;
576+
if (args[2]->IsArray()) {
577+
Local<Array> array = args[2].As<Array>();
578+
uint32_t length = array->Length();
579+
for (uint32_t i = 0; i < length; i++) {
580+
Local<Value> arg;
581+
if (!array->Get(env->context(), i).ToLocal(&arg)) {
582+
return;
583+
}
584+
Local<String> arg_v8;
585+
if (!arg->ToString(env->context()).ToLocal(&arg_v8)) {
586+
return;
587+
}
588+
Utf8Value arg_utf8_value(args.GetIsolate(), arg_v8);
589+
std::string arg_string(arg_utf8_value.out(), arg_utf8_value.length());
590+
exec_argv.push_back(arg_string);
588591
}
589-
Utf8Value arg_utf8_value(args.GetIsolate(), arg_v8);
590-
std::string arg_string(arg_utf8_value.out(), arg_utf8_value.length());
591-
exec_argv.push_back(arg_string);
592+
} else {
593+
exec_argv_out = env->exec_argv();
594+
exec_argv.insert(
595+
exec_argv.end(), exec_argv_out.begin(), exec_argv_out.end());
592596
}
593597

594598
std::vector<std::string> invalid_args{};
@@ -606,9 +610,8 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) {
606610
invalid_args.erase(invalid_args.begin());
607611
if (errors.size() > 0 || invalid_args.size() > 0) {
608612
Local<Value> error;
609-
if (!ToV8Value(env->context(),
610-
errors.size() > 0 ? errors : invalid_args)
611-
.ToLocal(&error)) {
613+
if (!ToV8Value(env->context(), errors.size() > 0 ? errors : invalid_args)
614+
.ToLocal(&error)) {
612615
return;
613616
}
614617
Local<String> key =
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Flags: --expose-internals
2+
'use strict';
3+
require('../common');
4+
const { Worker } = require('worker_threads');
5+
6+
// Test if the flags is passed to worker threads
7+
// See https://github.com/nodejs/node/issues/52825
8+
new Worker(`
9+
// If the --expose-internals flag does not pass to worker
10+
// require function will throw an error
11+
require('internal/options');
12+
`, { eval: true, env: process.env });

0 commit comments

Comments
 (0)