@@ -20,6 +20,7 @@ const std = @import("std");
2020
2121const parser = @import ("../netsurf.zig" );
2222const Node = @import ("node.zig" ).Node ;
23+ const SessionState = @import ("../env.zig" ).SessionState ;
2324
2425// https://dom.spec.whatwg.org/#processinginstruction
2526pub const ProcessingInstruction = struct {
@@ -35,8 +36,15 @@ pub const ProcessingInstruction = struct {
3536 return try parser .nodeName (parser .processingInstructionToNode (self ));
3637 }
3738
38- pub fn _cloneNode (self : * parser.ProcessingInstruction , _ : ? bool ) ! * parser.ProcessingInstruction {
39- return try parser .processInstructionCopy (self );
39+ // There's something wrong when we try to clone a ProcessInstruction normally.
40+ // The resulting object can't be cast back into a node (it crashes). This is
41+ // a simple workaround.
42+ pub fn _cloneNode (self : * parser.ProcessingInstruction , _ : ? bool , state : * SessionState ) ! * parser.ProcessingInstruction {
43+ return try parser .documentCreateProcessingInstruction (
44+ @ptrCast (state .document ),
45+ try get_target (self ),
46+ (try get_data (self )) orelse "" ,
47+ );
4048 }
4149
4250 pub fn get_data (self : * parser.ProcessingInstruction ) ! ? []const u8 {
@@ -91,6 +99,7 @@ test "Browser.DOM.ProcessingInstruction" {
9199 .{ "pi.data" , "foo" },
92100
93101 .{ "let pi2 = pi.cloneNode()" , "undefined" },
102+ .{ "pi2.nodeType" , "7" },
94103 }, .{});
95104
96105 try runner .testCases (&.{
0 commit comments