mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-30 07:31:47 +00:00
Make getParams return nullable
Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
@@ -67,7 +67,6 @@ fn browserSetDownloadBehavior(
|
|||||||
downloadPath: ?[]const u8 = null,
|
downloadPath: ?[]const u8 = null,
|
||||||
eventsEnabled: ?bool = null,
|
eventsEnabled: ?bool = null,
|
||||||
};
|
};
|
||||||
const params = try getParams(alloc, Params, scanner);
|
_ = try getParams(alloc, Params, scanner);
|
||||||
std.log.debug("params {any}", .{params});
|
|
||||||
return result(alloc, id, null, null, null);
|
return result(alloc, id, null, null, null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,13 +125,22 @@ pub fn getParams(
|
|||||||
alloc: std.mem.Allocator,
|
alloc: std.mem.Allocator,
|
||||||
comptime T: type,
|
comptime T: type,
|
||||||
scanner: *std.json.Scanner,
|
scanner: *std.json.Scanner,
|
||||||
) !T {
|
) !?T {
|
||||||
try checkKey("params", (try scanner.next()).string);
|
|
||||||
|
// if next token is the end of the object, there is no "params"
|
||||||
|
const t = try scanner.next();
|
||||||
|
if (t == .object_end) return null;
|
||||||
|
|
||||||
|
// if next token is not "params" there is no "params"
|
||||||
|
if (!std.mem.eql(u8, "params", t.string)) return null;
|
||||||
|
|
||||||
|
// parse "params"
|
||||||
const options = std.json.ParseOptions{
|
const options = std.json.ParseOptions{
|
||||||
.max_value_len = scanner.input.len,
|
.max_value_len = scanner.input.len,
|
||||||
.allocate = .alloc_if_needed,
|
.allocate = .alloc_if_needed,
|
||||||
};
|
};
|
||||||
return std.json.innerParse(T, alloc, scanner, options);
|
const params = try std.json.innerParse(T, alloc, scanner, options);
|
||||||
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getSessionID(scanner: *std.json.Scanner) !?[]const u8 {
|
pub fn getSessionID(scanner: *std.json.Scanner) !?[]const u8 {
|
||||||
|
|||||||
Reference in New Issue
Block a user