Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: cleanup beforeExit for consistency #21113

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ struct PackageConfig {
V(args_string, "args") \
V(async, "async") \
V(async_ids_stack_string, "async_ids_stack") \
V(before_exit_string, "beforeExit") \
V(buffer_string, "buffer") \
V(bytes_string, "bytes") \
V(bytes_parsed_string, "bytesParsed") \
Expand Down
10 changes: 5 additions & 5 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4075,9 +4075,9 @@ 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"),
env->before_exit_string(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a pattern, we only store strings on the Environment if we expect to use them more than once per isolate, but in the case of beforeExit that’s not the typical case, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not the case for "exit" or "exitCode" either ... so we should either just make them all use FIXED_ONE_BYTE_STRING here or put them all in env ... I'm good either way so long as it's consistent.

That said, one could in theory have beforeExit happen multiple times ... we've had that happen to us a few times ;-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case I’d prefer to follow the pattern and use FIXED_ONE_BYTE_STRING for those as well, yeah :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1... I'll keep exitCode on env since that is at least used in both beforeExit and exit. But will make beforeExit and exit each use FIXED_ONE_BYTE_STRING

process_object->Get(exit_code)->ToInteger(env->context()).ToLocalChecked()
};
MakeCallback(env->isolate(),
Expand All @@ -4093,8 +4093,8 @@ int EmitExit(Environment* env) {
Local<Object> process_object = env->process_object();
process_object->Set(env->exiting_string(), 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(exit_code)->Int32Value();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might as well switch to the non-deprecated versions of Int32Value() and ->Get() here if the PR already touched the code :)


Local<Value> args[] = {
env->exit_string(),
Expand All @@ -4106,7 +4106,7 @@ 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(exit_code)->Int32Value();
}


Expand Down