Skip to content

Commit

Permalink
Revert "src: make sure pass the argv to worker threads"
Browse files Browse the repository at this point in the history
This reverts commit aba4a00.
  • Loading branch information
nicolo-ribaudo committed May 16, 2024
1 parent cc4e8f2 commit e05e072
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 37 deletions.
39 changes: 18 additions & 21 deletions src/node_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -569,30 +569,26 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) {
}
}
#endif // NODE_WITHOUT_NODE_OPTIONS
}

if (args[2]->IsArray()) {
Local<Array> array = args[2].As<Array>();
// The first argument is reserved for program name, but we don't need it
// in workers.
std::vector<std::string> exec_argv = {""};
if (args[2]->IsArray()) {
Local<Array> array = args[2].As<Array>();
uint32_t length = array->Length();
for (uint32_t i = 0; i < length; i++) {
Local<Value> arg;
if (!array->Get(env->context(), i).ToLocal(&arg)) {
return;
}
Local<String> 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<Value> 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<String> 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<std::string> invalid_args{};
Expand All @@ -610,8 +606,9 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) {
invalid_args.erase(invalid_args.begin());
if (errors.size() > 0 || invalid_args.size() > 0) {
Local<Value> 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<String> key =
Expand Down
16 changes: 0 additions & 16 deletions test/parallel/test-worker-cli-options.js

This file was deleted.

0 comments on commit e05e072

Please sign in to comment.