@@ -124,8 +124,6 @@ using v8::Maybe;
124
124
using v8::MaybeLocal;
125
125
using v8::Message;
126
126
using v8::MicrotasksPolicy;
127
- using v8::NewStringType;
128
- using v8::Nothing;
129
127
using v8::Object;
130
128
using v8::ObjectTemplate;
131
129
using v8::Script;
@@ -582,82 +580,6 @@ void Exit(const FunctionCallbackInfo<Value>& args) {
582
580
env->Exit (code);
583
581
}
584
582
585
- static Maybe<bool > ProcessEmitWarningGeneric (Environment* env,
586
- const char * warning,
587
- const char * type = nullptr ,
588
- const char * code = nullptr ) {
589
- HandleScope handle_scope (env->isolate ());
590
- Context::Scope context_scope (env->context ());
591
-
592
- Local<Object> process = env->process_object ();
593
- Local<Value> emit_warning;
594
- if (!process->Get (env->context (),
595
- env->emit_warning_string ()).ToLocal (&emit_warning)) {
596
- return Nothing<bool >();
597
- }
598
-
599
- if (!emit_warning->IsFunction ()) return Just (false );
600
-
601
- int argc = 0 ;
602
- Local<Value> args[3 ]; // warning, type, code
603
-
604
- // The caller has to be able to handle a failure anyway, so we might as well
605
- // do proper error checking for string creation.
606
- if (!String::NewFromUtf8 (env->isolate (),
607
- warning,
608
- NewStringType::kNormal ).ToLocal (&args[argc++])) {
609
- return Nothing<bool >();
610
- }
611
- if (type != nullptr ) {
612
- if (!String::NewFromOneByte (env->isolate (),
613
- reinterpret_cast <const uint8_t *>(type),
614
- NewStringType::kNormal )
615
- .ToLocal (&args[argc++])) {
616
- return Nothing<bool >();
617
- }
618
- if (code != nullptr &&
619
- !String::NewFromOneByte (env->isolate (),
620
- reinterpret_cast <const uint8_t *>(code),
621
- NewStringType::kNormal )
622
- .ToLocal (&args[argc++])) {
623
- return Nothing<bool >();
624
- }
625
- }
626
-
627
- // MakeCallback() unneeded because emitWarning is internal code, it calls
628
- // process.emit('warning', ...), but does so on the nextTick.
629
- if (emit_warning.As <Function>()->Call (env->context (),
630
- process,
631
- argc,
632
- args).IsEmpty ()) {
633
- return Nothing<bool >();
634
- }
635
- return Just (true );
636
- }
637
-
638
-
639
- // Call process.emitWarning(str), fmt is a snprintf() format string
640
- Maybe<bool > ProcessEmitWarning (Environment* env, const char * fmt, ...) {
641
- char warning[1024 ];
642
- va_list ap;
643
-
644
- va_start (ap, fmt);
645
- vsnprintf (warning, sizeof (warning), fmt, ap);
646
- va_end (ap);
647
-
648
- return ProcessEmitWarningGeneric (env, warning);
649
- }
650
-
651
-
652
- Maybe<bool > ProcessEmitDeprecationWarning (Environment* env,
653
- const char * warning,
654
- const char * deprecation_code) {
655
- return ProcessEmitWarningGeneric (env,
656
- warning,
657
- " DeprecationWarning" ,
658
- deprecation_code);
659
- }
660
-
661
583
static void OnMessage (Local<Message> message, Local<Value> error) {
662
584
Isolate* isolate = message->GetIsolate ();
663
585
switch (message->ErrorLevel ()) {
@@ -1160,19 +1082,14 @@ void RunBeforeExit(Environment* env) {
1160
1082
void EmitBeforeExit (Environment* env) {
1161
1083
HandleScope handle_scope (env->isolate ());
1162
1084
Context::Scope context_scope (env->context ());
1163
- Local<Object> process_object = env->process_object ();
1164
- Local<String> exit_code = env->exit_code_string ();
1165
- Local<Value> args[] = {
1166
- FIXED_ONE_BYTE_STRING (env->isolate (), " beforeExit" ),
1167
- process_object->Get (env->context (), exit_code).ToLocalChecked ()
1168
- ->ToInteger (env->context ()).ToLocalChecked ()
1169
- };
1170
- MakeCallback (env->isolate (),
1171
- process_object, " emit" , arraysize (args), args,
1172
- {0 , 0 }).ToLocalChecked ();
1085
+ Local<Value> exit_code = env->process_object ()
1086
+ ->Get (env->context (), env->exit_code_string ())
1087
+ .ToLocalChecked ()
1088
+ ->ToInteger (env->context ())
1089
+ .ToLocalChecked ();
1090
+ ProcessEmit (env, " beforeExit" , exit_code).ToLocalChecked ();
1173
1091
}
1174
1092
1175
-
1176
1093
int EmitExit (Environment* env) {
1177
1094
// process.emit('exit')
1178
1095
HandleScope handle_scope (env->isolate ());
@@ -1185,15 +1102,7 @@ int EmitExit(Environment* env) {
1185
1102
Local<String> exit_code = env->exit_code_string ();
1186
1103
int code = process_object->Get (env->context (), exit_code).ToLocalChecked ()
1187
1104
->Int32Value (env->context ()).ToChecked ();
1188
-
1189
- Local<Value> args[] = {
1190
- FIXED_ONE_BYTE_STRING (env->isolate (), " exit" ),
1191
- Integer::New (env->isolate (), code)
1192
- };
1193
-
1194
- MakeCallback (env->isolate (),
1195
- process_object, " emit" , arraysize (args), args,
1196
- {0 , 0 }).ToLocalChecked ();
1105
+ ProcessEmit (env, " exit" , Integer::New (env->isolate (), code));
1197
1106
1198
1107
// Reload exit code, it may be changed by `emit('exit')`
1199
1108
return process_object->Get (env->context (), exit_code).ToLocalChecked ()
0 commit comments