diff --git a/src/dom/element.zig b/src/dom/element.zig index 1a506681..8ab9d3c7 100644 --- a/src/dom/element.zig +++ b/src/dom/element.zig @@ -177,6 +177,20 @@ 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 +271,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); } diff --git a/tests/wpt/dom/nodes/Element-nextElementSibling-svg.svg b/tests/wpt/dom/nodes/Element-nextElementSibling-svg.svg new file mode 100644 index 00000000..3e17cad2 --- /dev/null +++ b/tests/wpt/dom/nodes/Element-nextElementSibling-svg.svg @@ -0,0 +1,23 @@ + + diff --git a/tests/wpt/dom/nodes/Element-nextElementSibling-xhtml.xhtml b/tests/wpt/dom/nodes/Element-nextElementSibling-xhtml.xhtml new file mode 100644 index 00000000..915209bd --- /dev/null +++ b/tests/wpt/dom/nodes/Element-nextElementSibling-xhtml.xhtml @@ -0,0 +1,23 @@ + + +
+The result of this test is unknown.
+ + + diff --git a/tests/wpt/dom/nodes/Element-nextElementSibling.html b/tests/wpt/dom/nodes/Element-nextElementSibling.html new file mode 100644 index 00000000..985c602f --- /dev/null +++ b/tests/wpt/dom/nodes/Element-nextElementSibling.html @@ -0,0 +1,18 @@ + + +The result of this test is unknown.
+ diff --git a/tests/wpt/dom/nodes/Element-previousElementSibling-svg.svg b/tests/wpt/dom/nodes/Element-previousElementSibling-svg.svg new file mode 100644 index 00000000..671d2c87 --- /dev/null +++ b/tests/wpt/dom/nodes/Element-previousElementSibling-svg.svg @@ -0,0 +1,28 @@ + + diff --git a/tests/wpt/dom/nodes/Element-previousElementSibling-xhtml.xhtml b/tests/wpt/dom/nodes/Element-previousElementSibling-xhtml.xhtml new file mode 100644 index 00000000..7fbbc6d3 --- /dev/null +++ b/tests/wpt/dom/nodes/Element-previousElementSibling-xhtml.xhtml @@ -0,0 +1,28 @@ + + + +The result of this test is +unknown. + + + +
+ + + diff --git a/tests/wpt/dom/nodes/Element-previousElementSibling.html b/tests/wpt/dom/nodes/Element-previousElementSibling.html new file mode 100644 index 00000000..02c7b16d --- /dev/null +++ b/tests/wpt/dom/nodes/Element-previousElementSibling.html @@ -0,0 +1,23 @@ + + +The result of this test is +unknown. + + + +
+