From e05e0724746b6fca404a730ee03b8bae05a3c4d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 16 May 2024 11:28:23 +0200 Subject: [PATCH] Revert "src: make sure pass the `argv` to worker threads" This reverts commit aba4a00c8d20135ad8d071991bd8bff06d4e136c. --- src/node_worker.cc | 39 +++++++++++------------- test/parallel/test-worker-cli-options.js | 16 ---------- 2 files changed, 18 insertions(+), 37 deletions(-) delete mode 100644 test/parallel/test-worker-cli-options.js diff --git a/src/node_worker.cc b/src/node_worker.cc index 14fcf72c1ec3e5..f744c6a1a97ff1 100644 --- a/src/node_worker.cc +++ b/src/node_worker.cc @@ -569,30 +569,26 @@ void Worker::New(const FunctionCallbackInfo& args) { } } #endif // NODE_WITHOUT_NODE_OPTIONS + } + if (args[2]->IsArray()) { + Local array = args[2].As(); // The first argument is reserved for program name, but we don't need it // in workers. std::vector exec_argv = {""}; - if (args[2]->IsArray()) { - Local array = args[2].As(); - uint32_t length = array->Length(); - for (uint32_t i = 0; i < length; i++) { - Local arg; - if (!array->Get(env->context(), i).ToLocal(&arg)) { - return; - } - Local arg_v8; - if (!arg->ToString(env->context()).ToLocal(&arg_v8)) { - return; - } - Utf8Value arg_utf8_value(args.GetIsolate(), arg_v8); - std::string arg_string(arg_utf8_value.out(), arg_utf8_value.length()); - exec_argv.push_back(arg_string); + uint32_t length = array->Length(); + for (uint32_t i = 0; i < length; i++) { + Local arg; + if (!array->Get(env->context(), i).ToLocal(&arg)) { + return; } - } else { - exec_argv_out = env->exec_argv(); - exec_argv.insert( - exec_argv.end(), exec_argv_out.begin(), exec_argv_out.end()); + Local arg_v8; + if (!arg->ToString(env->context()).ToLocal(&arg_v8)) { + return; + } + Utf8Value arg_utf8_value(args.GetIsolate(), arg_v8); + std::string arg_string(arg_utf8_value.out(), arg_utf8_value.length()); + exec_argv.push_back(arg_string); } std::vector invalid_args{}; @@ -610,8 +606,9 @@ void Worker::New(const FunctionCallbackInfo& args) { invalid_args.erase(invalid_args.begin()); if (errors.size() > 0 || invalid_args.size() > 0) { Local error; - if (!ToV8Value(env->context(), errors.size() > 0 ? errors : invalid_args) - .ToLocal(&error)) { + if (!ToV8Value(env->context(), + errors.size() > 0 ? errors : invalid_args) + .ToLocal(&error)) { return; } Local key = diff --git a/test/parallel/test-worker-cli-options.js b/test/parallel/test-worker-cli-options.js deleted file mode 100644 index 98682243f2d16c..00000000000000 --- a/test/parallel/test-worker-cli-options.js +++ /dev/null @@ -1,16 +0,0 @@ -// Flags: --expose-internals -'use strict'; -require('../common'); -const { Worker } = require('worker_threads'); - -const CODE = ` -// If the --expose-internals flag does not pass to worker -// require function will throw an error -require('internal/options'); -`; -// Test if the flags is passed to worker threads -// See https://github.com/nodejs/node/issues/52825 -new Worker(CODE, { eval: true }); -new Worker(CODE, { eval: true, env: process.env, execArgv: ['--expose-internals'] }); -new Worker(CODE, { eval: true, env: process.env }); -new Worker(CODE, { eval: true, execArgv: ['--expose-internals'] });