mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 07:03:29 +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
|
// 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 {
|
fn checkKey(key: []const u8, token: []const u8) !void {
|
||||||
if (!std.mem.eql(u8, key, token)) return error.WrongToken;
|
if (!std.mem.eql(u8, key, token)) return error.WrongToken;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,16 +134,7 @@ fn evaluate(
|
|||||||
// save script in file at debug mode
|
// save script in file at debug mode
|
||||||
std.log.debug("script {d} length: {d}", .{ id, params.expression.len });
|
std.log.debug("script {d} length: {d}", .{ id, params.expression.len });
|
||||||
if (std.log.defaultLogEnabled(.debug)) {
|
if (std.log.defaultLogEnabled(.debug)) {
|
||||||
const name = try std.fmt.allocPrint(alloc, "id_{d}.js", .{id});
|
try cdp.dumpFile(alloc, id, params.expression);
|
||||||
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 });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// evaluate the script in the context of the current page
|
// evaluate the script in the context of the current page
|
||||||
|
|||||||
Reference in New Issue
Block a user