@@ -439,63 +439,64 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) {
439
439
std::vector<std::string> exec_argv_out;
440
440
bool has_explicit_exec_argv = false ;
441
441
442
+ CHECK_EQ (args.Length (), 2 );
442
443
// Argument might be a string or URL
443
- if (args. Length () > 0 && !args[0 ]->IsNullOrUndefined ()) {
444
+ if (!args[0 ]->IsNullOrUndefined ()) {
444
445
Utf8Value value (
445
446
args.GetIsolate (),
446
447
args[0 ]->ToString (env->context ()).FromMaybe (v8::Local<v8::String>()));
447
448
url.append (value.out (), value.length ());
449
+ }
448
450
449
- if (args.Length () > 1 && args[1 ]->IsArray ()) {
450
- v8::Local<v8::Array> array = args[1 ].As <v8::Array>();
451
- // The first argument is reserved for program name, but we don't need it
452
- // in workers.
453
- has_explicit_exec_argv = true ;
454
- std::vector<std::string> exec_argv = {" " };
455
- uint32_t length = array->Length ();
456
- for (uint32_t i = 0 ; i < length; i++) {
457
- v8::Local<v8::Value> arg;
458
- if (!array->Get (env->context (), i).ToLocal (&arg)) {
459
- return ;
460
- }
461
- v8::MaybeLocal<v8::String> arg_v8_string =
462
- arg->ToString (env->context ());
463
- if (arg_v8_string.IsEmpty ()) {
464
- return ;
465
- }
466
- Utf8Value arg_utf8_value (
467
- args.GetIsolate (),
468
- arg_v8_string.FromMaybe (v8::Local<v8::String>()));
469
- std::string arg_string (arg_utf8_value.out (), arg_utf8_value.length ());
470
- exec_argv.push_back (arg_string);
451
+ if (args[1 ]->IsArray ()) {
452
+ v8::Local<v8::Array> array = args[1 ].As <v8::Array>();
453
+ // The first argument is reserved for program name, but we don't need it
454
+ // in workers.
455
+ has_explicit_exec_argv = true ;
456
+ std::vector<std::string> exec_argv = {" " };
457
+ uint32_t length = array->Length ();
458
+ for (uint32_t i = 0 ; i < length; i++) {
459
+ v8::Local<v8::Value> arg;
460
+ if (!array->Get (env->context (), i).ToLocal (&arg)) {
461
+ return ;
471
462
}
472
-
473
- std::vector<std::string> invalid_args{};
474
- std::vector<std::string> errors{};
475
- per_isolate_opts.reset (new PerIsolateOptions ());
476
-
477
- // Using invalid_args as the v8_args argument as it stores unknown
478
- // options for the per isolate parser.
479
- options_parser::Parse (
480
- &exec_argv,
481
- &exec_argv_out,
482
- &invalid_args,
483
- per_isolate_opts.get (),
484
- kDisallowedInEnvironment ,
485
- &errors);
486
-
487
- // The first argument is program name.
488
- invalid_args.erase (invalid_args.begin ());
489
- if (errors.size () > 0 || invalid_args.size () > 0 ) {
490
- v8::Local<v8::Value> error =
491
- ToV8Value (env->context (),
492
- errors.size () > 0 ? errors : invalid_args)
493
- .ToLocalChecked ();
494
- Local<String> key =
495
- FIXED_ONE_BYTE_STRING (env->isolate (), " invalidExecArgv" );
496
- USE (args.This ()->Set (env->context (), key, error).FromJust ());
463
+ v8::MaybeLocal<v8::String> arg_v8_string =
464
+ arg->ToString (env->context ());
465
+ if (arg_v8_string.IsEmpty ()) {
497
466
return ;
498
467
}
468
+ Utf8Value arg_utf8_value (
469
+ args.GetIsolate (),
470
+ arg_v8_string.FromMaybe (v8::Local<v8::String>()));
471
+ std::string arg_string (arg_utf8_value.out (), arg_utf8_value.length ());
472
+ exec_argv.push_back (arg_string);
473
+ }
474
+
475
+ std::vector<std::string> invalid_args{};
476
+ std::vector<std::string> errors{};
477
+ per_isolate_opts.reset (new PerIsolateOptions ());
478
+
479
+ // Using invalid_args as the v8_args argument as it stores unknown
480
+ // options for the per isolate parser.
481
+ options_parser::Parse (
482
+ &exec_argv,
483
+ &exec_argv_out,
484
+ &invalid_args,
485
+ per_isolate_opts.get (),
486
+ kDisallowedInEnvironment ,
487
+ &errors);
488
+
489
+ // The first argument is program name.
490
+ invalid_args.erase (invalid_args.begin ());
491
+ if (errors.size () > 0 || invalid_args.size () > 0 ) {
492
+ v8::Local<v8::Value> error =
493
+ ToV8Value (env->context (),
494
+ errors.size () > 0 ? errors : invalid_args)
495
+ .ToLocalChecked ();
496
+ Local<String> key =
497
+ FIXED_ONE_BYTE_STRING (env->isolate (), " invalidExecArgv" );
498
+ USE (args.This ()->Set (env->context (), key, error).FromJust ());
499
+ return ;
499
500
}
500
501
}
501
502
if (!has_explicit_exec_argv)
0 commit comments