mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
src: add wrapper for process.emitWarning()
PR-URL: https://github.com/nodejs/node/pull/9139 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
This commit is contained in:
1 parent
1d400ea484
commit
5e07bce166
2 files changed
+29
No files matched your search
+27
@@ -2609,6 +2609,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<Object> process = env->process_object();
|
||||
MaybeLocal<Value> emit_warning = process->Get(env->context(),
|
||||
FIXED_ONE_BYTE_STRING(env->isolate(), "emitWarning"));
|
||||
Local<Value> arg = node::OneByteString(env->isolate(), warning);
|
||||
|
||||
Local<Value> 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<v8::Function>()->Call(process, 1, &arg);
|
||||
}
|
||||
|
||||
|
||||
static void Binding(const FunctionCallbackInfo<Value>& args) {
|
||||
Environment* env = Environment::GetCurrent(args);
|
||||
|
||||
@@ -133,6 +133,8 @@ void AppendExceptionLine(Environment* env,
|
||||
|
||||
NO_RETURN void FatalError(const char* location, const char* message);
|
||||
|
||||
void ProcessEmitWarning(Environment* env, const char* fmt, ...);
|
||||
|
||||
v8::Local<v8::Value> BuildStatsObject(Environment* env, const uv_stat_t* s);
|
||||
|
||||
enum Endianness {
|
||||
|
||||
Reference in new issue
Block a user