@@ -1373,6 +1373,12 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
13731373 return valueToString (scope .call_arena , js_value , scope .isolate , scope .context );
13741374 }
13751375
1376+ pub fn toDetailString (self : JsObject ) ! []const u8 {
1377+ const scope = self .scope ;
1378+ const js_value = self .js_obj .toValue ();
1379+ return valueToDetailString (scope .call_arena , js_value , scope .isolate , scope .context );
1380+ }
1381+
13761382 pub fn format (self : JsObject , comptime _ : []const u8 , _ : std.fmt.FormatOptions , writer : anytype ) ! void {
13771383 return writer .writeAll (try self .toString ());
13781384 }
@@ -2493,6 +2499,15 @@ fn Caller(comptime E: type, comptime State: type) type {
24932499 }
24942500
24952501 fn handleError (self : * Self , comptime Struct : type , comptime named_function : NamedFunction , err : anyerror , info : anytype ) void {
2502+ if (builtin .mode == .Debug and log .enabled (.js , .warn ) and @hasDecl (@TypeOf (info ), "length" )) {
2503+ const args_dump = self .serializeFunctionArgs (info ) catch "failed to serialize args" ;
2504+ log .warn (.js , "function call error" , .{
2505+ .name = named_function .full_name ,
2506+ .err = err ,
2507+ .args = args_dump ,
2508+ });
2509+ }
2510+
24962511 const isolate = self .isolate ;
24972512 var js_err : ? v8.Value = switch (err ) {
24982513 error .InvalidArgument = > createTypeException (isolate , "invalid argument" ),
@@ -2635,15 +2650,6 @@ fn Caller(comptime E: type, comptime State: type) type {
26352650 const last_js_parameter = params_to_map .len - 1 ;
26362651 var is_variadic = false ;
26372652
2638- errdefer | err | if (builtin .mode == .Debug and log .enabled (.js , .warn )) {
2639- const args_dump = self .serializeFunctionArgs (info ) catch "failed to serialize args" ;
2640- log .warn (.js , "function call error" , .{
2641- .name = named_function .full_name ,
2642- .err = err ,
2643- .args = args_dump ,
2644- });
2645- };
2646-
26472653 {
26482654 // This is going to get complicated. If the last Zig paremeter
26492655 // is a slice AND the corresponding javascript parameter is
@@ -2710,6 +2716,7 @@ fn Caller(comptime E: type, comptime State: type) type {
27102716 const isolate = self .isolate ;
27112717 const context = self .context ;
27122718 const arena = self .call_arena ;
2719+ const separator = log .separator ();
27132720 const js_parameter_count = info .length ();
27142721
27152722 var arr : std .ArrayListUnmanaged (u8 ) = .{};
@@ -2718,7 +2725,7 @@ fn Caller(comptime E: type, comptime State: type) type {
27182725 const value_string = try valueToDetailString (arena , js_value , isolate , context );
27192726 const value_type = try jsStringToZig (arena , try js_value .typeOf (isolate ), isolate );
27202727 try std .fmt .format (arr .writer (arena ), "{s}{d}: {s} ({s})" , .{
2721- log . separator () ,
2728+ separator ,
27222729 i + 1 ,
27232730 value_string ,
27242731 value_type ,
@@ -3057,9 +3064,23 @@ const TaggedAnyOpaque = struct {
30573064 subtype : ? SubType ,
30583065};
30593066
3060- fn valueToDetailString (allocator : Allocator , value : v8.Value , isolate : v8.Isolate , context : v8.Context ) ! []u8 {
3061- const str = try value .toDetailString (context );
3062- return jsStringToZig (allocator , str , isolate );
3067+ fn valueToDetailString (arena : Allocator , value : v8.Value , isolate : v8.Isolate , context : v8.Context ) ! []u8 {
3068+ var str : ? v8.String = null ;
3069+ if (value .isObject () and ! value .isFunction ()) {
3070+ str = try v8 .Json .stringify (context , value , null );
3071+
3072+ if (str .? .lenUtf8 (isolate ) == 2 ) {
3073+ // {} isn't useful, null this so that we can get the toDetailString
3074+ // (which might also be useless, but maybe not)
3075+ str = null ;
3076+ }
3077+ }
3078+
3079+ if (str == null ) {
3080+ str = try value .toDetailString (context );
3081+ }
3082+
3083+ return jsStringToZig (arena , str .? , isolate );
30633084}
30643085
30653086fn valueToString (allocator : Allocator , value : v8.Value , isolate : v8.Isolate , context : v8.Context ) ! []u8 {
0 commit comments