@@ -2563,6 +2563,33 @@ void ClearFatalExceptionHandlers(Environment* env) {
25632563 Undefined(env->isolate())).FromJust();
25642564}
25652565
2566+ // Call process.emitWarning(str), fmt is a snprintf() format string
2567+ void ProcessEmitWarning(Environment* env, const char* fmt, ...) {
2568+ char warning[1024];
2569+ va_list ap;
2570+
2571+ va_start(ap, fmt);
2572+ vsnprintf(warning, sizeof(warning), fmt, ap);
2573+ va_end(ap);
2574+
2575+ HandleScope handle_scope(env->isolate());
2576+ Context::Scope context_scope(env->context());
2577+
2578+ Local<Object> process = env->process_object();
2579+ MaybeLocal<Value> emit_warning = process->Get(env->context(),
2580+ FIXED_ONE_BYTE_STRING(env->isolate(), "emitWarning"));
2581+ Local<Value> arg = node::OneByteString(env->isolate(), warning);
2582+
2583+ Local<Value> f;
2584+
2585+ if (!emit_warning.ToLocal(&f)) return;
2586+ if (!f->IsFunction()) return;
2587+
2588+ // MakeCallback() unneeded, because emitWarning is internal code, it calls
2589+ // process.emit('warning', ..), but does so on the nextTick.
2590+ f.As<v8::Function>()->Call(process, 1, &arg);
2591+ }
2592+
25662593
25672594static void Binding(const FunctionCallbackInfo<Value>& args) {
25682595 Environment* env = Environment::GetCurrent(args);
0 commit comments