@@ -4369,10 +4369,9 @@ void FreeEnvironment(Environment* env) {
43694369}
43704370
43714371
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) {
43764375 Isolate::CreateParams params;
43774376 ArrayBufferAllocator array_buffer_allocator;
43784377 params.array_buffer_allocator = &array_buffer_allocator;
@@ -4383,39 +4382,32 @@ static void StartNodeInstance(void* arg) {
43834382
43844383 {
43854384 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;
43904387 }
43914388
43924389 if (track_heap_objects) {
43934390 isolate->GetHeapProfiler ()->StartTrackingHeapObjects (true );
43944391 }
43954392
4393+ int exit_code;
43964394 {
43974395 Locker locker (isolate);
43984396 Isolate::Scope isolate_scope (isolate);
43994397 HandleScope handle_scope (isolate);
4400- IsolateData isolate_data (isolate, instance_data-> event_loop () ,
4398+ IsolateData isolate_data (isolate, event_loop,
44014399 array_buffer_allocator.zero_fill_field ());
44024400 Local<Context> context = Context::New (isolate);
44034401 Context::Scope context_scope (context);
44044402 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);
44104404
44114405 isolate->SetAbortOnUncaughtExceptionCallback (
44124406 ShouldAbortOnUncaughtException);
44134407
44144408 // 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 ;
44194411 StartDebug (&env, path, debug_wait_connect);
44204412 if (use_inspector && !debugger_running) {
44214413 exit (12 );
@@ -4430,7 +4422,7 @@ static void StartNodeInstance(void* arg) {
44304422 env.set_trace_sync_io (trace_sync_io);
44314423
44324424 // Enable debugger
4433- if (instance_data-> use_debug_agent () )
4425+ if (use_debug_agent)
44344426 EnableDebug (&env);
44354427
44364428 {
@@ -4455,9 +4447,7 @@ static void StartNodeInstance(void* arg) {
44554447
44564448 env.set_trace_sync_io (false );
44574449
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);
44614451 RunAtExit (&env);
44624452
44634453 WaitForInspectorDisconnect (&env);
@@ -4475,6 +4465,8 @@ static void StartNodeInstance(void* arg) {
44754465 CHECK_NE (isolate, nullptr );
44764466 isolate->Dispose ();
44774467 isolate = nullptr ;
4468+
4469+ return exit_code;
44784470}
44794471
44804472int Start (int argc, char ** argv) {
@@ -4505,19 +4497,8 @@ int Start(int argc, char** argv) {
45054497 v8_platform.Initialize (v8_thread_pool_size);
45064498 V8::Initialize ();
45074499 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);
45214502 v8_initialized = false ;
45224503 V8::Dispose ();
45234504
0 commit comments