@@ -3875,15 +3875,42 @@ JSModuleDef *js_init_module_os(JSContext *ctx, const char *module_name)
3875
3875
3876
3876
/**********************************************************/
3877
3877
3878
+ #ifdef _WIN32
3878
3879
static JSValue js_print (JSContext * ctx , JSValue this_val ,
3879
3880
int argc , JSValue * argv )
3880
3881
{
3881
3882
int i ;
3882
3883
const char * str ;
3883
3884
size_t len ;
3884
-
3885
+ DWORD written ;
3886
+ HANDLE hConsole = GetStdHandle (STD_OUTPUT_HANDLE );
3887
+ if (hConsole == INVALID_HANDLE_VALUE )
3888
+ return JS_EXCEPTION ;
3885
3889
for (i = 0 ; i < argc ; i ++ ) {
3886
3890
if (i != 0 )
3891
+ WriteConsoleW (hConsole , L" " , 1 , & written , NULL );
3892
+ str = JS_ToCStringLen (ctx , & len , argv [i ]);
3893
+ if (!str )
3894
+ return JS_EXCEPTION ;
3895
+ DWORD prev = GetConsoleOutputCP ();
3896
+ SetConsoleOutputCP (CP_UTF8 );
3897
+ WriteConsoleA (hConsole , str , len , & written , NULL );
3898
+ SetConsoleOutputCP (prev );
3899
+ JS_FreeCString (ctx , str );
3900
+ }
3901
+ WriteConsoleW (hConsole , L"\n" , 1 , & written , NULL );
3902
+ FlushFileBuffers (hConsole );
3903
+ return JS_UNDEFINED ;
3904
+ }
3905
+ #else
3906
+ static JSValue js_print (JSContext * ctx , JSValue this_val ,
3907
+ int argc , JSValue * argv )
3908
+ {
3909
+ int i ;
3910
+ const char * str ;
3911
+ size_t len ;
3912
+ for (i = 0 ; i < argc ; i ++ ) {
3913
+ if (i != 0 )
3887
3914
putchar (' ' );
3888
3915
str = JS_ToCStringLen (ctx , & len , argv [i ]);
3889
3916
if (!str )
@@ -3895,6 +3922,7 @@ static JSValue js_print(JSContext *ctx, JSValue this_val,
3895
3922
fflush (stdout );
3896
3923
return JS_UNDEFINED ;
3897
3924
}
3925
+ #endif
3898
3926
3899
3927
void js_std_add_helpers (JSContext * ctx , int argc , char * * argv )
3900
3928
{
0 commit comments