Skip to content

Introduce InspectorSession #284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions src/engines/v8/v8.zig
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ pub fn jsExec(script: []const u8, name: ?[]const u8, isolate: v8.Isolate, js_ctx

pub const Inspector = struct {
inner: *v8.Inspector,
session: v8.InspectorSession,
session: InspectorSession,

pub fn init(
alloc: std.mem.Allocator,
Expand All @@ -662,8 +662,10 @@ pub const Inspector = struct {
const channel = v8.InspectorChannel.init(ctx, onResp, onEvent, env.isolate);
const client = v8.InspectorClient.init();
v8.Inspector.init(inner, client, channel, env.isolate);
const session = inner.connect();
return .{ .inner = inner, .session = session };
return .{
.inner = inner,
.session = .{ .inner = inner.connect() },
};
}

pub fn deinit(self: Inspector, alloc: std.mem.Allocator) void {
Expand Down Expand Up @@ -691,7 +693,22 @@ pub const Inspector = struct {
// msg should be formatted for the Inspector protocol
// for v8 it's the CDP protocol https://chromedevtools.github.io/devtools-protocol/
// with only some domains being relevant (mainly Runtime and Debugger)
pub fn send(self: Inspector, env: Env, msg: []const u8) void {
return self.session.dispatchProtocolMessage(env.isolate, msg);
pub fn send(self: Inspector, env: *const Env, msg: []const u8) void {
self.session.send(env, msg);
}

pub fn createSession(self: Inspector) InspectorSession {
return .{ .inner = self.inner.connect() };
}
};

pub const InspectorSession = struct {
inner: v8.InspectorSession,

// msg should be formatted for the Inspector protocol
// for v8 it's the CDP protocol https://chromedevtools.github.io/devtools-protocol/
// with only some domains being relevant (mainly Runtime and Debugger)
pub fn send(self: InspectorSession, env: *const Env, msg: []const u8) void {
return self.inner.dispatchProtocolMessage(env.isolate, msg);
}
};
2 changes: 1 addition & 1 deletion src/interfaces.zig
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ pub fn Inspector(comptime T: type, comptime Env_T: type) void {
) void);

// send()
assertDecl(T, "send", fn (self: T, env: Env_T, msg: []const u8) void);
assertDecl(T, "send", fn (self: T, env: *const Env_T, msg: []const u8) void);
}

// Utils
Expand Down