@@ -3341,11 +3341,6 @@ void SetupProcessObject(Environment* env,
3341
3341
#undef READONLY_PROPERTY
3342
3342
3343
3343
3344
- static void AtProcessExit () {
3345
- uv_tty_reset_mode ();
3346
- }
3347
-
3348
-
3349
3344
void SignalExit (int signo) {
3350
3345
uv_tty_reset_mode ();
3351
3346
#ifdef __FreeBSD__
@@ -3375,11 +3370,6 @@ static void RawDebug(const FunctionCallbackInfo<Value>& args) {
3375
3370
void LoadEnvironment (Environment* env) {
3376
3371
HandleScope handle_scope (env->isolate ());
3377
3372
3378
- env->isolate ()->SetFatalErrorHandler (node::OnFatalError);
3379
- env->isolate ()->AddMessageListener (OnMessage);
3380
-
3381
- atexit (AtProcessExit);
3382
-
3383
3373
TryCatch try_catch (env->isolate ());
3384
3374
3385
3375
// Disable verbose mode to stop FatalException() handler from trying
@@ -4369,107 +4359,118 @@ void FreeEnvironment(Environment* env) {
4369
4359
}
4370
4360
4371
4361
4362
+ inline int Start (Isolate* isolate, IsolateData* isolate_data,
4363
+ int argc, const char * const * argv,
4364
+ int exec_argc, const char * const * exec_argv) {
4365
+ HandleScope handle_scope (isolate);
4366
+ Local<Context> context = Context::New (isolate);
4367
+ Context::Scope context_scope (context);
4368
+ Environment env (isolate_data, context);
4369
+ env.Start (argc, argv, exec_argc, exec_argv, v8_is_profiling);
4370
+
4371
+ // Start debug agent when argv has --debug
4372
+ if (use_debug_agent) {
4373
+ const char * path = argc > 1 ? argv[1 ] : nullptr ;
4374
+ StartDebug (&env, path, debug_wait_connect);
4375
+ if (use_inspector && !debugger_running)
4376
+ return 12 ; // Signal internal error.
4377
+ }
4378
+
4379
+ {
4380
+ Environment::AsyncCallbackScope callback_scope (&env);
4381
+ LoadEnvironment (&env);
4382
+ }
4383
+
4384
+ env.set_trace_sync_io (trace_sync_io);
4385
+
4386
+ // Enable debugger
4387
+ if (use_debug_agent)
4388
+ EnableDebug (&env);
4389
+
4390
+ {
4391
+ SealHandleScope seal (isolate);
4392
+ bool more;
4393
+ do {
4394
+ v8_platform.PumpMessageLoop (isolate);
4395
+ more = uv_run (env.event_loop (), UV_RUN_ONCE);
4396
+
4397
+ if (more == false ) {
4398
+ v8_platform.PumpMessageLoop (isolate);
4399
+ EmitBeforeExit (&env);
4400
+
4401
+ // Emit `beforeExit` if the loop became alive either after emitting
4402
+ // event, or after running some callbacks.
4403
+ more = uv_loop_alive (env.event_loop ());
4404
+ if (uv_run (env.event_loop (), UV_RUN_NOWAIT) != 0 )
4405
+ more = true ;
4406
+ }
4407
+ } while (more == true );
4408
+ }
4409
+
4410
+ env.set_trace_sync_io (false );
4411
+
4412
+ const int exit_code = EmitExit (&env);
4413
+ RunAtExit (&env);
4414
+
4415
+ WaitForInspectorDisconnect (&env);
4416
+ #if defined(LEAK_SANITIZER)
4417
+ __lsan_do_leak_check ();
4418
+ #endif
4419
+
4420
+ return exit_code;
4421
+ }
4422
+
4372
4423
inline int Start (uv_loop_t * event_loop,
4373
4424
int argc, const char * const * argv,
4374
4425
int exec_argc, const char * const * exec_argv) {
4375
4426
Isolate::CreateParams params;
4376
- ArrayBufferAllocator array_buffer_allocator ;
4377
- params.array_buffer_allocator = &array_buffer_allocator ;
4427
+ ArrayBufferAllocator allocator ;
4428
+ params.array_buffer_allocator = &allocator ;
4378
4429
#ifdef NODE_ENABLE_VTUNE_PROFILING
4379
4430
params.code_event_handler = vTune::GetVtuneCodeEventHandler ();
4380
4431
#endif
4381
- Isolate* isolate = Isolate::New (params);
4432
+
4433
+ Isolate* const isolate = Isolate::New (params);
4434
+ if (isolate == nullptr )
4435
+ return 12 ; // Signal internal error.
4436
+
4437
+ isolate->AddMessageListener (OnMessage);
4438
+ isolate->SetAbortOnUncaughtExceptionCallback (ShouldAbortOnUncaughtException);
4439
+ isolate->SetAutorunMicrotasks (false );
4440
+ isolate->SetFatalErrorHandler (OnFatalError);
4441
+
4442
+ if (track_heap_objects) {
4443
+ isolate->GetHeapProfiler ()->StartTrackingHeapObjects (true );
4444
+ }
4382
4445
4383
4446
{
4384
4447
Mutex::ScopedLock scoped_lock (node_isolate_mutex);
4385
4448
CHECK_EQ (node_isolate, nullptr );
4386
4449
node_isolate = isolate;
4387
4450
}
4388
4451
4389
- if (track_heap_objects) {
4390
- isolate->GetHeapProfiler ()->StartTrackingHeapObjects (true );
4391
- }
4392
-
4393
4452
int exit_code;
4394
4453
{
4395
4454
Locker locker (isolate);
4396
4455
Isolate::Scope isolate_scope (isolate);
4397
4456
HandleScope handle_scope (isolate);
4398
- IsolateData isolate_data (isolate, event_loop,
4399
- array_buffer_allocator.zero_fill_field ());
4400
- Local<Context> context = Context::New (isolate);
4401
- Context::Scope context_scope (context);
4402
- Environment env (&isolate_data, context);
4403
- env.Start (argc, argv, exec_argc, exec_argv, v8_is_profiling);
4404
-
4405
- isolate->SetAbortOnUncaughtExceptionCallback (
4406
- ShouldAbortOnUncaughtException);
4407
-
4408
- // Start debug agent when argv has --debug
4409
- if (use_debug_agent) {
4410
- const char * path = argc > 1 ? argv[1 ] : nullptr ;
4411
- StartDebug (&env, path, debug_wait_connect);
4412
- if (use_inspector && !debugger_running) {
4413
- exit (12 );
4414
- }
4415
- }
4416
-
4417
- {
4418
- Environment::AsyncCallbackScope callback_scope (&env);
4419
- LoadEnvironment (&env);
4420
- }
4421
-
4422
- env.set_trace_sync_io (trace_sync_io);
4423
-
4424
- // Enable debugger
4425
- if (use_debug_agent)
4426
- EnableDebug (&env);
4427
-
4428
- {
4429
- SealHandleScope seal (isolate);
4430
- bool more;
4431
- do {
4432
- v8_platform.PumpMessageLoop (isolate);
4433
- more = uv_run (env.event_loop (), UV_RUN_ONCE);
4434
-
4435
- if (more == false ) {
4436
- v8_platform.PumpMessageLoop (isolate);
4437
- EmitBeforeExit (&env);
4438
-
4439
- // Emit `beforeExit` if the loop became alive either after emitting
4440
- // event, or after running some callbacks.
4441
- more = uv_loop_alive (env.event_loop ());
4442
- if (uv_run (env.event_loop (), UV_RUN_NOWAIT) != 0 )
4443
- more = true ;
4444
- }
4445
- } while (more == true );
4446
- }
4447
-
4448
- env.set_trace_sync_io (false );
4449
-
4450
- exit_code = EmitExit (&env);
4451
- RunAtExit (&env);
4452
-
4453
- WaitForInspectorDisconnect (&env);
4454
- #if defined(LEAK_SANITIZER)
4455
- __lsan_do_leak_check ();
4456
- #endif
4457
+ IsolateData isolate_data (isolate, event_loop, allocator.zero_fill_field ());
4458
+ exit_code = Start (isolate, &isolate_data, argc, argv, exec_argc, exec_argv);
4457
4459
}
4458
4460
4459
4461
{
4460
4462
Mutex::ScopedLock scoped_lock (node_isolate_mutex);
4461
- if (node_isolate == isolate)
4462
- node_isolate = nullptr ;
4463
+ CHECK_EQ (node_isolate, isolate);
4464
+ node_isolate = nullptr ;
4463
4465
}
4464
4466
4465
- CHECK_NE (isolate, nullptr );
4466
4467
isolate->Dispose ();
4467
- isolate = nullptr ;
4468
4468
4469
4469
return exit_code;
4470
4470
}
4471
4471
4472
4472
int Start (int argc, char ** argv) {
4473
+ atexit ([] () { uv_tty_reset_mode (); });
4473
4474
PlatformInit ();
4474
4475
4475
4476
CHECK_GT (argc, 0 );
0 commit comments