summaryrefslogtreecommitdiff
path: root/libdeno
diff options
context:
space:
mode:
authorKevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com>2018-09-25 01:27:02 -0400
committerRyan Dahl <ry@tinyclouds.org>2018-09-25 01:27:02 -0400
commitf156a86024fc98e63f42c1c7acccac0af10950ef (patch)
treec024ecd75f5574e412eba937b1a46d8a0232e234 /libdeno
parentad5065e23ec33af1422eeffdbb877ef8fd5f6da4 (diff)
console.warn goes to stderr (#810)
Diffstat (limited to 'libdeno')
-rw-r--r--libdeno/binding.cc12
-rw-r--r--libdeno/libdeno_test.js2
2 files changed, 10 insertions, 4 deletions
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<v8::Value>& args) {
- CHECK_EQ(args.Length(), 1);
+ CHECK_GE(args.Length(), 1);
+ CHECK_LE(args.Length(), 2);
auto* isolate = args.GetIsolate();
+ Deno* d = static_cast<Deno*>(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<v8::Uint8Array> 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);