@@ -4369,10 +4369,9 @@ void FreeEnvironment(Environment* env) {
4369
4369
}
4370
4370
4371
4371
4372
- // Entry point for new node instances, also called directly for the main
4373
- // node instance.
4374
- static void StartNodeInstance (void * arg) {
4375
- NodeInstanceData* instance_data = static_cast <NodeInstanceData*>(arg);
4372
+ inline int Start (uv_loop_t * event_loop,
4373
+ int argc, const char * const * argv,
4374
+ int exec_argc, const char * const * exec_argv) {
4376
4375
Isolate::CreateParams params;
4377
4376
ArrayBufferAllocator array_buffer_allocator;
4378
4377
params.array_buffer_allocator = &array_buffer_allocator;
@@ -4383,39 +4382,32 @@ static void StartNodeInstance(void* arg) {
4383
4382
4384
4383
{
4385
4384
Mutex::ScopedLock scoped_lock (node_isolate_mutex);
4386
- if (instance_data->is_main ()) {
4387
- CHECK_EQ (node_isolate, nullptr );
4388
- node_isolate = isolate;
4389
- }
4385
+ CHECK_EQ (node_isolate, nullptr );
4386
+ node_isolate = isolate;
4390
4387
}
4391
4388
4392
4389
if (track_heap_objects) {
4393
4390
isolate->GetHeapProfiler ()->StartTrackingHeapObjects (true );
4394
4391
}
4395
4392
4393
+ int exit_code;
4396
4394
{
4397
4395
Locker locker (isolate);
4398
4396
Isolate::Scope isolate_scope (isolate);
4399
4397
HandleScope handle_scope (isolate);
4400
- IsolateData isolate_data (isolate, instance_data-> event_loop () ,
4398
+ IsolateData isolate_data (isolate, event_loop,
4401
4399
array_buffer_allocator.zero_fill_field ());
4402
4400
Local<Context> context = Context::New (isolate);
4403
4401
Context::Scope context_scope (context);
4404
4402
Environment env (&isolate_data, context);
4405
- env.Start (instance_data->argc (),
4406
- instance_data->argv (),
4407
- instance_data->exec_argc (),
4408
- instance_data->exec_argv (),
4409
- v8_is_profiling);
4403
+ env.Start (argc, argv, exec_argc, exec_argv, v8_is_profiling);
4410
4404
4411
4405
isolate->SetAbortOnUncaughtExceptionCallback (
4412
4406
ShouldAbortOnUncaughtException);
4413
4407
4414
4408
// Start debug agent when argv has --debug
4415
- if (instance_data->use_debug_agent ()) {
4416
- const char * path = instance_data->argc () > 1
4417
- ? instance_data->argv ()[1 ]
4418
- : nullptr ;
4409
+ if (use_debug_agent) {
4410
+ const char * path = argc > 1 ? argv[1 ] : nullptr ;
4419
4411
StartDebug (&env, path, debug_wait_connect);
4420
4412
if (use_inspector && !debugger_running) {
4421
4413
exit (12 );
@@ -4430,7 +4422,7 @@ static void StartNodeInstance(void* arg) {
4430
4422
env.set_trace_sync_io (trace_sync_io);
4431
4423
4432
4424
// Enable debugger
4433
- if (instance_data-> use_debug_agent () )
4425
+ if (use_debug_agent)
4434
4426
EnableDebug (&env);
4435
4427
4436
4428
{
@@ -4455,9 +4447,7 @@ static void StartNodeInstance(void* arg) {
4455
4447
4456
4448
env.set_trace_sync_io (false );
4457
4449
4458
- int exit_code = EmitExit (&env);
4459
- if (instance_data->is_main ())
4460
- instance_data->set_exit_code (exit_code);
4450
+ exit_code = EmitExit (&env);
4461
4451
RunAtExit (&env);
4462
4452
4463
4453
WaitForInspectorDisconnect (&env);
@@ -4475,6 +4465,8 @@ static void StartNodeInstance(void* arg) {
4475
4465
CHECK_NE (isolate, nullptr );
4476
4466
isolate->Dispose ();
4477
4467
isolate = nullptr ;
4468
+
4469
+ return exit_code;
4478
4470
}
4479
4471
4480
4472
int Start (int argc, char ** argv) {
@@ -4505,19 +4497,8 @@ int Start(int argc, char** argv) {
4505
4497
v8_platform.Initialize (v8_thread_pool_size);
4506
4498
V8::Initialize ();
4507
4499
v8_initialized = true ;
4508
-
4509
- int exit_code = 1 ;
4510
- {
4511
- NodeInstanceData instance_data (NodeInstanceType::MAIN,
4512
- uv_default_loop (),
4513
- argc,
4514
- const_cast <const char **>(argv),
4515
- exec_argc,
4516
- exec_argv,
4517
- use_debug_agent);
4518
- StartNodeInstance (&instance_data);
4519
- exit_code = instance_data.exit_code ();
4520
- }
4500
+ const int exit_code =
4501
+ Start (uv_default_loop (), argc, argv, exec_argc, exec_argv);
4521
4502
v8_initialized = false ;
4522
4503
V8::Dispose ();
4523
4504
0 commit comments