Fix set_innerHTML, fix HTMLCollection fixed (postAttached) return type

This commit is contained in:
Karl Seguin
2025-05-30 13:32:29 +08:00
parent 7202d758a2
commit 2a4feb7bee
2 changed files with 13 additions and 6 deletions

View File

@@ -128,10 +128,10 @@ pub const Element = struct {
// append children to the node // append children to the node
const ln = try parser.nodeListLength(children); const ln = try parser.nodeListLength(children);
var i: u32 = 0; for (0..ln) |_| {
while (i < ln) { // always index 0, because ndoeAppendChild moves the node out of
defer i += 1; // the nodeList and into the new tree
const child = try parser.nodeListItem(children, i) orelse continue; const child = try parser.nodeListItem(children, 0) orelse continue;
_ = try parser.nodeAppendChild(node, child); _ = try parser.nodeAppendChild(node, child);
} }
} }
@@ -653,4 +653,10 @@ test "Browser.DOM.Element" {
.{ "a1.after('over 9000', a1_a);", "undefined" }, .{ "a1.after('over 9000', a1_a);", "undefined" },
.{ "after_container.innerHTML", "<div></div>over 9000<p></p>" }, .{ "after_container.innerHTML", "<div></div>over 9000<p></p>" },
}, .{}); }, .{});
try runner.testCases(&.{
.{ "var div1 = document.createElement('div');", null },
.{ "div1.innerHTML = \" <link/><table></table><a href='/a'>a</a><input type='checkbox'/>\"", null },
.{ "div1.getElementsByTagName('a').length", "1" },
}, .{});
} }

View File

@@ -432,7 +432,8 @@ pub const HTMLCollection = struct {
for (0..len) |i| { for (0..len) |i| {
const node = try self.item(@intCast(i)) orelse unreachable; const node = try self.item(@intCast(i)) orelse unreachable;
const e = @as(*parser.Element, @ptrCast(node)); const e = @as(*parser.Element, @ptrCast(node));
try js_this.setIndex(@intCast(i), e, .{}); const as_interface = try Element.toInterface(e);
try js_this.setIndex(@intCast(i), as_interface, .{});
if (try item_name(e)) |name| { if (try item_name(e)) |name| {
// Even though an entry might have an empty id, the spec says // Even though an entry might have an empty id, the spec says
@@ -440,7 +441,7 @@ pub const HTMLCollection = struct {
if (name.len > 0) { if (name.len > 0) {
// Named fields should not be enumerable (it is defined with // Named fields should not be enumerable (it is defined with
// the LegacyUnenumerableNamedProperties flag.) // the LegacyUnenumerableNamedProperties flag.)
try js_this.set(name, e, .{ .DONT_ENUM = true }); try js_this.set(name, as_interface, .{ .DONT_ENUM = true });
} }
} }
} }