Skip to content

Commit

Permalink
Inspector: add public interfaces
Browse files Browse the repository at this point in the history
Signed-off-by: Francis Bouvier <[email protected]>
  • Loading branch information
francisbouvier committed Sep 30, 2024
1 parent d4d7420 commit b43b51e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/engines/v8/v8.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
};
27 changes: 27 additions & 0 deletions src/interfaces.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
// -----

Expand Down
2 changes: 2 additions & 0 deletions src/private_api.zig
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ fn checkInterfaces(engine: anytype) void {
engine.Object,
);

interfaces.Inspector(engine.Inspector, engine.Env);

// private api
}

Expand Down

0 comments on commit b43b51e

Please sign in to comment.