@@ -915,14 +915,16 @@ pub const Formatter = struct {
915915 JSON ,
916916 toJSON ,
917917 NativeCode ,
918- ArrayBuffer ,
919918
920919 JSX ,
921920 Event ,
922921
923922 GetterSetter ,
924923 CustomGetterSetter ,
925924
925+ Proxy ,
926+ RevokedProxy ,
927+ 926928 pub fn isPrimitive (this : Tag ) bool {
927929 return switch (this ) {
928930 .String ,
@@ -971,15 +973,20 @@ pub const Formatter = struct {
971973 JSON : void ,
972974 toJSON : void ,
973975 NativeCode : void ,
974- ArrayBuffer : void ,
975976 JSX : void ,
976977 Event : void ,
977978 GetterSetter : void ,
978979 CustomGetterSetter : void ,
980+ Proxy : void ,
981+ RevokedProxy : void ,
979982
980983 pub fn isPrimitive (this : @This ()) bool {
981984 return @as (Tag , this ).isPrimitive ();
982985 }
986+ 987+ pub fn tag (this : @This ()) Tag {
988+ return @as (Tag , this );
989+ }
983990 },
984991 cell : JSValue.JSType = JSValue .JSType .Cell ,
985992 };
@@ -1126,10 +1133,17 @@ pub const Formatter = struct {
11261133
11271134 .Object ,
11281135 .FinalObject ,
1129- .ProxyObject ,
11301136 .ModuleNamespaceObject ,
11311137 = > .Object ,
11321138
1139+ .ProxyObject = > tag : {
1140+ const handler = value .getProxyInternalField (.handler );
1141+ if (handler == .zero or handler == .undefined or handler == .null ) {
1142+ break :tag .RevokedProxy ;
1143+ }
1144+ break :tag .Proxy ;
1145+ },
1146+ 11331147 .GlobalObject = > if (! opts .hide_global )
11341148 .Object
11351149 else
@@ -2877,7 +2891,20 @@ pub const Formatter = struct {
28772891
28782892 writer .writeAll (" ]" );
28792893 },
2880- else = > {},
2894+ .RevokedProxy = > {
2895+ this .addForNewLine ("<Revoked Proxy>" .len );
2896+ writer .print (comptime Output .prettyFmt ("<r><cyan>\\ <Revoked Proxy\\ ><r>" , enable_ansi_colors ), .{});
2897+ },
2898+ .Proxy = > {
2899+ const target = value .getProxyInternalField (.target );
2900+ if (Environment .allow_assert ) {
2901+ // Proxy does not allow non-objects here.
2902+ std .debug .assert (target .isCell ());
2903+ }
2904+ // TODO: if (options.showProxy), print like `Proxy { target: ..., handlers: ... }`
2905+ // this is default off so it is not used.
2906+ this .format (ConsoleObject .Formatter .Tag .get (target , this .globalThis ), Writer , writer_ , target , this .globalThis , enable_ansi_colors );
2907+ },
28812908 }
28822909 }
28832910
@@ -2908,9 +2935,6 @@ pub const Formatter = struct {
29082935 }
29092936
29102937 pub fn format (this : * ConsoleObject.Formatter , result : Tag.Result , comptime Writer : type , writer : Writer , value : JSValue , globalThis : * JSGlobalObject , comptime enable_ansi_colors : bool ) void {
2911- if (comptime is_bindgen ) {
2912- return ;
2913- }
29142938 const prevGlobalThis = this .globalThis ;
29152939 defer this .globalThis = prevGlobalThis ;
29162940 this .globalThis = globalThis ;
@@ -2919,44 +2943,11 @@ pub const Formatter = struct {
29192943 // comptime var so we have to repeat it here. The rationale there is
29202944 // it _should_ limit the stack usage because each version of the
29212945 // function will be relatively small
2922- switch (result .tag ) {
2923- .StringPossiblyFormatted = > this .printAs (.StringPossiblyFormatted , Writer , writer , value , result .cell , enable_ansi_colors ),
2924- .String = > this .printAs (.String , Writer , writer , value , result .cell , enable_ansi_colors ),
2925- .Undefined = > this .printAs (.Undefined , Writer , writer , value , result .cell , enable_ansi_colors ),
2926- .Double = > this .printAs (.Double , Writer , writer , value , result .cell , enable_ansi_colors ),
2927- .Integer = > this .printAs (.Integer , Writer , writer , value , result .cell , enable_ansi_colors ),
2928- .Null = > this .printAs (.Null , Writer , writer , value , result .cell , enable_ansi_colors ),
2929- .Boolean = > this .printAs (.Boolean , Writer , writer , value , result .cell , enable_ansi_colors ),
2930- .Array = > this .printAs (.Array , Writer , writer , value , result .cell , enable_ansi_colors ),
2931- .Object = > this .printAs (.Object , Writer , writer , value , result .cell , enable_ansi_colors ),
2932- .Function = > this .printAs (.Function , Writer , writer , value , result .cell , enable_ansi_colors ),
2933- .Class = > this .printAs (.Class , Writer , writer , value , result .cell , enable_ansi_colors ),
2934- .Error = > this .printAs (.Error , Writer , writer , value , result .cell , enable_ansi_colors ),
2935- .ArrayBuffer , .TypedArray = > this .printAs (.TypedArray , Writer , writer , value , result .cell , enable_ansi_colors ),
2936- .Map = > this .printAs (.Map , Writer , writer , value , result .cell , enable_ansi_colors ),
2937- .MapIterator = > this .printAs (.MapIterator , Writer , writer , value , result .cell , enable_ansi_colors ),
2938- .SetIterator = > this .printAs (.SetIterator , Writer , writer , value , result .cell , enable_ansi_colors ),
2939- .Set = > this .printAs (.Set , Writer , writer , value , result .cell , enable_ansi_colors ),
2940- .Symbol = > this .printAs (.Symbol , Writer , writer , value , result .cell , enable_ansi_colors ),
2941- .BigInt = > this .printAs (.BigInt , Writer , writer , value , result .cell , enable_ansi_colors ),
2942- .GlobalObject = > this .printAs (.GlobalObject , Writer , writer , value , result .cell , enable_ansi_colors ),
2943- .Private = > this .printAs (.Private , Writer , writer , value , result .cell , enable_ansi_colors ),
2944- .Promise = > this .printAs (.Promise , Writer , writer , value , result .cell , enable_ansi_colors ),
2945- 2946- // Call JSON.stringify on the value
2947- .JSON = > this .printAs (.JSON , Writer , writer , value , result .cell , enable_ansi_colors ),
2948- 2949- // Call value.toJSON() and print as an object
2950- .toJSON = > this .printAs (.toJSON , Writer , writer , value , result .cell , enable_ansi_colors ),
2951- 2952- .NativeCode = > this .printAs (.NativeCode , Writer , writer , value , result .cell , enable_ansi_colors ),
2953- .JSX = > this .printAs (.JSX , Writer , writer , value , result .cell , enable_ansi_colors ),
2954- .Event = > this .printAs (.Event , Writer , writer , value , result .cell , enable_ansi_colors ),
2955- .GetterSetter = > this .printAs (.GetterSetter , Writer , writer , value , result .cell , enable_ansi_colors ),
2956- .CustomGetterSetter = > this .printAs (.CustomGetterSetter , Writer , writer , value , result .cell , enable_ansi_colors ),
2957- 2958- .CustomFormattedObject = > | callback | {
2959- this .custom_formatted_object = callback ;
2946+ switch (result .tag .tag ()) {
2947+ inline else = > | tag | this .printAs (tag , Writer , writer , value , result .cell , enable_ansi_colors ),
2948+ 2949+ .CustomFormattedObject = > {
2950+ this .custom_formatted_object = result .tag .CustomFormattedObject ;
29602951 this .printAs (.CustomFormattedObject , Writer , writer , value , result .cell , enable_ansi_colors );
29612952 },
29622953 }
0 commit comments