Merge pull request #1530 from lightpanda-io/node_contains_null

Allow node.contains(null) (false), per spec
This commit is contained in:
Pierre Tachoire
2026-02-12 09:48:14 +01:00
committed by GitHub
2 changed files with 16 additions and 1 deletions

View File

@@ -210,3 +210,16 @@
testing.expectEqual('HTMLDivElement', disconnectedChild.getRootNode().__proto__.constructor.name); testing.expectEqual('HTMLDivElement', disconnectedChild.getRootNode().__proto__.constructor.name);
testing.expectEqual('HTMLDivElement', disconnectedChild.getRootNode({ composed: true }).__proto__.constructor.name); testing.expectEqual('HTMLDivElement', disconnectedChild.getRootNode({ composed: true }).__proto__.constructor.name);
</script> </script>
<div id=contains><div id=other></div></div>
<script id=contains>
{
const d1 = $('#contains');
const d2 = $('#other');
testing.expectEqual(false, d1.contains(null));
testing.expectEqual(true, d1.contains(d1));
testing.expectEqual(false, d2.contains(d1));
testing.expectEqual(true, d1.contains(d2));
testing.expectEqual(false, d1.contains(p1));
}
</script>

View File

@@ -413,7 +413,9 @@ pub fn getRootNode(self: *Node, opts_: ?GetRootNodeOpts) *Node {
return root; return root;
} }
pub fn contains(self: *const Node, child: *const Node) bool { pub fn contains(self: *const Node, child_: ?*const Node) bool {
const child = child_ orelse return false;
if (self == child) { if (self == child) {
// yes, this is correct // yes, this is correct
return true; return true;