From e4d1b1d921c99c78bfcba951c1fc3655e4583110 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Tue, 21 Nov 2023 08:54:58 +0100 Subject: [PATCH 1/5] dom: add document.documentElement getter --- src/dom/document.zig | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/dom/document.zig b/src/dom/document.zig index dfd7f75a..55b7e1e7 100644 --- a/src/dom/document.zig +++ b/src/dom/document.zig @@ -29,6 +29,11 @@ pub const Document = struct { // JS funcs // -------- // + pub fn get_documentElement(self: *parser.Document) ElementUnion { + const e = parser.documentGetDocumentElement(self); + return Element.toInterface(e); + } + pub fn get_doctype(self: *parser.Document) ?*parser.DocumentType { return parser.documentGetDoctype(self); } @@ -112,6 +117,12 @@ pub fn testExecFn( }; try checkCases(js_env, &getElementsByClassName); + var getDocumentElement = [_]Case{ + .{ .src = "let e = document.documentElement", .ex = "undefined" }, + .{ .src = "e.localName", .ex = "html" }, + }; + try checkCases(js_env, &getDocumentElement); + const tags = comptime parser.Tag.all(); comptime var createElements: [(tags.len) * 2]Case = undefined; inline for (tags, 0..) |tag, i| { From 4ae0c0c5af0c686cef14a85b72bbc7d9293cff9e Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Tue, 21 Nov 2023 09:30:36 +0100 Subject: [PATCH 2/5] dom: add document.characterSet with hardcoded value --- src/dom/document.zig | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/dom/document.zig b/src/dom/document.zig index 55b7e1e7..238de044 100644 --- a/src/dom/document.zig +++ b/src/dom/document.zig @@ -34,6 +34,22 @@ pub const Document = struct { return Element.toInterface(e); } + // TODO implement characterSet + pub fn get_characterSet(self: *parser.Document) []const u8 { + _ = self; + return "UTF-8"; + } + + // alias of get_characterSet + pub fn get_charset(self: *parser.Document) []const u8 { + return get_characterSet(self); + } + + // alias of get_characterSet + pub fn get_inputEncoding(self: *parser.Document) []const u8 { + return get_characterSet(self); + } + pub fn get_doctype(self: *parser.Document) ?*parser.DocumentType { return parser.documentGetDoctype(self); } @@ -123,6 +139,13 @@ pub fn testExecFn( }; try checkCases(js_env, &getDocumentElement); + var getCharacterSet = [_]Case{ + .{ .src = "document.characterSet", .ex = "UTF-8" }, + .{ .src = "document.charset", .ex = "UTF-8" }, + .{ .src = "document.inputEncoding", .ex = "UTF-8" }, + }; + try checkCases(js_env, &getCharacterSet); + const tags = comptime parser.Tag.all(); comptime var createElements: [(tags.len) * 2]Case = undefined; inline for (tags, 0..) |tag, i| { From f1ea914303303aa5613875cb2a8d21540d5b04cf Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Tue, 21 Nov 2023 09:33:31 +0100 Subject: [PATCH 3/5] dom: add document.compatMode with hardcoded value --- src/dom/document.zig | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/dom/document.zig b/src/dom/document.zig index 238de044..80deaf36 100644 --- a/src/dom/document.zig +++ b/src/dom/document.zig @@ -34,6 +34,12 @@ pub const Document = struct { return Element.toInterface(e); } + // TODO implement compactMode + pub fn get_compatMode(self: *parser.Document) []const u8 { + _ = self; + return "CSS1Compat"; + } + // TODO implement characterSet pub fn get_characterSet(self: *parser.Document) []const u8 { _ = self; @@ -146,6 +152,11 @@ pub fn testExecFn( }; try checkCases(js_env, &getCharacterSet); + var getCompatMode = [_]Case{ + .{ .src = "document.compatMode", .ex = "CSS1Compat" }, + }; + try checkCases(js_env, &getCompatMode); + const tags = comptime parser.Tag.all(); comptime var createElements: [(tags.len) * 2]Case = undefined; inline for (tags, 0..) |tag, i| { From 0fadb4ff985a5c6a993c38582f3b4a9ab3a3b242 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Tue, 21 Nov 2023 09:47:19 +0100 Subject: [PATCH 4/5] dom: document.contentType with hardcoded value --- src/dom/document.zig | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/dom/document.zig b/src/dom/document.zig index 80deaf36..8119f357 100644 --- a/src/dom/document.zig +++ b/src/dom/document.zig @@ -34,6 +34,12 @@ pub const Document = struct { return Element.toInterface(e); } + // TODO implement contentType + pub fn get_contentType(self: *parser.Document) []const u8 { + _ = self; + return "text/html"; + } + // TODO implement compactMode pub fn get_compatMode(self: *parser.Document) []const u8 { _ = self; @@ -157,6 +163,11 @@ pub fn testExecFn( }; try checkCases(js_env, &getCompatMode); + var getContentType = [_]Case{ + .{ .src = "document.contentType", .ex = "text/html" }, + }; + try checkCases(js_env, &getContentType); + const tags = comptime parser.Tag.all(); comptime var createElements: [(tags.len) * 2]Case = undefined; inline for (tags, 0..) |tag, i| { From bf297ac97d61084de0592df63f2d84c0db2e01ca Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Tue, 21 Nov 2023 09:52:35 +0100 Subject: [PATCH 5/5] dom: document.documentURI and document.URL --- src/dom/document.zig | 16 ++++++++++++++++ src/netsurf.zig | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/src/dom/document.zig b/src/dom/document.zig index 8119f357..d4cfbb21 100644 --- a/src/dom/document.zig +++ b/src/dom/document.zig @@ -34,6 +34,15 @@ pub const Document = struct { return Element.toInterface(e); } + pub fn get_documentURI(self: *parser.Document) []const u8 { + return parser.documentGetDocumentURI(self); + } + + // TODO should be get_URL but in this case, document.URL is indefined. + pub fn get_url(self: *parser.Document) []const u8 { + return get_documentURI(self); + } + // TODO implement contentType pub fn get_contentType(self: *parser.Document) []const u8 { _ = self; @@ -168,6 +177,13 @@ pub fn testExecFn( }; try checkCases(js_env, &getContentType); + var getDocumentURI = [_]Case{ + .{ .src = "document.documentURI", .ex = "about:blank" }, + // TODO should be document.URL + .{ .src = "document.url", .ex = "about:blank" }, + }; + try checkCases(js_env, &getDocumentURI); + const tags = comptime parser.Tag.all(); comptime var createElements: [(tags.len) * 2]Case = undefined; inline for (tags, 0..) |tag, i| { diff --git a/src/netsurf.zig b/src/netsurf.zig index 66571071..368e01f1 100644 --- a/src/netsurf.zig +++ b/src/netsurf.zig @@ -794,6 +794,12 @@ pub inline fn documentGetDocumentElement(doc: *Document) *Element { return elem.?; } +pub inline fn documentGetDocumentURI(doc: *Document) []const u8 { + var s: ?*String = undefined; + _ = documentVtable(doc).dom_document_get_uri.?(doc, &s); + return stringToData(s.?); +} + pub inline fn documentCreateElement(doc: *Document, tag_name: []const u8) *Element { var elem: ?*Element = undefined; _ = documentVtable(doc).dom_document_create_element.?(doc, stringFromData(tag_name), &elem);