@@ -86,6 +86,7 @@ pub const Env = struct {
8686 isolate_params : v8.CreateParams ,
8787 hscope : v8.HandleScope ,
8888 globals : v8.FunctionTemplate ,
89+ inspector : ? Inspector = null ,
8990
9091 js_ctx : ? v8.Context = null ,
9192
@@ -152,6 +153,14 @@ pub const Env = struct {
152153 self .* = undefined ;
153154 }
154155
156+ pub fn setInspector (self : * Env , inspector : Inspector ) void {
157+ self .inspector = inspector ;
158+ }
159+
160+ pub fn getInspector (self : Env ) Inspector {
161+ return self .inspector .? ;
162+ }
163+
155164 pub fn setUserContext (self : * Env , userctx : public.UserContext ) anyerror ! void {
156165 self .nat_ctx .userctx = userctx ;
157166 }
@@ -220,6 +229,7 @@ pub const Env = struct {
220229 // Native context
221230 self .nat_ctx .stop ();
222231 }
232+
223233 pub fn getGlobal (self : Env ) anyerror ! Object {
224234 if (self .js_ctx == null ) {
225235 return error .EnvNotStarted ;
@@ -504,3 +514,38 @@ pub fn jsExec(script: []const u8, name: ?[]const u8, isolate: v8.Isolate, js_ctx
504514 const value = scr .run (js_ctx ) catch return error .JSExec ;
505515 return .{ .value = value };
506516}
517+
518+ // Inspector
519+
520+ pub const Inspector = struct {
521+ inner : * v8.Inspector ,
522+ session : v8.InspectorSession ,
523+
524+ pub fn init (
525+ alloc : std.mem.Allocator ,
526+ env : Env ,
527+ ctx : * anyopaque ,
528+ onResp : public.InspectorOnResponseFn ,
529+ onEvent : public.InspectorOnEventFn ,
530+ ) ! Inspector {
531+ const inner = try alloc .create (v8 .Inspector );
532+ const channel = v8 .InspectorChannel .init (ctx , onResp , onEvent , env .isolate );
533+ const client = v8 .InspectorClient .init ();
534+ v8 .Inspector .init (inner , client , channel , env .isolate );
535+ const session = inner .connect ();
536+ return .{ .inner = inner , .session = session };
537+ }
538+
539+ pub fn deinit (self : Inspector , alloc : std.mem.Allocator ) void {
540+ self .inner .deinit ();
541+ alloc .destroy (self .inner );
542+ }
543+
544+ pub fn contextCreated (self : Inspector , env : Env , name : []const u8 , origin : []const u8 , auxData : ? []const u8 ) void {
545+ self .inner .contextCreated (env .js_ctx .? , name , origin , auxData );
546+ }
547+
548+ pub fn send (self : Inspector , msg : []const u8 , env : Env ) void {
549+ return self .session .dispatchProtocolMessage (env .isolate , msg );
550+ }
551+ };
0 commit comments