Merge pull request #1099 from lightpanda-io/nikneym/qol-changes
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / cdp-and-hyperfine-bench (push) Has been cancelled
e2e-test / perf-fmt (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / browser fetch (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
nightly build / build-linux-x86_64 (push) Has been cancelled
nightly build / build-linux-aarch64 (push) Has been cancelled
nightly build / build-macos-aarch64 (push) Has been cancelled
nightly build / build-macos-x86_64 (push) Has been cancelled
wpt / web platform tests json output (push) Has been cancelled
wpt / perf-fmt (push) Has been cancelled

Small changes
This commit is contained in:
Karl Seguin
2025-09-29 17:39:32 +08:00
committed by GitHub
2 changed files with 24 additions and 39 deletions

View File

@@ -192,11 +192,9 @@ pub const Element = struct {
// a new fragment // a new fragment
const clean = try parser.documentCreateDocumentFragment(doc); const clean = try parser.documentCreateDocumentFragment(doc);
const children = try parser.nodeGetChildNodes(body); const children = try parser.nodeGetChildNodes(body);
const ln = parser.nodeListLength(children); // always index 0, because nodeAppendChild moves the node out of
for (0..ln) |_| { // the nodeList and into the new tree
// always index 0, because nodeAppendChild moves the node out of while (parser.nodeListItem(children, 0)) |child| {
// the nodeList and into the new tree
const child = parser.nodeListItem(children, 0) orelse continue;
_ = try parser.nodeAppendChild(@ptrCast(@alignCast(clean)), child); _ = try parser.nodeAppendChild(@ptrCast(@alignCast(clean)), child);
} }
@@ -210,22 +208,18 @@ pub const Element = struct {
{ {
// First, copy some of the head element // First, copy some of the head element
const children = try parser.nodeGetChildNodes(head); const children = try parser.nodeGetChildNodes(head);
const ln = parser.nodeListLength(children); // always index 0, because nodeAppendChild moves the node out of
for (0..ln) |_| { // the nodeList and into the new tree
// always index 0, because nodeAppendChild moves the node out of while (parser.nodeListItem(children, 0)) |child| {
// the nodeList and into the new tree
const child = parser.nodeListItem(children, 0) orelse continue;
_ = try parser.nodeAppendChild(node, child); _ = try parser.nodeAppendChild(node, child);
} }
} }
{ {
const children = try parser.nodeGetChildNodes(body); const children = try parser.nodeGetChildNodes(body);
const ln = parser.nodeListLength(children); // always index 0, because nodeAppendChild moves the node out of
for (0..ln) |_| { // the nodeList and into the new tree
// always index 0, because nodeAppendChild moves the node out of while (parser.nodeListItem(children, 0)) |child| {
// the nodeList and into the new tree
const child = parser.nodeListItem(children, 0) orelse continue;
_ = try parser.nodeAppendChild(node, child); _ = try parser.nodeAppendChild(node, child);
} }
} }

View File

@@ -2500,31 +2500,22 @@ fn parseParams(enc: ?[:0]const u8) c.dom_hubbub_parser_params {
} }
fn parseData(parser: *c.dom_hubbub_parser, reader: anytype) !void { fn parseData(parser: *c.dom_hubbub_parser, reader: anytype) !void {
var err: c.hubbub_error = undefined; var buffer: [1024]u8 = undefined;
const TI = @typeInfo(@TypeOf(reader)); var ln = buffer.len;
if (TI == .pointer and @hasDecl(TI.pointer.child, "next")) { while (ln > 0) {
while (try reader.next()) |data| { ln = try reader.read(&buffer);
err = c.dom_hubbub_parser_parse_chunk(parser, data.ptr, data.len); const err = c.dom_hubbub_parser_parse_chunk(parser, &buffer, ln);
try parserErr(err); // TODO handle encoding change error return.
} // When the HTML contains a META tag with a different encoding than the
} else { // original one, a c.DOM_HUBBUB_HUBBUB_ERR_ENCODINGCHANGE error is
var buffer: [1024]u8 = undefined; // returned.
var ln = buffer.len; // In this case, we must restart the parsing with the new detected
while (ln > 0) { // encoding. The detected encoding is stored in the document and we can
ln = try reader.read(&buffer); // get it with documentGetInputEncoding().
err = c.dom_hubbub_parser_parse_chunk(parser, &buffer, ln); try parserErr(err);
// TODO handle encoding change error return.
// When the HTML contains a META tag with a different encoding than the
// original one, a c.DOM_HUBBUB_HUBBUB_ERR_ENCODINGCHANGE error is
// returned.
// In this case, we must restart the parsing with the new detected
// encoding. The detected encoding is stored in the document and we can
// get it with documentGetInputEncoding().
try parserErr(err);
}
} }
err = c.dom_hubbub_parser_completed(parser); const err = c.dom_hubbub_parser_completed(parser);
try parserErr(err); return parserErr(err);
} }
// documentHTMLClose closes the document. // documentHTMLClose closes the document.