From c47eb932bcb9af521b13323f5441afb94ef562de Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Fri, 1 Feb 2019 08:00:23 +0800 Subject: [PATCH] src: move process.reallyExit impl into node_process_methods.cc Because the part that is shared by `process.reallyExit` and the Node.js teardown is `WaitForInspectorDisconnect()`, move that into node_internals.h instead, and move the C++ binding code into `node_process_methods.cc` since that's the only place it's needed. PR-URL: https://github.com/nodejs/node/pull/25860 Reviewed-By: Anna Henningsen Reviewed-By: Minwoo Jung Reviewed-By: Jeremiah Senkpiel --- src/node.cc | 10 +--------- src/node_internals.h | 2 +- src/node_process_methods.cc | 9 ++++++++- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/node.cc b/src/node.cc index 2942b33d8d5c18..a0409b2519516f 100644 --- a/src/node.cc +++ b/src/node.cc @@ -118,7 +118,6 @@ using v8::Exception; using v8::Function; using v8::FunctionCallbackInfo; using v8::HandleScope; -using v8::Int32; using v8::Isolate; using v8::Just; using v8::Local; @@ -158,7 +157,7 @@ struct V8Platform v8_platform; static const unsigned kMaxSignal = 32; #endif -static void WaitForInspectorDisconnect(Environment* env) { +void WaitForInspectorDisconnect(Environment* env) { #if HAVE_INSPECTOR if (env->inspector_agent()->IsActive()) { // Restore signal dispositions, the app is done and is no longer @@ -178,13 +177,6 @@ static void WaitForInspectorDisconnect(Environment* env) { #endif } -void Exit(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); - WaitForInspectorDisconnect(env); - int code = args[0]->Int32Value(env->context()).FromMaybe(0); - env->Exit(code); -} - void SignalExit(int signo) { uv_tty_reset_mode(); #ifdef __FreeBSD__ diff --git a/src/node_internals.h b/src/node_internals.h index b34e6f90e7d28c..c94be6ebe9155d 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -86,7 +86,7 @@ void GetSockOrPeerName(const v8::FunctionCallbackInfo& args) { args.GetReturnValue().Set(err); } -void Exit(const v8::FunctionCallbackInfo& args); +void WaitForInspectorDisconnect(Environment* env); void SignalExit(int signo); #ifdef __POSIX__ void RegisterSignalHandler(int signal, diff --git a/src/node_process_methods.cc b/src/node_process_methods.cc index a6d2c252e77ac5..be91a11f566baa 100644 --- a/src/node_process_methods.cc +++ b/src/node_process_methods.cc @@ -385,6 +385,13 @@ static void DebugEnd(const FunctionCallbackInfo& args) { #endif } +static void ReallyExit(const FunctionCallbackInfo& args) { + Environment* env = Environment::GetCurrent(args); + WaitForInspectorDisconnect(env); + int code = args[0]->Int32Value(env->context()).FromMaybe(0); + env->Exit(code); +} + static void InitializeProcessMethods(Local target, Local unused, Local context, @@ -416,7 +423,7 @@ static void InitializeProcessMethods(Local target, env->SetMethodNoSideEffect(target, "cwd", Cwd); env->SetMethod(target, "dlopen", binding::DLOpen); - env->SetMethod(target, "reallyExit", Exit); + env->SetMethod(target, "reallyExit", ReallyExit); env->SetMethodNoSideEffect(target, "uptime", Uptime); }