worker: allow execArgv and eval in combination · nodejs/node@682b410 (original) (raw)
`@@ -400,63 +400,64 @@ void Worker::New(const FunctionCallbackInfo& args) {
`
400
400
` std::vectorstd::string exec_argv_out;
`
401
401
`bool has_explicit_exec_argv = false;
`
402
402
``
``
403
`+
CHECK_EQ(args.Length(), 2);
`
403
404
`// Argument might be a string or URL
`
404
``
`-
if (args.Length() > 0 && !args[0]->IsNullOrUndefined()) {
`
``
405
`+
if (!args[0]->IsNullOrUndefined()) {
`
405
406
` Utf8Value value(
`
406
407
` args.GetIsolate(),
`
407
408
` args[0]->ToString(env->context()).FromMaybe(v8::Localv8::String()));
`
408
409
` url.append(value.out(), value.length());
`
``
410
`+
}
`
409
411
``
410
``
`-
if (args.Length() > 1 && args[1]->IsArray()) {
`
411
``
`-
v8::Localv8::Array array = args[1].Asv8::Array();
`
412
``
`-
// The first argument is reserved for program name, but we don't need it
`
413
``
`-
// in workers.
`
414
``
`-
has_explicit_exec_argv = true;
`
415
``
`-
std::vectorstd::string exec_argv = {""};
`
416
``
`-
uint32_t length = array->Length();
`
417
``
`-
for (uint32_t i = 0; i < length; i++) {
`
418
``
`-
v8::Localv8::Value arg;
`
419
``
`-
if (!array->Get(env->context(), i).ToLocal(&arg)) {
`
420
``
`-
return;
`
421
``
`-
}
`
422
``
`-
v8::MaybeLocalv8::String arg_v8_string =
`
423
``
`-
arg->ToString(env->context());
`
424
``
`-
if (arg_v8_string.IsEmpty()) {
`
425
``
`-
return;
`
426
``
`-
}
`
427
``
`-
Utf8Value arg_utf8_value(
`
428
``
`-
args.GetIsolate(),
`
429
``
`-
arg_v8_string.FromMaybe(v8::Localv8::String()));
`
430
``
`-
std::string arg_string(arg_utf8_value.out(), arg_utf8_value.length());
`
431
``
`-
exec_argv.push_back(arg_string);
`
``
412
`+
if (args[1]->IsArray()) {
`
``
413
`+
v8::Localv8::Array array = args[1].Asv8::Array();
`
``
414
`+
// The first argument is reserved for program name, but we don't need it
`
``
415
`+
// in workers.
`
``
416
`+
has_explicit_exec_argv = true;
`
``
417
`+
std::vectorstd::string exec_argv = {""};
`
``
418
`+
uint32_t length = array->Length();
`
``
419
`+
for (uint32_t i = 0; i < length; i++) {
`
``
420
`+
v8::Localv8::Value arg;
`
``
421
`+
if (!array->Get(env->context(), i).ToLocal(&arg)) {
`
``
422
`+
return;
`
432
423
` }
`
433
``
-
434
``
`-
std::vectorstd::string invalid_args{};
`
435
``
`-
std::vectorstd::string errors{};
`
436
``
`-
per_isolate_opts.reset(new PerIsolateOptions());
`
437
``
-
438
``
`-
// Using invalid_args as the v8_args argument as it stores unknown
`
439
``
`-
// options for the per isolate parser.
`
440
``
`-
options_parser::Parse(
`
441
``
`-
&exec_argv,
`
442
``
`-
&exec_argv_out,
`
443
``
`-
&invalid_args,
`
444
``
`-
per_isolate_opts.get(),
`
445
``
`-
kDisallowedInEnvironment,
`
446
``
`-
&errors);
`
447
``
-
448
``
`-
// The first argument is program name.
`
449
``
`-
invalid_args.erase(invalid_args.begin());
`
450
``
`-
if (errors.size() > 0 || invalid_args.size() > 0) {
`
451
``
`-
v8::Localv8::Value error =
`
452
``
`-
ToV8Value(env->context(),
`
453
``
`-
errors.size() > 0 ? errors : invalid_args)
`
454
``
`-
.ToLocalChecked();
`
455
``
`-
Local key =
`
456
``
`-
FIXED_ONE_BYTE_STRING(env->isolate(), "invalidExecArgv");
`
457
``
`-
USE(args.This()->Set(env->context(), key, error).FromJust());
`
``
424
`+
v8::MaybeLocalv8::String arg_v8_string =
`
``
425
`+
arg->ToString(env->context());
`
``
426
`+
if (arg_v8_string.IsEmpty()) {
`
458
427
`return;
`
459
428
` }
`
``
429
`+
Utf8Value arg_utf8_value(
`
``
430
`+
args.GetIsolate(),
`
``
431
`+
arg_v8_string.FromMaybe(v8::Localv8::String()));
`
``
432
`+
std::string arg_string(arg_utf8_value.out(), arg_utf8_value.length());
`
``
433
`+
exec_argv.push_back(arg_string);
`
``
434
`+
}
`
``
435
+
``
436
`+
std::vectorstd::string invalid_args{};
`
``
437
`+
std::vectorstd::string errors{};
`
``
438
`+
per_isolate_opts.reset(new PerIsolateOptions());
`
``
439
+
``
440
`+
// Using invalid_args as the v8_args argument as it stores unknown
`
``
441
`+
// options for the per isolate parser.
`
``
442
`+
options_parser::Parse(
`
``
443
`+
&exec_argv,
`
``
444
`+
&exec_argv_out,
`
``
445
`+
&invalid_args,
`
``
446
`+
per_isolate_opts.get(),
`
``
447
`+
kDisallowedInEnvironment,
`
``
448
`+
&errors);
`
``
449
+
``
450
`+
// The first argument is program name.
`
``
451
`+
invalid_args.erase(invalid_args.begin());
`
``
452
`+
if (errors.size() > 0 || invalid_args.size() > 0) {
`
``
453
`+
v8::Localv8::Value error =
`
``
454
`+
ToV8Value(env->context(),
`
``
455
`+
errors.size() > 0 ? errors : invalid_args)
`
``
456
`+
.ToLocalChecked();
`
``
457
`+
Local key =
`
``
458
`+
FIXED_ONE_BYTE_STRING(env->isolate(), "invalidExecArgv");
`
``
459
`+
USE(args.This()->Set(env->context(), key, error).FromJust());
`
``
460
`+
return;
`
460
461
` }
`
461
462
` }
`
462
463
`if (!has_explicit_exec_argv)
`