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