mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 07:03:29 +00:00
Remove alloc from CmdContext struct
Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
@@ -9,7 +9,6 @@ pub var socket_fd: std.os.socket_t = undefined;
|
|||||||
|
|
||||||
// I/O input command context
|
// I/O input command context
|
||||||
pub const CmdContext = struct {
|
pub const CmdContext = struct {
|
||||||
alloc: std.mem.Allocator,
|
|
||||||
js_env: *public.Env,
|
js_env: *public.Env,
|
||||||
socket: std.os.socket_t,
|
socket: std.os.socket_t,
|
||||||
completion: *public.IO.Completion,
|
completion: *public.IO.Completion,
|
||||||
@@ -18,7 +17,10 @@ pub const CmdContext = struct {
|
|||||||
|
|
||||||
try_catch: public.TryCatch,
|
try_catch: public.TryCatch,
|
||||||
|
|
||||||
// cmds: cdp.Cmds,
|
// shortcuts
|
||||||
|
fn alloc(self: *CmdContext) std.mem.Allocator {
|
||||||
|
return self.js_env.nat_ctx.alloc;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fn respCallback(
|
fn respCallback(
|
||||||
@@ -34,6 +36,11 @@ fn respCallback(
|
|||||||
std.log.debug("send ok", .{});
|
std.log.debug("send ok", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn send(ctx: *CmdContext, msg: []const u8) !void {
|
||||||
|
defer ctx.alloc().free(msg);
|
||||||
|
return osSend(ctx, msg);
|
||||||
|
}
|
||||||
|
|
||||||
pub const SendFn = (fn (*CmdContext, []const u8) anyerror!void);
|
pub const SendFn = (fn (*CmdContext, []const u8) anyerror!void);
|
||||||
|
|
||||||
fn osSend(ctx: *CmdContext, msg: []const u8) !void {
|
fn osSend(ctx: *CmdContext, msg: []const u8) !void {
|
||||||
@@ -85,13 +92,12 @@ fn cmdCallback(
|
|||||||
}
|
}
|
||||||
|
|
||||||
std.debug.print("input {s}\n", .{input});
|
std.debug.print("input {s}\n", .{input});
|
||||||
const res = cdp.do(ctx.alloc, input, ctx, osSend) catch |err| {
|
const res = cdp.do(ctx.alloc(), input, ctx, osSend) catch |err| {
|
||||||
std.log.debug("error: {any}\n", .{err});
|
std.log.debug("error: {any}\n", .{err});
|
||||||
loopSend(ctx, "{}") catch unreachable;
|
loopSend(ctx, "{}") catch unreachable;
|
||||||
// TODO: return proper error
|
// TODO: return proper error
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
defer ctx.alloc.free(res);
|
|
||||||
std.log.debug("res {s}", .{res});
|
std.log.debug("res {s}", .{res});
|
||||||
|
|
||||||
osSend(ctx, res) catch unreachable;
|
osSend(ctx, res) catch unreachable;
|
||||||
@@ -189,7 +195,6 @@ pub fn execJS(
|
|||||||
var completion: public.IO.Completion = undefined;
|
var completion: public.IO.Completion = undefined;
|
||||||
var input: [1024]u8 = undefined;
|
var input: [1024]u8 = undefined;
|
||||||
var cmd_ctx = CmdContext{
|
var cmd_ctx = CmdContext{
|
||||||
.alloc = alloc,
|
|
||||||
.js_env = js_env,
|
.js_env = js_env,
|
||||||
.socket = undefined,
|
.socket = undefined,
|
||||||
.buf = &input,
|
.buf = &input,
|
||||||
|
|||||||
Reference in New Issue
Block a user