src: cleanup beforeExit for consistency

PR-URL: https://github.com/nodejs/node/pull/21113
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
James M Snell 2018-06-03 07:28:29 -07:00 committed by Anna Henningsen
parent 8d27477acf
commit 9459dfad90
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9
2 changed files with 11 additions and 9 deletions

View File

@ -160,9 +160,7 @@ struct PackageConfig {
V(env_pairs_string, "envPairs") \
V(errno_string, "errno") \
V(error_string, "error") \
V(exiting_string, "_exiting") \
V(exit_code_string, "exitCode") \
V(exit_string, "exit") \
V(expire_string, "expire") \
V(exponent_string, "exponent") \
V(exports_string, "exports") \

View File

@ -4117,10 +4117,11 @@ void EmitBeforeExit(Environment* env) {
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());
Local<Object> process_object = env->process_object();
Local<String> exit_code = FIXED_ONE_BYTE_STRING(env->isolate(), "exitCode");
Local<String> exit_code = env->exit_code_string();
Local<Value> args[] = {
FIXED_ONE_BYTE_STRING(env->isolate(), "beforeExit"),
process_object->Get(exit_code)->ToInteger(env->context()).ToLocalChecked()
process_object->Get(env->context(), exit_code).ToLocalChecked()
->ToInteger(env->context()).ToLocalChecked()
};
MakeCallback(env->isolate(),
process_object, "emit", arraysize(args), args,
@ -4133,13 +4134,15 @@ int EmitExit(Environment* env) {
HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());
Local<Object> process_object = env->process_object();
process_object->Set(env->exiting_string(), True(env->isolate()));
process_object->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "_exiting"),
True(env->isolate()));
Local<String> exitCode = env->exit_code_string();
int code = process_object->Get(exitCode)->Int32Value();
Local<String> exit_code = env->exit_code_string();
int code = process_object->Get(env->context(), exit_code).ToLocalChecked()
->Int32Value(env->context()).ToChecked();
Local<Value> args[] = {
env->exit_string(),
FIXED_ONE_BYTE_STRING(env->isolate(), "exit"),
Integer::New(env->isolate(), code)
};
@ -4148,7 +4151,8 @@ int EmitExit(Environment* env) {
{0, 0}).ToLocalChecked();
// Reload exit code, it may be changed by `emit('exit')`
return process_object->Get(exitCode)->Int32Value();
return process_object->Get(env->context(), exit_code).ToLocalChecked()
->Int32Value(env->context()).ToChecked();
}