@@ -124,8 +124,8 @@ void ExitOnPromiseRejectCallback(PromiseRejectMessage promise_reject_message) {
124
124
func->Call (context->Global (), 5 , args);
125
125
/* message, source, lineno, colno, error */
126
126
} else {
127
- printf ( " Unhandled Promise\n " );
128
- message->PrintCurrentStackTrace (isolate, stdout );
127
+ fprintf (stderr, " Unhandled Promise\n " );
128
+ message->PrintCurrentStackTrace (isolate, stderr );
129
129
}
130
130
131
131
exit (1 );
@@ -336,21 +336,29 @@ int worker_load_module(worker* w, char* name_s, char* source_s, int callback_ind
336
336
return 0 ;
337
337
}
338
338
339
- void Print ( const FunctionCallbackInfo<Value>& args) {
339
+ void Fprint (FILE * out, const FunctionCallbackInfo<Value>& args) {
340
340
bool first = true ;
341
341
for (int i = 0 ; i < args.Length (); i++) {
342
342
HandleScope handle_scope (args.GetIsolate ());
343
343
if (first) {
344
344
first = false ;
345
345
} else {
346
- printf ( " " );
346
+ fprintf (out, " " );
347
347
}
348
348
String::Utf8Value str (args[i]);
349
349
const char * cstr = ToCString (str);
350
- printf ( " %s" , cstr);
350
+ fprintf (out, " %s" , cstr);
351
351
}
352
- printf (" \n " );
353
- fflush (stdout);
352
+ fprintf (out, " \n " );
353
+ fflush (out);
354
+ }
355
+
356
+ void Print (const FunctionCallbackInfo<Value>& args) {
357
+ Fprint (stdout, args);
358
+ }
359
+
360
+ void Log (const FunctionCallbackInfo<Value>& args) {
361
+ Fprint (stderr, args);
354
362
}
355
363
356
364
// Sets the recv callback.
@@ -475,6 +483,9 @@ worker* worker_new(int table_index) {
475
483
v8worker2->Set (String::NewFromUtf8 (w->isolate , " print" ),
476
484
FunctionTemplate::New (w->isolate , Print));
477
485
486
+ v8worker2->Set (String::NewFromUtf8 (w->isolate , " log" ),
487
+ FunctionTemplate::New (w->isolate , Log));
488
+
478
489
v8worker2->Set (String::NewFromUtf8 (w->isolate , " recv" ),
479
490
FunctionTemplate::New (w->isolate , Recv));
480
491
0 commit comments