Lightpanda: the headless browser designed for AI and automation
webapi: treat null textContent as the empty string
Jay Hemnanie463e98170a0
diff --git a/src/browser/tests/node/text_content.html b/src/browser/tests/node/text_content.htmlindex fc6a0de9a..7e1ddf5fe 100644--- a/src/browser/tests/node/text_content.html+++ b/src/browser/tests/node/text_content.html@@ -42,3 +42,18 @@testing.expectEqual('attr2', attr.textContent);testing.expectEqual(div, $('#attr2'));</script>++<script id=null_and_undefined>+ const p = document.createElement('p');+ p.innerHTML = '<b>x</b>';+ p.textContent = null;+ testing.expectEqual('<p></p>', p.outerHTML);++ p.innerHTML = '<b>x</b>';+ p.textContent = undefined;+ testing.expectEqual('<p></p>', p.outerHTML);++ const text = document.createTextNode('abc');+ text.textContent = null;+ testing.expectEqual('', text.data);+</script>diff --git a/src/browser/webapi/Node.zig b/src/browser/webapi/Node.zigindex 5a48c578a..c6c99ba05 100644--- a/src/browser/webapi/Node.zig+++ b/src/browser/webapi/Node.zig@@ -1792,7 +1792,11 @@ pub const JsApi = struct {}.wrap, null, .{});pub const nodeType = bridge.accessor(Node.getNodeType, null, .{});- pub const textContent = bridge.accessor(_textContext, Node.setTextContent, .{ .ce_reactions = true });+ pub const textContent = bridge.accessor(_textContext, _setTextContent, .{ .ce_reactions = true });+ // textContent is a nullable DOMString: null (and undefined) mean the empty string.+ fn _setTextContent(self: *Node, data: ?[]const u8, frame: *Frame) !void {+ return self.setTextContent(data orelse "", frame);+ }fn _textContext(self: *Node, frame: *const Frame) !?[]const u8 {// cdata and attributes can return value directly, avoiding the copyswitch (self._type) {