mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 23:23:28 +00:00
dom: implement document.createProcessingInstruction
This commit is contained in:
@@ -11,6 +11,7 @@ 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 ProcessingInstruction = @import("processing_instruction.zig").ProcessingInstruction;
|
||||
const HTMLElem = @import("../html/elements.zig");
|
||||
|
||||
// CharacterData interfaces
|
||||
@@ -18,6 +19,7 @@ pub const Interfaces = generate.Tuple(.{
|
||||
Comment,
|
||||
Text,
|
||||
CDATASection,
|
||||
ProcessingInstruction,
|
||||
});
|
||||
|
||||
// CharacterData implementation
|
||||
|
||||
@@ -141,6 +141,10 @@ pub const Document = struct {
|
||||
return try parser.documentCreateComment(self, data);
|
||||
}
|
||||
|
||||
pub fn _createProcessingInstruction(self: *parser.Document, target: []const u8, data: []const u8) !*parser.ProcessingInstruction {
|
||||
return try parser.documentCreateProcessingInstruction(self, target, data);
|
||||
}
|
||||
|
||||
pub fn deinit(_: *parser.Document, _: std.mem.Allocator) void {}
|
||||
};
|
||||
|
||||
@@ -253,6 +257,11 @@ pub fn testExecFn(
|
||||
};
|
||||
try checkCases(js_env, &createComment);
|
||||
|
||||
var createProcessingInstruction = [_]Case{
|
||||
.{ .src = "document.createProcessingInstruction('foo', 'bar')", .ex = "[object ProcessingInstruction]" },
|
||||
};
|
||||
try checkCases(js_env, &createProcessingInstruction);
|
||||
|
||||
const tags = comptime parser.Tag.all();
|
||||
comptime var createElements: [(tags.len) * 2]Case = undefined;
|
||||
inline for (tags, 0..) |tag, i| {
|
||||
|
||||
@@ -55,6 +55,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)) },
|
||||
.processing_instruction => .{ .ProcessingInstruction = @as(*parser.ProcessingInstruction, @ptrCast(node)) },
|
||||
.document => .{ .HTMLDocument = @as(*parser.DocumentHTML, @ptrCast(node)) },
|
||||
.document_type => .{ .DocumentType = @as(*parser.DocumentType, @ptrCast(node)) },
|
||||
.attribute => .{ .Attr = @as(*parser.Attribute, @ptrCast(node)) },
|
||||
|
||||
14
src/dom/processing_instruction.zig
Normal file
14
src/dom/processing_instruction.zig
Normal file
@@ -0,0 +1,14 @@
|
||||
const std = @import("std");
|
||||
|
||||
const parser = @import("../netsurf.zig");
|
||||
|
||||
const CharacterData = @import("character_data.zig").CharacterData;
|
||||
|
||||
// https://dom.spec.whatwg.org/#processinginstruction
|
||||
pub const ProcessingInstruction = struct {
|
||||
pub const Self = parser.ProcessingInstruction;
|
||||
pub const prototype = *CharacterData;
|
||||
pub const mem_guarantied = true;
|
||||
|
||||
// TODO implement get_target
|
||||
};
|
||||
@@ -818,6 +818,9 @@ pub fn textSplitText(text: *Text, offset: u32) !*Text {
|
||||
// Comment
|
||||
pub const Comment = c.dom_comment;
|
||||
|
||||
// ProcessingInstruction
|
||||
pub const ProcessingInstruction = c.dom_processing_instruction;
|
||||
|
||||
// Attribute
|
||||
pub const Attribute = c.dom_attr;
|
||||
|
||||
@@ -1161,6 +1164,18 @@ pub inline fn documentCreateComment(doc: *Document, s: []const u8) !*Comment {
|
||||
return com.?;
|
||||
}
|
||||
|
||||
pub inline fn documentCreateProcessingInstruction(doc: *Document, target: []const u8, data: []const u8) !*ProcessingInstruction {
|
||||
var pi: ?*ProcessingInstruction = undefined;
|
||||
const err = documentVtable(doc).dom_document_create_processing_instruction.?(
|
||||
doc,
|
||||
try strFromData(target),
|
||||
try strFromData(data),
|
||||
&pi,
|
||||
);
|
||||
try DOMErr(err);
|
||||
return pi.?;
|
||||
}
|
||||
|
||||
// DocumentHTML
|
||||
pub const DocumentHTML = c.dom_html_document;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user