GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — src: make sure pass the `argv` to worker threads · nodejs/node@21776a3

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • node_worker.cc
  • test/parallel
    • test-worker-cli-options.js
Expand file treeCollapse file tree
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
@@ -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 =
Collapse file

‎test/parallel/test-worker-cli-options.js‎

Copy file name to clipboard
+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)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.