diff --git a/src/node.cc b/src/node.cc index b33bc0d2a1782a..4c85712dc8686b 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2563,6 +2563,33 @@ void ClearFatalExceptionHandlers(Environment* env) { Undefined(env->isolate())).FromJust(); } +// Call process.emitWarning(str), fmt is a snprintf() format string +void ProcessEmitWarning(Environment* env, const char* fmt, ...) { + char warning[1024]; + va_list ap; + + va_start(ap, fmt); + vsnprintf(warning, sizeof(warning), fmt, ap); + va_end(ap); + + HandleScope handle_scope(env->isolate()); + Context::Scope context_scope(env->context()); + + Local process = env->process_object(); + MaybeLocal emit_warning = process->Get(env->context(), + FIXED_ONE_BYTE_STRING(env->isolate(), "emitWarning")); + Local arg = node::OneByteString(env->isolate(), warning); + + Local f; + + if (!emit_warning.ToLocal(&f)) return; + if (!f->IsFunction()) return; + + // MakeCallback() unneeded, because emitWarning is internal code, it calls + // process.emit('warning', ..), but does so on the nextTick. + f.As()->Call(process, 1, &arg); +} + static void Binding(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); diff --git a/src/node_internals.h b/src/node_internals.h index ae284660782cfe..0a65be7642ff2a 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -129,6 +129,8 @@ void AppendExceptionLine(Environment* env, NO_RETURN void FatalError(const char* location, const char* message); +void ProcessEmitWarning(Environment* env, const char* fmt, ...); + v8::Local BuildStatsObject(Environment* env, const uv_stat_t* s); void SetupProcessObject(Environment* env,