diff --git a/src/engines/v8/v8.zig b/src/engines/v8/v8.zig index bf9ca9a..6b50005 100644 --- a/src/engines/v8/v8.zig +++ b/src/engines/v8/v8.zig @@ -525,7 +525,7 @@ pub const Inspector = struct { ctx: *anyopaque, onResp: public.InspectorOnResponseFn, onEvent: public.InspectorOnEventFn, - ) !Inspector { + ) anyerror!Inspector { const inner = try alloc.create(v8.Inspector); const channel = v8.InspectorChannel.init(ctx, onResp, onEvent, env.isolate); const client = v8.InspectorClient.init(); @@ -543,7 +543,7 @@ pub const Inspector = struct { self.inner.contextCreated(env.js_ctx.?, name, origin, auxData); } - pub fn send(self: Inspector, msg: []const u8, env: Env) void { + pub fn send(self: Inspector, env: Env, msg: []const u8) void { return self.session.dispatchProtocolMessage(env.isolate, msg); } }; diff --git a/src/interfaces.zig b/src/interfaces.zig index 1d7db3c..3dd3636 100644 --- a/src/interfaces.zig +++ b/src/interfaces.zig @@ -192,6 +192,33 @@ pub fn CallbackResult(comptime T: type) void { // TODO: how to get the result? } +pub fn Inspector(comptime T: type, comptime Env_T: type) void { + + // init() + assertDecl(T, "init", fn ( + alloc: std.mem.Allocator, + env: Env_T, + ctx: *anyopaque, + onResp: public.InspectorOnResponseFn, + onEvent: public.InspectorOnEventFn, + ) anyerror!T); + + // deinit() + assertDecl(T, "deinit", fn (self: T, alloc: std.mem.Allocator) void); + + // contextCreated() + assertDecl(T, "contextCreated", fn ( + self: T, + env: Env_T, + name: []const u8, + origin: []const u8, + auxData: ?[]const u8, + ) void); + + // send() + assertDecl(T, "send", fn (self: T, env: Env_T, msg: []const u8) void); +} + // Utils // ----- diff --git a/src/private_api.zig b/src/private_api.zig index 57703f4..be43c1e 100644 --- a/src/private_api.zig +++ b/src/private_api.zig @@ -38,6 +38,8 @@ fn checkInterfaces(engine: anytype) void { engine.Object, ); + interfaces.Inspector(engine.Inspector, engine.Env); + // private api }