From 766c2ae47c8a829dec9dda9e8047d88645b274f9 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Mon, 27 Nov 2023 09:57:41 +0100 Subject: [PATCH 01/11] dom: add DOMImplementation --- src/dom/dom.zig | 2 + src/dom/implementation.zig | 82 ++++++++++++++++++++++++++++++++++++++ src/netsurf.zig | 50 ++++++++++++++++++++++- src/run_tests.zig | 2 + 4 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 src/dom/implementation.zig diff --git a/src/dom/dom.zig b/src/dom/dom.zig index 9fb3ad79..6a29a937 100644 --- a/src/dom/dom.zig +++ b/src/dom/dom.zig @@ -2,11 +2,13 @@ const generate = @import("../generate.zig"); const DOMException = @import("exceptions.zig").DOMException; const EventTarget = @import("event_target.zig").EventTarget; +const DOMImplementation = @import("implementation.zig").DOMImplementation; const Nod = @import("node.zig"); pub const Interfaces = generate.Tuple(.{ DOMException, EventTarget, + DOMImplementation, Nod.Node, Nod.Interfaces, }); diff --git a/src/dom/implementation.zig b/src/dom/implementation.zig new file mode 100644 index 00000000..c81aabce --- /dev/null +++ b/src/dom/implementation.zig @@ -0,0 +1,82 @@ +const std = @import("std"); + +const parser = @import("../netsurf.zig"); + +const jsruntime = @import("jsruntime"); +const Case = jsruntime.test_utils.Case; +const checkCases = jsruntime.test_utils.checkCases; + +const Document = @import("document.zig").Document; +const DocumentType = @import("document_type.zig").DocumentType; + +// WEB IDL https://dom.spec.whatwg.org/#domimplementation +pub const DOMImplementation = struct { + pub const mem_guarantied = true; + + pub fn _createDocumentType( + self: *DOMImplementation, + allocator: std.mem.Allocator, + qname: []const u8, + publicId: []const u8, + systemId: []const u8, + ) !*parser.DocumentType { + _ = self; + const cqname = try allocator.dupeZ(u8, qname); + defer allocator.free(cqname); + + const cpublicId = try allocator.dupeZ(u8, publicId); + defer allocator.free(cpublicId); + + const csystemId = try allocator.dupeZ(u8, systemId); + defer allocator.free(csystemId); + + const dt = parser.domImplementationCreateDocumentType(cqname, cpublicId, csystemId); + return dt; + } + + pub fn _createDocument( + self: *DOMImplementation, + allocator: std.mem.Allocator, + namespace: ?[]const u8, + qname: ?[]const u8, + doctype: ?*parser.DocumentType, + ) !*parser.Document { + _ = self; + var cnamespace: ?[:0]const u8 = null; + if (namespace != null) { + cnamespace = try allocator.dupeZ(u8, namespace.?); + defer allocator.free(cnamespace.?); + } + + var cqname: ?[:0]const u8 = null; + if (qname != null) { + cqname = try allocator.dupeZ(u8, qname.?); + defer allocator.free(cqname.?); + } + + const doc = parser.domImplementationCreateDocument(cnamespace, cqname, doctype); + return doc; + } + + pub fn _createHTMLDocument(_: *DOMImplementation, title: ?[]const u8) *parser.Document { + const doc = parser.domImplementationCreateHTMLDocument(title); + return doc; + } +}; + +// Tests +// ----- + +pub fn testExecFn( + _: std.mem.Allocator, + js_env: *jsruntime.Env, + comptime _: []jsruntime.API, +) !void { + var getImplementation = [_]Case{ + .{ .src = "let impl = document.implementation", .ex = "undefined" }, + .{ .src = "impl.createHTMLDocument();", .ex = "[object Document]" }, + .{ .src = "impl.createDocument(null, 'foo');", .ex = "[object Document]" }, + .{ .src = "impl.createDocumentType('foo', 'bar', 'baz');", .ex = "[object DocumentType]" }, + }; + try checkCases(js_env, &getImplementation); +} diff --git a/src/netsurf.zig b/src/netsurf.zig index dbb3e61e..0605f005 100644 --- a/src/netsurf.zig +++ b/src/netsurf.zig @@ -826,6 +826,54 @@ pub inline fn documentTypeGetSystemId(dt: *DocumentType) []const u8 { return stringToData(s.?); } +// DOMImplementation +pub inline fn domImplementationCreateDocument(namespace: ?[:0]const u8, qname: ?[:0]const u8, doctype: ?*DocumentType) *Document { + var doc: ?*Document = undefined; + + var ptrnamespace: [*c]const u8 = null; + if (namespace != null) { + ptrnamespace = namespace.?.ptr; + } + + var ptrqname: [*c]const u8 = null; + if (qname != null) { + ptrqname = qname.?.ptr; + } + + _ = c.dom_implementation_create_document( + c.DOM_IMPLEMENTATION_XML, + ptrnamespace, + ptrqname, + doctype, + null, + null, + &doc, + ); + return doc.?; +} + +pub inline fn domImplementationCreateDocumentType(qname: [:0]const u8, publicId: [:0]const u8, systemId: [:0]const u8) *DocumentType { + var dt: ?*DocumentType = undefined; + _ = c.dom_implementation_create_document_type(qname.ptr, publicId.ptr, systemId.ptr, &dt); + return dt.?; +} + +pub inline fn domImplementationCreateHTMLDocument(title: ?[]const u8) *Document { + _ = title; + var doc: ?*Document = undefined; + _ = c.dom_implementation_create_document( + c.DOM_IMPLEMENTATION_HTML, + null, + null, + null, + null, + null, + &doc, + ); + // TODO set title + return doc.?; +} + // Document pub const Document = c.dom_document; @@ -915,7 +963,7 @@ pub fn documentHTMLParseFromFile(filename: [:0]const u8) !*DocumentHTML { // 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. -pub fn documentHTMLParseFromStrAlloc(allocator: std.mem.Allocator, str: [:0]const u8) !*DocumentHTML { +pub fn documentHTMLParseFromStrAlloc(allocator: std.mem.Allocator, str: []const u8) !*DocumentHTML { // create a null terminated c string. const cstr = try allocator.dupeZ(u8, str); defer allocator.free(cstr); diff --git a/src/run_tests.zig b/src/run_tests.zig index 8acad71c..3a7dec64 100644 --- a/src/run_tests.zig +++ b/src/run_tests.zig @@ -13,6 +13,7 @@ const characterDataTestExecFn = @import("dom/character_data.zig").testExecFn; const textTestExecFn = @import("dom/text.zig").testExecFn; const HTMLCollectionTestExecFn = @import("dom/html_collection.zig").testExecFn; const DOMExceptionTestExecFn = @import("dom/exceptions.zig").testExecFn; +const DOMImplementationExecFn = @import("dom/implementation.zig").testExecFn; var doc: *parser.DocumentHTML = undefined; @@ -55,6 +56,7 @@ fn testsAllExecFn( textTestExecFn, HTMLCollectionTestExecFn, DOMExceptionTestExecFn, + DOMImplementationExecFn, }; inline for (testFns) |testFn| { From 7bd4729d3f5b972d18582d384ba1fe53019b3467 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Mon, 27 Nov 2023 11:46:57 +0100 Subject: [PATCH 02/11] dom: add document.implementation --- src/dom/document.zig | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/dom/document.zig b/src/dom/document.zig index f364b1bc..ef3f4831 100644 --- a/src/dom/document.zig +++ b/src/dom/document.zig @@ -14,6 +14,7 @@ const Element = @import("element.zig").Element; const ElementUnion = @import("element.zig").Union; const DocumentType = @import("document_type.zig").DocumentType; +const DOMImplementation = @import("implementation.zig").DOMImplementation; // WEB IDL https://dom.spec.whatwg.org/#document pub const Document = struct { @@ -28,7 +29,11 @@ pub const Document = struct { // JS funcs // -------- - // + + pub fn get_implementation(_: *parser.Document) DOMImplementation { + return DOMImplementation{}; + } + pub fn get_documentElement(self: *parser.Document) ElementUnion { const e = parser.documentGetDocumentElement(self); return Element.toInterface(e); @@ -198,6 +203,11 @@ pub fn testExecFn( }; try checkCases(js_env, &getDocumentURI); + var getImplementation = [_]Case{ + .{ .src = "let impl = document.implementation", .ex = "undefined" }, + }; + try checkCases(js_env, &getImplementation); + const tags = comptime parser.Tag.all(); comptime var createElements: [(tags.len) * 2]Case = undefined; inline for (tags, 0..) |tag, i| { From 1c4edf7c95fdd85df9fb7e59e0d3e37ea93caddf Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Mon, 27 Nov 2023 11:53:52 +0100 Subject: [PATCH 03/11] dom: implement document constructor --- src/dom/document.zig | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/dom/document.zig b/src/dom/document.zig index ef3f4831..a2a74810 100644 --- a/src/dom/document.zig +++ b/src/dom/document.zig @@ -22,10 +22,9 @@ pub const Document = struct { pub const prototype = *Node; pub const mem_guarantied = true; - // pub fn constructor() *parser.Document { - // // TODO - // return .{}; - // } + pub fn constructor() *parser.Document { + return parser.domImplementationCreateHTMLDocument(null); + } // JS funcs // -------- @@ -208,6 +207,16 @@ pub fn testExecFn( }; try checkCases(js_env, &getImplementation); + var new = [_]Case{ + .{ .src = "let d = new Document()", .ex = "undefined" }, + .{ .src = "d.characterSet", .ex = "UTF-8" }, + .{ .src = "d.URL", .ex = "about:blank" }, + .{ .src = "d.documentURI", .ex = "about:blank" }, + .{ .src = "d.compatMode", .ex = "CSS1Compat" }, + .{ .src = "d.contentType", .ex = "text/html" }, + }; + try checkCases(js_env, &new); + const tags = comptime parser.Tag.all(); comptime var createElements: [(tags.len) * 2]Case = undefined; inline for (tags, 0..) |tag, i| { From dde3f149d6b88b81e697a54977da906ca7ddddf0 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Mon, 27 Nov 2023 12:37:42 +0100 Subject: [PATCH 04/11] dom: add DOMImplementation.deinit --- src/dom/implementation.zig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/dom/implementation.zig b/src/dom/implementation.zig index c81aabce..0caa011a 100644 --- a/src/dom/implementation.zig +++ b/src/dom/implementation.zig @@ -62,6 +62,8 @@ pub const DOMImplementation = struct { const doc = parser.domImplementationCreateHTMLDocument(title); return doc; } + + pub fn deinit(_: *DOMImplementation, _: std.mem.Allocator) void {} }; // Tests From 443aef4f76e1aade98df1600e8dfbbae5dedcac6 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Mon, 27 Nov 2023 16:31:41 +0100 Subject: [PATCH 05/11] dom: add DOMImplementation.hasFeature --- src/dom/implementation.zig | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/dom/implementation.zig b/src/dom/implementation.zig index 0caa011a..138422db 100644 --- a/src/dom/implementation.zig +++ b/src/dom/implementation.zig @@ -63,6 +63,10 @@ pub const DOMImplementation = struct { return doc; } + pub fn _hasFeature(_: *DOMImplementation) bool { + return true; + } + pub fn deinit(_: *DOMImplementation, _: std.mem.Allocator) void {} }; @@ -78,7 +82,8 @@ pub fn testExecFn( .{ .src = "let impl = document.implementation", .ex = "undefined" }, .{ .src = "impl.createHTMLDocument();", .ex = "[object Document]" }, .{ .src = "impl.createDocument(null, 'foo');", .ex = "[object Document]" }, - .{ .src = "impl.createDocumentType('foo', 'bar', 'baz');", .ex = "[object DocumentType]" }, + .{ .src = "impl.createDocumentType('foo', 'bar', 'baz')", .ex = "[object DocumentType]" }, + .{ .src = "impl.hasFeature()", .ex = "true" }, }; try checkCases(js_env, &getImplementation); } From 88c6a2395b260a129cafa82739405af025c191bd Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Mon, 27 Nov 2023 16:34:42 +0100 Subject: [PATCH 06/11] dom: add WPT for implementation --- ...ment-with-null-browsing-context-crash.html | 13 ++ .../DOMImplementation-createDocument.html | 170 ++++++++++++++++++ .../DOMImplementation-createDocumentType.html | 123 +++++++++++++ ...ment-with-null-browsing-context-crash.html | 13 ++ ...TMLDocument-with-saved-implementation.html | 16 ++ .../DOMImplementation-createHTMLDocument.html | 96 ++++++++++ .../DOMImplementation-createHTMLDocument.js | 25 +++ .../nodes/DOMImplementation-hasFeature.html | 155 ++++++++++++++++ 8 files changed, 611 insertions(+) create mode 100644 tests/wpt/dom/nodes/DOMImplementation-createDocument-with-null-browsing-context-crash.html create mode 100644 tests/wpt/dom/nodes/DOMImplementation-createDocument.html create mode 100644 tests/wpt/dom/nodes/DOMImplementation-createDocumentType.html create mode 100644 tests/wpt/dom/nodes/DOMImplementation-createHTMLDocument-with-null-browsing-context-crash.html create mode 100644 tests/wpt/dom/nodes/DOMImplementation-createHTMLDocument-with-saved-implementation.html create mode 100644 tests/wpt/dom/nodes/DOMImplementation-createHTMLDocument.html create mode 100644 tests/wpt/dom/nodes/DOMImplementation-createHTMLDocument.js create mode 100644 tests/wpt/dom/nodes/DOMImplementation-hasFeature.html diff --git a/tests/wpt/dom/nodes/DOMImplementation-createDocument-with-null-browsing-context-crash.html b/tests/wpt/dom/nodes/DOMImplementation-createDocument-with-null-browsing-context-crash.html new file mode 100644 index 00000000..c9393d0a --- /dev/null +++ b/tests/wpt/dom/nodes/DOMImplementation-createDocument-with-null-browsing-context-crash.html @@ -0,0 +1,13 @@ + + +DOMImplementation.createDocument() + + + + + + diff --git a/tests/wpt/dom/nodes/DOMImplementation-createDocument.html b/tests/wpt/dom/nodes/DOMImplementation-createDocument.html new file mode 100644 index 00000000..835002b4 --- /dev/null +++ b/tests/wpt/dom/nodes/DOMImplementation-createDocument.html @@ -0,0 +1,170 @@ + + +DOMImplementation.createDocument(namespace, qualifiedName, doctype) + + + + + + + + +
+ diff --git a/tests/wpt/dom/nodes/DOMImplementation-createDocumentType.html b/tests/wpt/dom/nodes/DOMImplementation-createDocumentType.html new file mode 100644 index 00000000..8d23e66a --- /dev/null +++ b/tests/wpt/dom/nodes/DOMImplementation-createDocumentType.html @@ -0,0 +1,123 @@ + + +DOMImplementation.createDocumentType(qualifiedName, publicId, systemId) + + + + + + + +
+ diff --git a/tests/wpt/dom/nodes/DOMImplementation-createHTMLDocument-with-null-browsing-context-crash.html b/tests/wpt/dom/nodes/DOMImplementation-createHTMLDocument-with-null-browsing-context-crash.html new file mode 100644 index 00000000..d0cd6f1f --- /dev/null +++ b/tests/wpt/dom/nodes/DOMImplementation-createHTMLDocument-with-null-browsing-context-crash.html @@ -0,0 +1,13 @@ + + +DOMImplementation.createHTMLDocument() + + + + + + diff --git a/tests/wpt/dom/nodes/DOMImplementation-createHTMLDocument-with-saved-implementation.html b/tests/wpt/dom/nodes/DOMImplementation-createHTMLDocument-with-saved-implementation.html new file mode 100644 index 00000000..bae22660 --- /dev/null +++ b/tests/wpt/dom/nodes/DOMImplementation-createHTMLDocument-with-saved-implementation.html @@ -0,0 +1,16 @@ + +DOMImplementation.createHTMLDocument + + + +
+ diff --git a/tests/wpt/dom/nodes/DOMImplementation-createHTMLDocument.html b/tests/wpt/dom/nodes/DOMImplementation-createHTMLDocument.html new file mode 100644 index 00000000..c6e0beaf --- /dev/null +++ b/tests/wpt/dom/nodes/DOMImplementation-createHTMLDocument.html @@ -0,0 +1,96 @@ + + + +DOMImplementation.createHTMLDocument + + + + + + + + +
+ diff --git a/tests/wpt/dom/nodes/DOMImplementation-createHTMLDocument.js b/tests/wpt/dom/nodes/DOMImplementation-createHTMLDocument.js new file mode 100644 index 00000000..3e7e9aa9 --- /dev/null +++ b/tests/wpt/dom/nodes/DOMImplementation-createHTMLDocument.js @@ -0,0 +1,25 @@ +function createHTMLDocuments(checkDoc) { + var tests = [ + ["", "", ""], + [null, "null", "null"], + [undefined, undefined, ""], + ["foo bar baz", "foo bar baz", "foo bar baz"], + ["foo\t\tbar baz", "foo\t\tbar baz", "foo bar baz"], + ["foo\n\nbar baz", "foo\n\nbar baz", "foo bar baz"], + ["foo\f\fbar baz", "foo\f\fbar baz", "foo bar baz"], + ["foo\r\rbar baz", "foo\r\rbar baz", "foo bar baz"], + ] + + tests.forEach(function(t, i) { + var title = t[0], expectedtitle = t[1], normalizedtitle = t[2] + test(function() { + var doc = document.implementation.createHTMLDocument(title); + checkDoc(doc, expectedtitle, normalizedtitle) + }, "createHTMLDocument test " + i + ": " + t.map(function(el) { return format_value(el) })) + }) + + test(function() { + var doc = document.implementation.createHTMLDocument(); + checkDoc(doc, undefined, "") + }, "Missing title argument"); +} diff --git a/tests/wpt/dom/nodes/DOMImplementation-hasFeature.html b/tests/wpt/dom/nodes/DOMImplementation-hasFeature.html new file mode 100644 index 00000000..637565a6 --- /dev/null +++ b/tests/wpt/dom/nodes/DOMImplementation-hasFeature.html @@ -0,0 +1,155 @@ + + +DOMImplementation.hasFeature(feature, version) + + + +
+ From bd68f0720651030b5712b460a452e7ce3d72a030 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Mon, 27 Nov 2023 17:45:43 +0100 Subject: [PATCH 07/11] use _ name for unused self args Co-authored-by: Francis Bouvier --- src/dom/implementation.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dom/implementation.zig b/src/dom/implementation.zig index 138422db..4fad84fd 100644 --- a/src/dom/implementation.zig +++ b/src/dom/implementation.zig @@ -14,7 +14,7 @@ pub const DOMImplementation = struct { pub const mem_guarantied = true; pub fn _createDocumentType( - self: *DOMImplementation, + _: *DOMImplementation, allocator: std.mem.Allocator, qname: []const u8, publicId: []const u8, @@ -35,7 +35,7 @@ pub const DOMImplementation = struct { } pub fn _createDocument( - self: *DOMImplementation, + _: *DOMImplementation, allocator: std.mem.Allocator, namespace: ?[]const u8, qname: ?[]const u8, From 0afa6b27b91b5db4376bf53bf7e6e6ca8868faba Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Mon, 27 Nov 2023 17:46:44 +0100 Subject: [PATCH 08/11] remove useless var Co-authored-by: Francis Bouvier --- src/dom/implementation.zig | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/dom/implementation.zig b/src/dom/implementation.zig index 4fad84fd..c8b03959 100644 --- a/src/dom/implementation.zig +++ b/src/dom/implementation.zig @@ -30,8 +30,7 @@ pub const DOMImplementation = struct { const csystemId = try allocator.dupeZ(u8, systemId); defer allocator.free(csystemId); - const dt = parser.domImplementationCreateDocumentType(cqname, cpublicId, csystemId); - return dt; + return parser.domImplementationCreateDocumentType(cqname, cpublicId, csystemId); } pub fn _createDocument( @@ -54,13 +53,11 @@ pub const DOMImplementation = struct { defer allocator.free(cqname.?); } - const doc = parser.domImplementationCreateDocument(cnamespace, cqname, doctype); - return doc; + return parser.domImplementationCreateDocument(cnamespace, cqname, doctype); } pub fn _createHTMLDocument(_: *DOMImplementation, title: ?[]const u8) *parser.Document { - const doc = parser.domImplementationCreateHTMLDocument(title); - return doc; + return parser.domImplementationCreateHTMLDocument(title); } pub fn _hasFeature(_: *DOMImplementation) bool { From 8d6f18744e14108cf83be777f39c1d039f0db4bd Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Mon, 27 Nov 2023 17:51:21 +0100 Subject: [PATCH 09/11] move unsued along with TODO Co-authored-by: Francis Bouvier --- src/netsurf.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/netsurf.zig b/src/netsurf.zig index 0605f005..774fed62 100644 --- a/src/netsurf.zig +++ b/src/netsurf.zig @@ -859,7 +859,6 @@ pub inline fn domImplementationCreateDocumentType(qname: [:0]const u8, publicId: } pub inline fn domImplementationCreateHTMLDocument(title: ?[]const u8) *Document { - _ = title; var doc: ?*Document = undefined; _ = c.dom_implementation_create_document( c.DOM_IMPLEMENTATION_HTML, @@ -871,6 +870,7 @@ pub inline fn domImplementationCreateHTMLDocument(title: ?[]const u8) *Document &doc, ); // TODO set title + _ = title; return doc.?; } From c4c6cfa04456dd0dfacdf2591a6d048f9a91e722 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Mon, 27 Nov 2023 17:52:32 +0100 Subject: [PATCH 10/11] better null check syntax Co-authored-by: Francis Bouvier --- src/dom/implementation.zig | 8 ++++---- src/netsurf.zig | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/dom/implementation.zig b/src/dom/implementation.zig index c8b03959..f577f634 100644 --- a/src/dom/implementation.zig +++ b/src/dom/implementation.zig @@ -42,14 +42,14 @@ pub const DOMImplementation = struct { ) !*parser.Document { _ = self; var cnamespace: ?[:0]const u8 = null; - if (namespace != null) { - cnamespace = try allocator.dupeZ(u8, namespace.?); + if (namespace) |ns| { + cnamespace = try allocator.dupeZ(u8, ns); defer allocator.free(cnamespace.?); } var cqname: ?[:0]const u8 = null; - if (qname != null) { - cqname = try allocator.dupeZ(u8, qname.?); + if (qname) |qn| { + cqname = try allocator.dupeZ(u8, qn); defer allocator.free(cqname.?); } diff --git a/src/netsurf.zig b/src/netsurf.zig index 774fed62..5a6bb796 100644 --- a/src/netsurf.zig +++ b/src/netsurf.zig @@ -831,13 +831,13 @@ pub inline fn domImplementationCreateDocument(namespace: ?[:0]const u8, qname: ? var doc: ?*Document = undefined; var ptrnamespace: [*c]const u8 = null; - if (namespace != null) { - ptrnamespace = namespace.?.ptr; + if (namespace) |ns| { + ptrnamespace = ns.ptr; } var ptrqname: [*c]const u8 = null; - if (qname != null) { - ptrqname = qname.?.ptr; + if (qname) |qn| { + ptrqname = qn.ptr; } _ = c.dom_implementation_create_document( From a504daebe1651b28604253476e9249e8b88ce62f Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Mon, 27 Nov 2023 17:50:00 +0100 Subject: [PATCH 11/11] dom: use alloc short name --- src/dom/implementation.zig | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/dom/implementation.zig b/src/dom/implementation.zig index f577f634..3e4e9eaa 100644 --- a/src/dom/implementation.zig +++ b/src/dom/implementation.zig @@ -14,43 +14,41 @@ pub const DOMImplementation = struct { pub const mem_guarantied = true; pub fn _createDocumentType( - _: *DOMImplementation, - allocator: std.mem.Allocator, + _: *DOMImplementation, + alloc: std.mem.Allocator, qname: []const u8, publicId: []const u8, systemId: []const u8, ) !*parser.DocumentType { - _ = self; - const cqname = try allocator.dupeZ(u8, qname); - defer allocator.free(cqname); + const cqname = try alloc.dupeZ(u8, qname); + defer alloc.free(cqname); - const cpublicId = try allocator.dupeZ(u8, publicId); - defer allocator.free(cpublicId); + const cpublicId = try alloc.dupeZ(u8, publicId); + defer alloc.free(cpublicId); - const csystemId = try allocator.dupeZ(u8, systemId); - defer allocator.free(csystemId); + const csystemId = try alloc.dupeZ(u8, systemId); + defer alloc.free(csystemId); return parser.domImplementationCreateDocumentType(cqname, cpublicId, csystemId); } pub fn _createDocument( - _: *DOMImplementation, - allocator: std.mem.Allocator, + _: *DOMImplementation, + alloc: std.mem.Allocator, namespace: ?[]const u8, qname: ?[]const u8, doctype: ?*parser.DocumentType, ) !*parser.Document { - _ = self; var cnamespace: ?[:0]const u8 = null; if (namespace) |ns| { - cnamespace = try allocator.dupeZ(u8, ns); - defer allocator.free(cnamespace.?); + cnamespace = try alloc.dupeZ(u8, ns); + defer alloc.free(cnamespace.?); } var cqname: ?[:0]const u8 = null; if (qname) |qn| { - cqname = try allocator.dupeZ(u8, qn); - defer allocator.free(cqname.?); + cqname = try alloc.dupeZ(u8, qn); + defer alloc.free(cqname.?); } return parser.domImplementationCreateDocument(cnamespace, cqname, doctype);