diff --git a/src/dom/text.zig b/src/dom/text.zig index 2481c850..89773a35 100644 --- a/src/dom/text.zig +++ b/src/dom/text.zig @@ -1,3 +1,9 @@ +const std = @import("std"); + +const jsruntime = @import("jsruntime"); +const Case = jsruntime.test_utils.Case; +const checkCases = jsruntime.test_utils.checkCases; + const parser = @import("../netsurf.zig"); const CharacterData = @import("character_data.zig").CharacterData; @@ -6,4 +12,28 @@ pub const Text = struct { pub const Self = parser.Text; pub const prototype = *CharacterData; pub const mem_guarantied = true; + + // JS funcs + // -------- + + // Read attributes + + pub fn get_wholeText(self: *parser.Text) []const u8 { + return parser.textWholdeText(self); + } }; + +// Tests +// ----- + +pub fn testExecFn( + _: std.mem.Allocator, + js_env: *jsruntime.Env, + comptime _: []jsruntime.API, +) !void { + var get_whole_text = [_]Case{ + .{ .src = "let text = document.getElementById('link').firstChild", .ex = "undefined" }, + .{ .src = "text.wholeText === 'OK'", .ex = "true" }, + }; + try checkCases(js_env, &get_whole_text); +} diff --git a/src/netsurf.zig b/src/netsurf.zig index 866346b2..d11b043d 100644 --- a/src/netsurf.zig +++ b/src/netsurf.zig @@ -503,6 +503,16 @@ pub fn characterDataSubstringData(cdata: *CharacterData, offset: u32, count: u32 // Text pub const Text = c.dom_text; +fn textVtable(text: *Text) c.dom_text_vtable { + return getVtable(c.dom_text_vtable, Text, text); +} + +pub fn textWholdeText(text: *Text) []const u8 { + var s: ?*String = undefined; + _ = textVtable(text).dom_text_get_whole_text.?(text, &s); + return stringToData(s.?); +} + // Comment pub const Comment = c.dom_comment; diff --git a/src/run_tests.zig b/src/run_tests.zig index bb036659..9a34bd7f 100644 --- a/src/run_tests.zig +++ b/src/run_tests.zig @@ -9,6 +9,7 @@ const DOM = @import("dom.zig"); const docTestExecFn = @import("html/document.zig").testExecFn; const nodeTestExecFn = @import("dom/node.zig").testExecFn; const characterDataTestExecFn = @import("dom/character_data.zig").testExecFn; +const textTestExecFn = @import("dom/text.zig").testExecFn; var doc: *parser.DocumentHTML = undefined; @@ -43,6 +44,7 @@ fn testsAllExecFn( docTestExecFn, nodeTestExecFn, characterDataTestExecFn, + textTestExecFn, }; inline for (testFns) |testFn| {