Skip to content

Commit 98c24c5

Browse files
Inspector: add public interfaces
Signed-off-by: Francis Bouvier <francis@lightpanda.io>
1 parent 47c71d8 commit 98c24c5

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

src/engines/v8/v8.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ pub const Env = struct {
157157
self.inspector = inspector;
158158
}
159159

160-
pub fn getInspector(self: Env) Inspector {
161-
return self.inspector.?;
160+
pub inline fn getInspector(self: Env) ?Inspector {
161+
return self.inspector;
162162
}
163163

164164
pub fn setUserContext(self: *Env, userctx: public.UserContext) anyerror!void {
@@ -527,7 +527,7 @@ pub const Inspector = struct {
527527
ctx: *anyopaque,
528528
onResp: public.InspectorOnResponseFn,
529529
onEvent: public.InspectorOnEventFn,
530-
) !Inspector {
530+
) anyerror!Inspector {
531531
const inner = try alloc.create(v8.Inspector);
532532
const channel = v8.InspectorChannel.init(ctx, onResp, onEvent, env.isolate);
533533
const client = v8.InspectorClient.init();
@@ -545,7 +545,7 @@ pub const Inspector = struct {
545545
self.inner.contextCreated(env.js_ctx.?, name, origin, auxData);
546546
}
547547

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

src/interfaces.zig

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pub fn VM(comptime T: type) void {
4646

4747
pub fn Env(
4848
comptime T: type,
49+
comptime Inspector_T: type,
4950
comptime JSValue_T: type,
5051
comptime Object_T: type,
5152
) void {
@@ -64,6 +65,9 @@ pub fn Env(
6465

6566
assertDecl(T, "bindGlobal", fn (self: *T, ob: anytype) anyerror!void);
6667

68+
assertDecl(T, "setInspector", fn (self: *T, inspector: Inspector_T) void);
69+
assertDecl(T, "getInspector", fn (self: T) callconv(.Inline) ?Inspector_T);
70+
6771
assertDecl(T, "setUserContext", fn (
6872
self: *T,
6973
userctx: public.UserContext,
@@ -192,6 +196,33 @@ pub fn CallbackResult(comptime T: type) void {
192196
// TODO: how to get the result?
193197
}
194198

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

src/private_api.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,13 @@ fn checkInterfaces(engine: anytype) void {
3434
interfaces.VM(engine.VM);
3535
interfaces.Env(
3636
engine.Env,
37+
engine.Inspector,
3738
engine.JSValue,
3839
engine.Object,
3940
);
4041

42+
interfaces.Inspector(engine.Inspector, engine.Env);
43+
4144
// private api
4245
}
4346

0 commit comments

Comments
 (0)