From f156a86024fc98e63f42c1c7acccac0af10950ef Mon Sep 17 00:00:00 2001 From: "Kevin (Kun) \"Kassimo\" Qian" Date: Tue, 25 Sep 2018 01:27:02 -0400 Subject: console.warn goes to stderr (#810) --- libdeno/binding.cc | 12 +++++++++--- libdeno/libdeno_test.js | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'libdeno') diff --git a/libdeno/binding.cc b/libdeno/binding.cc index bc155b6db..b3c59c3ec 100644 --- a/libdeno/binding.cc +++ b/libdeno/binding.cc @@ -141,13 +141,19 @@ void ExitOnPromiseRejectCallback( } void Print(const v8::FunctionCallbackInfo& args) { - CHECK_EQ(args.Length(), 1); + CHECK_GE(args.Length(), 1); + CHECK_LE(args.Length(), 2); auto* isolate = args.GetIsolate(); + Deno* d = static_cast(isolate->GetData(0)); + auto context = d->context.Get(d->isolate); v8::HandleScope handle_scope(isolate); v8::String::Utf8Value str(isolate, args[0]); + bool is_err = + args.Length() >= 2 ? args[1]->BooleanValue(context).ToChecked() : false; const char* cstr = ToCString(str); - printf("%s\n", cstr); - fflush(stdout); + auto stream = is_err ? stderr : stdout; + fprintf(stream, "%s\n", cstr); + fflush(stream); } static v8::Local ImportBuf(v8::Isolate* isolate, deno_buf buf) { diff --git a/libdeno/libdeno_test.js b/libdeno/libdeno_test.js index ec8e4c752..e0d1d7252 100644 --- a/libdeno/libdeno_test.js +++ b/libdeno/libdeno_test.js @@ -112,7 +112,7 @@ global.SnapshotBug = () => { global.GlobalErrorHandling = () => { libdeno.setGlobalErrorHandler((message, source, line, col, error) => { - libdeno.print(`line ${line} col ${col}`); + libdeno.print(`line ${line} col ${col}`, true); assert("ReferenceError: notdefined is not defined" === message); assert(source === "helloworld.js"); assert(line === 3); -- cgit v1.2.3