diff --git a/src/main.zig b/src/main.zig index 2dd6403c..7850c00f 100644 --- a/src/main.zig +++ b/src/main.zig @@ -61,7 +61,10 @@ pub fn main() !void { defer arena.deinit(); // document - doc = try parser.documentHTMLParseFromFileAlloc(arena.allocator(), "test.html"); + const file = try std.fs.cwd().openFile("test.html", .{}); + defer file.close(); + + doc = try parser.documentHTMLParseFromFile(file); defer parser.documentHTMLClose(doc) catch |err| { std.debug.print("documentHTMLClose error: {s}\n", .{@errorName(err)}); }; diff --git a/src/main_shell.zig b/src/main_shell.zig index 762e97fd..066d2051 100644 --- a/src/main_shell.zig +++ b/src/main_shell.zig @@ -42,7 +42,10 @@ pub fn main() !void { defer arena.deinit(); // document - doc = try parser.documentHTMLParseFromFileAlloc(arena.allocator(), "test.html"); + const file = try std.fs.cwd().openFile("test.html", .{}); + defer file.close(); + + doc = try parser.documentHTMLParseFromFile(file); defer parser.documentHTMLClose(doc) catch |err| { std.debug.print("documentHTMLClose error: {s}\n", .{@errorName(err)}); }; diff --git a/src/netsurf.zig b/src/netsurf.zig index 3d2ded24..86fccb2f 100644 --- a/src/netsurf.zig +++ b/src/netsurf.zig @@ -1281,21 +1281,9 @@ fn documentHTMLVtable(doc_html: *DocumentHTML) c.dom_html_document_vtable { return getVtable(c.dom_html_document_vtable, DocumentHTML, doc_html); } -// documentHTMLParseFromFileAlloc parses the file. -// The allocator is required to create a null terminated string from filename. -// The buffer is freed by the function. -// The caller is responsible for closing the document. -// DEPRECATED -pub fn documentHTMLParseFromFileAlloc(_: std.mem.Allocator, filename: []const u8) !*DocumentHTML { - return documentHTMLParseFromFile(filename); -} - // documentHTMLParseFromFile parses the given HTML file. // The caller is responsible for closing the document. -pub fn documentHTMLParseFromFile(filename: []const u8) !*DocumentHTML { - const file = try std.fs.openFileAbsolute(filename, .{}); - defer file.close(); - +pub fn documentHTMLParseFromFile(file: std.fs.File) !*DocumentHTML { var parser: ?*c.dom_hubbub_parser = undefined; var doc: ?*c.dom_document = undefined; var err: c.hubbub_error = undefined; @@ -1334,15 +1322,6 @@ pub fn documentHTMLParseFromFile(filename: []const u8) !*DocumentHTML { return @as(*DocumentHTML, @ptrCast(doc.?)); } -// documentHTMLParseFromStrAlloc the given string. -// The allocator is required to create a null terminated string. -// The c string allocated is freed by the function. -// The caller is responsible for closing the document. -// DEPRECATED -pub fn documentHTMLParseFromStrAlloc(_: std.mem.Allocator, str: []const u8) !*DocumentHTML { - return documentHTMLParseFromStr(str); -} - // documentHTMLParseFromStr parses the given HTML string. // The caller is responsible for closing the document. pub fn documentHTMLParseFromStr(str: []const u8) !*DocumentHTML { diff --git a/src/run_tests.zig b/src/run_tests.zig index 0f541c79..3f6b17e8 100644 --- a/src/run_tests.zig +++ b/src/run_tests.zig @@ -37,7 +37,10 @@ fn testExecFn( try js_env.attachObject(try js_env.getGlobal(), "window", null); // document - doc = try parser.documentHTMLParseFromFileAlloc(std.testing.allocator, "test.html"); + const file = try std.fs.cwd().openFile("test.html", .{}); + defer file.close(); + + doc = try parser.documentHTMLParseFromFile(file); defer parser.documentHTMLClose(doc) catch |err| { std.debug.print("documentHTMLClose error: {s}\n", .{@errorName(err)}); }; diff --git a/src/wpt/run.zig b/src/wpt/run.zig index 1cdb74bf..68243c23 100644 --- a/src/wpt/run.zig +++ b/src/wpt/run.zig @@ -17,7 +17,10 @@ pub fn run(arena: *std.heap.ArenaAllocator, comptime apis: []jsruntime.API, comp const alloc = arena.allocator(); // document - const html_doc = try parser.documentHTMLParseFromFileAlloc(alloc, f); + const file = try std.fs.cwd().openFile(f, .{}); + defer file.close(); + + const html_doc = try parser.documentHTMLParseFromFile(file); const doc = parser.documentHTMLToDocument(html_doc); const dirname = fspath.dirname(f[dir.len..]) orelse unreachable;