netsurf: remove deprecated API for parsing HTML

This commit is contained in:
Pierre Tachoire
2024-01-08 15:18:17 +01:00
parent 9f77ba01bb
commit 0159051b17
5 changed files with 17 additions and 26 deletions

View File

@@ -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)});
};

View File

@@ -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)});
};

View File

@@ -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 {

View File

@@ -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)});
};

View File

@@ -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;