Skip to content

Commit 21776a3

Browse files
theanarkhtargos
authored andcommitted
src: make sure pass the argv to worker threads
PR-URL: #52827 Fixes: #52825 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent e2ea7b2 commit 21776a3

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed

src/node_worker.cc

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -604,26 +604,30 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) {
604604
}
605605
}
606606
#endif // NODE_WITHOUT_NODE_OPTIONS
607-
}
608607

609-
if (args[2]->IsArray()) {
610-
Local<Array> array = args[2].As<Array>();
611608
// The first argument is reserved for program name, but we don't need it
612609
// in workers.
613610
std::vector<std::string> exec_argv = {""};
614-
uint32_t length = array->Length();
615-
for (uint32_t i = 0; i < length; i++) {
616-
Local<Value> arg;
617-
if (!array->Get(env->context(), i).ToLocal(&arg)) {
618-
return;
619-
}
620-
Local<String> arg_v8;
621-
if (!arg->ToString(env->context()).ToLocal(&arg_v8)) {
622-
return;
611+
if (args[2]->IsArray()) {
612+
Local<Array> array = args[2].As<Array>();
613+
uint32_t length = array->Length();
614+
for (uint32_t i = 0; i < length; i++) {
615+
Local<Value> arg;
616+
if (!array->Get(env->context(), i).ToLocal(&arg)) {
617+
return;
618+
}
619+
Local<String> arg_v8;
620+
if (!arg->ToString(env->context()).ToLocal(&arg_v8)) {
621+
return;
622+
}
623+
Utf8Value arg_utf8_value(args.GetIsolate(), arg_v8);
624+
std::string arg_string(arg_utf8_value.out(), arg_utf8_value.length());
625+
exec_argv.push_back(arg_string);
623626
}
624-
Utf8Value arg_utf8_value(args.GetIsolate(), arg_v8);
625-
std::string arg_string(arg_utf8_value.out(), arg_utf8_value.length());
626-
exec_argv.push_back(arg_string);
627+
} else {
628+
exec_argv_out = env->exec_argv();
629+
exec_argv.insert(
630+
exec_argv.end(), exec_argv_out.begin(), exec_argv_out.end());
627631
}
628632

629633
std::vector<std::string> invalid_args{};
@@ -641,9 +645,8 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) {
641645
invalid_args.erase(invalid_args.begin());
642646
if (errors.size() > 0 || invalid_args.size() > 0) {
643647
Local<Value> error;
644-
if (!ToV8Value(env->context(),
645-
errors.size() > 0 ? errors : invalid_args)
646-
.ToLocal(&error)) {
648+
if (!ToV8Value(env->context(), errors.size() > 0 ? errors : invalid_args)
649+
.ToLocal(&error)) {
647650
return;
648651
}
649652
Local<String> key =
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Flags: --expose-internals
2+
'use strict';
3+
require('../common');
4+
const { Worker } = require('worker_threads');
5+
6+
const CODE = `
7+
// If the --expose-internals flag does not pass to worker
8+
// require function will throw an error
9+
require('internal/options');
10+
`;
11+
// Test if the flags is passed to worker threads
12+
// See https://github.com/nodejs/node/issues/52825
13+
new Worker(CODE, { eval: true });
14+
new Worker(CODE, { eval: true, env: process.env, execArgv: ['--expose-internals'] });
15+
new Worker(CODE, { eval: true, env: process.env });
16+
new Worker(CODE, { eval: true, execArgv: ['--expose-internals'] });

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy