Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ace65a9

Browse filesBrowse 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 d71e161 commit ace65a9
Copy full SHA for ace65a9

File tree

Expand file treeCollapse file tree

2 files changed

+37
-18
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+37
-18
lines changed
Open diff view settings
Collapse file

‎src/node_worker.cc‎

Copy file name to clipboardExpand all lines: src/node_worker.cc
+21-18Lines 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 =
Collapse file
+16Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.