@@ -1083,6 +1083,13 @@ static JSValue js_std_file_printf(JSContext *ctx, JSValueConst this_val,
1083
1083
return js_printf_internal (ctx , argc , argv , f );
1084
1084
}
1085
1085
1086
+ static JSValue js_std_file_printObject (JSContext * ctx , JSValueConst this_val ,
1087
+ int argc , JSValueConst * argv )
1088
+ {
1089
+ JS_PrintValue (ctx , stdout , argv [0 ], NULL );
1090
+ return JS_UNDEFINED ;
1091
+ }
1092
+
1086
1093
static JSValue js_std_file_flush (JSContext * ctx , JSValueConst this_val ,
1087
1094
int argc , JSValueConst * argv )
1088
1095
{
@@ -1540,6 +1547,7 @@ static const JSCFunctionListEntry js_std_funcs[] = {
1540
1547
JS_PROP_INT32_DEF ("SEEK_CUR" , SEEK_CUR , JS_PROP_CONFIGURABLE ),
1541
1548
JS_PROP_INT32_DEF ("SEEK_END" , SEEK_END , JS_PROP_CONFIGURABLE ),
1542
1549
JS_OBJECT_DEF ("Error" , js_std_error_props , countof (js_std_error_props ), JS_PROP_CONFIGURABLE ),
1550
+ JS_CFUNC_DEF ("__printObject" , 1 , js_std_file_printObject ),
1543
1551
};
1544
1552
1545
1553
static const JSCFunctionListEntry js_std_file_proto_funcs [] = {
@@ -3891,17 +3899,23 @@ static JSValue js_print(JSContext *ctx, JSValueConst this_val,
3891
3899
int argc , JSValueConst * argv )
3892
3900
{
3893
3901
int i ;
3894
- const char * str ;
3895
- size_t len ;
3896
-
3902
+ JSValueConst v ;
3903
+
3897
3904
for (i = 0 ; i < argc ; i ++ ) {
3898
3905
if (i != 0 )
3899
3906
putchar (' ' );
3900
- str = JS_ToCStringLen (ctx , & len , argv [i ]);
3901
- if (!str )
3902
- return JS_EXCEPTION ;
3903
- fwrite (str , 1 , len , stdout );
3904
- JS_FreeCString (ctx , str );
3907
+ v = argv [i ];
3908
+ if (JS_IsString (v )) {
3909
+ const char * str ;
3910
+ size_t len ;
3911
+ str = JS_ToCStringLen (ctx , & len , v );
3912
+ if (!str )
3913
+ return JS_EXCEPTION ;
3914
+ fwrite (str , 1 , len , stdout );
3915
+ JS_FreeCString (ctx , str );
3916
+ } else {
3917
+ JS_PrintValue (ctx , stdout , v , NULL );
3918
+ }
3905
3919
}
3906
3920
putchar ('\n' );
3907
3921
return JS_UNDEFINED ;
@@ -4012,33 +4026,10 @@ void js_std_free_handlers(JSRuntime *rt)
4012
4026
JS_SetRuntimeOpaque (rt , NULL ); /* fail safe */
4013
4027
}
4014
4028
4015
- static void js_dump_obj (JSContext * ctx , FILE * f , JSValueConst val )
4016
- {
4017
- const char * str ;
4018
-
4019
- str = JS_ToCString (ctx , val );
4020
- if (str ) {
4021
- fprintf (f , "%s\n" , str );
4022
- JS_FreeCString (ctx , str );
4023
- } else {
4024
- fprintf (f , "[exception]\n" );
4025
- }
4026
- }
4027
-
4028
4029
static void js_std_dump_error1 (JSContext * ctx , JSValueConst exception_val )
4029
4030
{
4030
- JSValue val ;
4031
- BOOL is_error ;
4032
-
4033
- is_error = JS_IsError (ctx , exception_val );
4034
- js_dump_obj (ctx , stderr , exception_val );
4035
- if (is_error ) {
4036
- val = JS_GetPropertyStr (ctx , exception_val , "stack" );
4037
- if (!JS_IsUndefined (val )) {
4038
- js_dump_obj (ctx , stderr , val );
4039
- }
4040
- JS_FreeValue (ctx , val );
4041
- }
4031
+ JS_PrintValue (ctx , stderr , exception_val , NULL );
4032
+ fputc ('\n' , stderr );
4042
4033
}
4043
4034
4044
4035
void js_std_dump_error (JSContext * ctx )
0 commit comments