mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 23:23:28 +00:00
dom: add document.createCDATASection
This commit is contained in:
12
src/dom/cdata_section.zig
Normal file
12
src/dom/cdata_section.zig
Normal file
@@ -0,0 +1,12 @@
|
||||
const std = @import("std");
|
||||
|
||||
const parser = @import("../netsurf.zig");
|
||||
|
||||
const Text = @import("text.zig").Text;
|
||||
|
||||
// https://dom.spec.whatwg.org/#cdatasection
|
||||
pub const CDATASection = struct {
|
||||
pub const Self = parser.CDATASection;
|
||||
pub const prototype = *Text;
|
||||
pub const mem_guarantied = true;
|
||||
};
|
||||
@@ -10,12 +10,14 @@ const parser = @import("../netsurf.zig");
|
||||
const Node = @import("node.zig").Node;
|
||||
const Comment = @import("comment.zig").Comment;
|
||||
const Text = @import("text.zig").Text;
|
||||
const CDATASection = @import("cdata_section.zig").CDATASection;
|
||||
const HTMLElem = @import("../html/elements.zig");
|
||||
|
||||
// CharacterData interfaces
|
||||
pub const Interfaces = generate.Tuple(.{
|
||||
Comment,
|
||||
Text,
|
||||
CDATASection,
|
||||
});
|
||||
|
||||
// CharacterData implementation
|
||||
|
||||
@@ -133,6 +133,10 @@ pub const Document = struct {
|
||||
return try parser.documentCreateTextNode(self, data);
|
||||
}
|
||||
|
||||
pub fn _createCDATASection(self: *parser.Document, data: []const u8) !*parser.CDATASection {
|
||||
return try parser.documentCreateCDATASection(self, data);
|
||||
}
|
||||
|
||||
pub fn deinit(_: *parser.Document, _: std.mem.Allocator) void {}
|
||||
};
|
||||
|
||||
@@ -235,6 +239,11 @@ pub fn testExecFn(
|
||||
};
|
||||
try checkCases(js_env, &createTextNode);
|
||||
|
||||
var createCDATASection = [_]Case{
|
||||
.{ .src = "document.createCDATASection('foo')", .ex = "[object CDATASection]" },
|
||||
};
|
||||
try checkCases(js_env, &createCDATASection);
|
||||
|
||||
const tags = comptime parser.Tag.all();
|
||||
comptime var createElements: [(tags.len) * 2]Case = undefined;
|
||||
inline for (tags, 0..) |tag, i| {
|
||||
|
||||
@@ -54,6 +54,7 @@ pub const Node = struct {
|
||||
),
|
||||
.comment => .{ .Comment = @as(*parser.Comment, @ptrCast(node)) },
|
||||
.text => .{ .Text = @as(*parser.Text, @ptrCast(node)) },
|
||||
.cdata_section => .{ .CDATASection = @as(*parser.CDATASection, @ptrCast(node)) },
|
||||
.document => .{ .HTMLDocument = @as(*parser.DocumentHTML, @ptrCast(node)) },
|
||||
.document_type => .{ .DocumentType = @as(*parser.DocumentType, @ptrCast(node)) },
|
||||
.attribute => .{ .Attr = @as(*parser.Attribute, @ptrCast(node)) },
|
||||
|
||||
@@ -791,6 +791,9 @@ pub fn characterDataSubstringData(cdata: *CharacterData, offset: u32, count: u32
|
||||
return strToData(s.?);
|
||||
}
|
||||
|
||||
// CDATASection
|
||||
pub const CDATASection = c.dom_cdata_section;
|
||||
|
||||
// Text
|
||||
pub const Text = c.dom_text;
|
||||
|
||||
@@ -1144,6 +1147,13 @@ pub inline fn documentCreateTextNode(doc: *Document, s: []const u8) !*Text {
|
||||
return txt.?;
|
||||
}
|
||||
|
||||
pub inline fn documentCreateCDATASection(doc: *Document, s: []const u8) !*CDATASection {
|
||||
var cdata: ?*CDATASection = undefined;
|
||||
const err = documentVtable(doc).dom_document_create_cdata_section.?(doc, try strFromData(s), &cdata);
|
||||
try DOMErr(err);
|
||||
return cdata.?;
|
||||
}
|
||||
|
||||
// DocumentHTML
|
||||
pub const DocumentHTML = c.dom_html_document;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user