mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-28 22:53:28 +00:00
Add a dumpFile utility function
Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
@@ -108,6 +108,23 @@ pub const State = struct {
|
||||
// Utils
|
||||
// -----
|
||||
|
||||
pub fn dumpFile(
|
||||
alloc: std.mem.Allocator,
|
||||
id: u16,
|
||||
script: []const u8,
|
||||
) !void {
|
||||
const name = try std.fmt.allocPrint(alloc, "id_{d}.js", .{id});
|
||||
defer alloc.free(name);
|
||||
const dir = try std.fs.cwd().makeOpenPath("zig-cache/tmp", .{});
|
||||
const f = try dir.createFile(name, .{});
|
||||
defer f.close();
|
||||
const nb = try f.write(script);
|
||||
std.debug.assert(nb == script.len);
|
||||
const p = try dir.realpathAlloc(alloc, name);
|
||||
defer alloc.free(p);
|
||||
std.log.debug("Script {d} saved at {s}", .{ id, p });
|
||||
}
|
||||
|
||||
fn checkKey(key: []const u8, token: []const u8) !void {
|
||||
if (!std.mem.eql(u8, key, token)) return error.WrongToken;
|
||||
}
|
||||
|
||||
@@ -134,16 +134,7 @@ fn evaluate(
|
||||
// save script in file at debug mode
|
||||
std.log.debug("script {d} length: {d}", .{ id, params.expression.len });
|
||||
if (std.log.defaultLogEnabled(.debug)) {
|
||||
const name = try std.fmt.allocPrint(alloc, "id_{d}.js", .{id});
|
||||
defer alloc.free(name);
|
||||
const dir = try std.fs.cwd().makeOpenPath("zig-cache/tmp", .{});
|
||||
const f = try dir.createFile(name, .{});
|
||||
defer f.close();
|
||||
const nb = try f.write(params.expression);
|
||||
std.debug.assert(nb == params.expression.len);
|
||||
const p = try dir.realpathAlloc(alloc, name);
|
||||
defer alloc.free(p);
|
||||
std.log.debug("Script {d} saved at {s}", .{ id, p });
|
||||
try cdp.dumpFile(alloc, id, params.expression);
|
||||
}
|
||||
|
||||
// evaluate the script in the context of the current page
|
||||
|
||||
Reference in New Issue
Block a user