diff --git a/src/d8-posix.cc b/src/d8-posix.cc index d2cf573d4c..cdfc39cc5d 100644 --- a/src/d8-posix.cc +++ b/src/d8-posix.cc @@ -772,4 +772,12 @@ void Shell::AddOSMethods(Isolate* isolate, Local os_templ) { FunctionTemplate::New(isolate, RemoveDirectory)); } +void Shell::Exit(int exit_code) { + // Use _exit instead of exit to avoid races between isolate + // threads and static destructors. + fflush(stdout); + fflush(stderr); + _exit(exit_code); +} + } // namespace v8 diff --git a/src/d8-windows.cc b/src/d8-windows.cc index ba89c4156f..e7ddca694f 100644 --- a/src/d8-windows.cc +++ b/src/d8-windows.cc @@ -10,5 +10,12 @@ namespace v8 { void Shell::AddOSMethods(Isolate* isolate, Local os_templ) {} +void Shell::Exit(int exit_code) { + // Use TerminateProcess avoid races between isolate threads and + // static destructors. + fflush(stdout); + fflush(stderr); + TerminateProcess(GetCurrentProcess(), exit_code); +} } // namespace v8 diff --git a/src/d8.cc b/src/d8.cc index 66e3b518a5..4b156b22c6 100644 --- a/src/d8.cc +++ b/src/d8.cc @@ -1569,16 +1569,6 @@ Local Shell::CreateEvaluationContext(Isolate* isolate) { return handle_scope.Escape(context); } - -void Shell::Exit(int exit_code) { - // Use _exit instead of exit to avoid races between isolate - // threads and static destructors. - fflush(stdout); - fflush(stderr); - _exit(exit_code); -} - - struct CounterAndKey { Counter* counter; const char* key;