@@ -16,7 +16,6 @@ using v8::NewStringType;
16
16
using v8::Nothing;
17
17
using v8::Object;
18
18
using v8::String;
19
- using v8::Value;
20
19
21
20
void RunAtExit (Environment* env) {
22
21
env->RunAtExitCallbacks ();
@@ -36,19 +35,17 @@ Maybe<bool> EmitProcessBeforeExit(Environment* env) {
36
35
if (!env->destroy_async_id_list ()->empty ())
37
36
AsyncWrap::DestroyAsyncIdsCallback (env);
38
37
39
- HandleScope handle_scope (env->isolate ());
40
- Local<Context> context = env->context ();
41
- Context::Scope context_scope (context);
42
-
43
- Local<Value> exit_code_v;
44
- if (!env->process_object ()->Get (context, env->exit_code_string ())
45
- .ToLocal (&exit_code_v)) return Nothing<bool >();
38
+ Isolate* isolate = env->isolate ();
39
+ HandleScope handle_scope (isolate);
40
+ Context::Scope context_scope (env->context ());
46
41
47
- Local<Integer> exit_code;
48
- if (!exit_code_v->ToInteger (context).ToLocal (&exit_code)) {
42
+ if (!env->can_call_into_js ()) {
49
43
return Nothing<bool >();
50
44
}
51
45
46
+ Local<Integer> exit_code = Integer::New (
47
+ isolate, static_cast <int32_t >(env->exit_code (ExitCode::kNoFailure )));
48
+
52
49
return ProcessEmit (env, " beforeExit" , exit_code).IsEmpty () ?
53
50
Nothing<bool >() : Just (true );
54
51
}
@@ -65,29 +62,22 @@ Maybe<ExitCode> EmitProcessExitInternal(Environment* env) {
65
62
// process.emit('exit')
66
63
Isolate* isolate = env->isolate ();
67
64
HandleScope handle_scope (isolate);
68
- Local<Context> context = env->context ();
69
- Context::Scope context_scope (context);
70
- Local<Object> process_object = env->process_object ();
71
-
72
- // TODO(addaleax): It might be nice to share process.exitCode via
73
- // getter/setter pairs that pass data directly to the native side, so that we
74
- // don't manually have to read and write JS properties here. These getters
75
- // could use e.g. a typed array for performance.
65
+ Context::Scope context_scope (env->context ());
66
+
76
67
env->set_exiting (true );
77
68
78
- Local<String> exit_code = env->exit_code_string ();
79
- Local<Value> code_v;
80
- int code;
81
- if (!process_object->Get (context, exit_code).ToLocal (&code_v) ||
82
- !code_v->Int32Value (context).To (&code) ||
83
- ProcessEmit (env, " exit" , Integer::New (isolate, code)).IsEmpty () ||
84
- // Reload exit code, it may be changed by `emit('exit')`
85
- !process_object->Get (context, exit_code).ToLocal (&code_v) ||
86
- !code_v->Int32Value (context).To (&code)) {
69
+ if (!env->can_call_into_js ()) {
87
70
return Nothing<ExitCode>();
88
71
}
89
72
90
- return Just (static_cast <ExitCode>(code));
73
+ Local<Integer> exit_code = Integer::New (
74
+ isolate, static_cast <int32_t >(env->exit_code (ExitCode::kNoFailure )));
75
+
76
+ if (ProcessEmit (env, " exit" , exit_code).IsEmpty ()) {
77
+ return Nothing<ExitCode>();
78
+ }
79
+ // Reload exit code, it may be changed by `emit('exit')`
80
+ return Just (env->exit_code (ExitCode::kNoFailure ));
91
81
}
92
82
93
83
Maybe<int > EmitProcessExit (Environment* env) {
0 commit comments