@@ -562,3 +562,47 @@ fn debugValueToString(arena: Allocator, js_obj: v8.Object, isolate: v8.Isolate,
562562 }
563563 return arr .items ;
564564}
565+
566+ // These are here, and not in Inspector.zig, because Inspector.zig isn't always
567+ // included (e.g. in the wpt build).
568+
569+ // This is called from V8. Whenever the v8 inspector has to describe a value
570+ // it'll call this function to gets its [optional] subtype - which, from V8's
571+ // point of view, is an arbitrary string.
572+ pub export fn v8_inspector__Client__IMPL__valueSubtype (
573+ _ : * v8.c.InspectorClientImpl ,
574+ c_value : * const v8.C_Value ,
575+ ) callconv (.c ) [* c ]const u8 {
576+ const external_entry = getTaggedAnyOpaque (.{ .handle = c_value }) orelse return null ;
577+ return if (external_entry .subtype ) | st | @tagName (st ) else null ;
578+ }
579+
580+ // Same as valueSubType above, but for the optional description field.
581+ // From what I can tell, some drivers _need_ the description field to be
582+ // present, even if it's empty. So if we have a subType for the value, we'll
583+ // put an empty description.
584+ pub export fn v8_inspector__Client__IMPL__descriptionForValueSubtype (
585+ _ : * v8.c.InspectorClientImpl ,
586+ v8_context : * const v8.C_Context ,
587+ c_value : * const v8.C_Value ,
588+ ) callconv (.c ) [* c ]const u8 {
589+ _ = v8_context ;
590+
591+ // We _must_ include a non-null description in order for the subtype value
592+ // to be included. Besides that, I don't know if the value has any meaning
593+ const external_entry = getTaggedAnyOpaque (.{ .handle = c_value }) orelse return null ;
594+ return if (external_entry .subtype == null ) null else "" ;
595+ }
596+
597+ fn getTaggedAnyOpaque (value : v8.Value ) ? * TaggedAnyOpaque {
598+ if (value .isObject () == false ) {
599+ return null ;
600+ }
601+ const obj = value .castTo (v8 .Object );
602+ if (obj .internalFieldCount () == 0 ) {
603+ return null ;
604+ }
605+
606+ const external_data = obj .getInternalField (0 ).castTo (v8 .External ).get ().? ;
607+ return @ptrCast (@alignCast (external_data ));
608+ }
0 commit comments