Skip to content

Commit b43b51e

Browse files
Inspector: add public interfaces
Signed-off-by: Francis Bouvier <francis@lightpanda.io>
1 parent d4d7420 commit b43b51e

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

src/engines/v8/v8.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ pub const Inspector = struct {
525525
ctx: *anyopaque,
526526
onResp: public.InspectorOnResponseFn,
527527
onEvent: public.InspectorOnEventFn,
528-
) !Inspector {
528+
) anyerror!Inspector {
529529
const inner = try alloc.create(v8.Inspector);
530530
const channel = v8.InspectorChannel.init(ctx, onResp, onEvent, env.isolate);
531531
const client = v8.InspectorClient.init();
@@ -543,7 +543,7 @@ pub const Inspector = struct {
543543
self.inner.contextCreated(env.js_ctx.?, name, origin, auxData);
544544
}
545545

546-
pub fn send(self: Inspector, msg: []const u8, env: Env) void {
546+
pub fn send(self: Inspector, env: Env, msg: []const u8) void {
547547
return self.session.dispatchProtocolMessage(env.isolate, msg);
548548
}
549549
};

src/interfaces.zig

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,33 @@ pub fn CallbackResult(comptime T: type) void {
192192
// TODO: how to get the result?
193193
}
194194

195+
pub fn Inspector(comptime T: type, comptime Env_T: type) void {
196+
197+
// init()
198+
assertDecl(T, "init", fn (
199+
alloc: std.mem.Allocator,
200+
env: Env_T,
201+
ctx: *anyopaque,
202+
onResp: public.InspectorOnResponseFn,
203+
onEvent: public.InspectorOnEventFn,
204+
) anyerror!T);
205+
206+
// deinit()
207+
assertDecl(T, "deinit", fn (self: T, alloc: std.mem.Allocator) void);
208+
209+
// contextCreated()
210+
assertDecl(T, "contextCreated", fn (
211+
self: T,
212+
env: Env_T,
213+
name: []const u8,
214+
origin: []const u8,
215+
auxData: ?[]const u8,
216+
) void);
217+
218+
// send()
219+
assertDecl(T, "send", fn (self: T, env: Env_T, msg: []const u8) void);
220+
}
221+
195222
// Utils
196223
// -----
197224

src/private_api.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ fn checkInterfaces(engine: anytype) void {
3838
engine.Object,
3939
);
4040

41+
interfaces.Inspector(engine.Inspector, engine.Env);
42+
4143
// private api
4244
}
4345

0 commit comments

Comments
 (0)