Skip to content

Commit f9b0977

Browse files
Simplify browser session.setInspector
Signed-off-by: Francis Bouvier <[email protected]>
1 parent a2f65eb commit f9b0977

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/browser/browser.zig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,12 @@ pub const Session = struct {
140140

141141
pub fn setInspector(
142142
self: *Session,
143-
ctx: *anyopaque,
143+
ctx: anytype,
144144
onResp: jsruntime.InspectorOnResponseFn,
145145
onEvent: jsruntime.InspectorOnEventFn,
146146
) !void {
147-
self.inspector = try jsruntime.Inspector.init(self.alloc, self.env, ctx, onResp, onEvent);
147+
const ctx_opaque = @as(*anyopaque, @ptrCast(ctx));
148+
self.inspector = try jsruntime.Inspector.init(self.alloc, self.env, ctx_opaque, onResp, onEvent);
148149
self.env.setInspector(self.inspector.?);
149150
}
150151

src/server.zig

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,7 @@ pub const Ctx = struct {
245245

246246
fn newSession(self: *Ctx) !void {
247247
try self.browser.newSession(self.alloc(), self.loop);
248-
const ctx_opaque = @as(*anyopaque, @ptrCast(self));
249-
try self.browser.currentSession().setInspector(ctx_opaque, Ctx.onInspectorResp, Ctx.onInspectorNotif);
248+
try self.browser.currentSession().setInspector(self, Ctx.onInspectorResp, Ctx.onInspectorNotif);
250249
self.sessionNew = true;
251250
std.log.debug("new session", .{});
252251
}
@@ -380,8 +379,7 @@ pub fn listen(browser: *Browser, loop: *public.Loop, server_socket: std.posix.so
380379
.conn_completion = &conn_completion,
381380
.timeout_completion = &timeout_completion,
382381
};
383-
const ctx_opaque = @as(*anyopaque, @ptrCast(ctx));
384-
try browser.currentSession().setInspector(ctx_opaque, Ctx.onInspectorResp, Ctx.onInspectorNotif);
382+
try browser.currentSession().setInspector(&ctx, Ctx.onInspectorResp, Ctx.onInspectorNotif);
385383

386384
// accepting connection asynchronously on internal server
387385
std.log.debug("accepting new conn...", .{});

0 commit comments

Comments
 (0)