Simplify browser session.setInspector

Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
Francis Bouvier
2024-10-09 00:58:13 +02:00
parent a2f65eb540
commit f9b097794f
2 changed files with 5 additions and 6 deletions

View File

@@ -140,11 +140,12 @@ pub const Session = struct {
pub fn setInspector( pub fn setInspector(
self: *Session, self: *Session,
ctx: *anyopaque, ctx: anytype,
onResp: jsruntime.InspectorOnResponseFn, onResp: jsruntime.InspectorOnResponseFn,
onEvent: jsruntime.InspectorOnEventFn, onEvent: jsruntime.InspectorOnEventFn,
) !void { ) !void {
self.inspector = try jsruntime.Inspector.init(self.alloc, self.env, ctx, onResp, onEvent); const ctx_opaque = @as(*anyopaque, @ptrCast(ctx));
self.inspector = try jsruntime.Inspector.init(self.alloc, self.env, ctx_opaque, onResp, onEvent);
self.env.setInspector(self.inspector.?); self.env.setInspector(self.inspector.?);
} }

View File

@@ -245,8 +245,7 @@ pub const Ctx = struct {
fn newSession(self: *Ctx) !void { fn newSession(self: *Ctx) !void {
try self.browser.newSession(self.alloc(), self.loop); try self.browser.newSession(self.alloc(), self.loop);
const ctx_opaque = @as(*anyopaque, @ptrCast(self)); try self.browser.currentSession().setInspector(self, Ctx.onInspectorResp, Ctx.onInspectorNotif);
try self.browser.currentSession().setInspector(ctx_opaque, Ctx.onInspectorResp, Ctx.onInspectorNotif);
self.sessionNew = true; self.sessionNew = true;
std.log.debug("new session", .{}); std.log.debug("new session", .{});
} }
@@ -380,8 +379,7 @@ pub fn listen(browser: *Browser, loop: *public.Loop, server_socket: std.posix.so
.conn_completion = &conn_completion, .conn_completion = &conn_completion,
.timeout_completion = &timeout_completion, .timeout_completion = &timeout_completion,
}; };
const ctx_opaque = @as(*anyopaque, @ptrCast(ctx)); try browser.currentSession().setInspector(&ctx, Ctx.onInspectorResp, Ctx.onInspectorNotif);
try browser.currentSession().setInspector(ctx_opaque, Ctx.onInspectorResp, Ctx.onInspectorNotif);
// accepting connection asynchronously on internal server // accepting connection asynchronously on internal server
std.log.debug("accepting new conn...", .{}); std.log.debug("accepting new conn...", .{});