dom: implement NonDocumentTypeChildNode mixin for element

This commit is contained in:
Pierre Tachoire
2023-12-13 16:16:57 +01:00
parent 6332b1af41
commit a9fee9be07
7 changed files with 168 additions and 0 deletions

View File

@@ -177,6 +177,24 @@ pub const Element = struct {
return try children.get_length();
}
// NonDocumentTypeChildNode
// https://dom.spec.whatwg.org/#interface-nondocumenttypechildnode
pub fn get_previousElementSibling(self: *parser.Element) !?Union {
const res = try parser.nodePreviousElementSibling(parser.elementToNode(self));
if (res == null) {
return null;
}
return try HTMLElem.toInterface(HTMLElem.Union, res.?);
}
pub fn get_nextElementSibling(self: *parser.Element) !?Union {
const res = try parser.nodeNextElementSibling(parser.elementToNode(self));
if (res == null) {
return null;
}
return try HTMLElem.toInterface(HTMLElem.Union, res.?);
}
pub fn deinit(_: *parser.Element, _: std.mem.Allocator) void {}
};
@@ -257,4 +275,11 @@ pub fn testExecFn(
.{ .src = "c.childElementCount", .ex = "3" },
};
try checkCases(js_env, &parentNode);
var elementSibling = [_]Case{
.{ .src = "let d = document.getElementById('para')", .ex = "undefined" },
.{ .src = "d.previousElementSibling.nodeName", .ex = "P" },
.{ .src = "d.nextElementSibling", .ex = "null" },
};
try checkCases(js_env, &elementSibling);
}