mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
dom: add HTMLCollectionIterator
This commit is contained in:
committed by
Francis Bouvier
parent
7cef1bb550
commit
0b17d79baa
@@ -338,6 +338,34 @@ pub const WalkerNone = struct {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const HTMLCollectionIterator = struct {
|
||||||
|
pub const mem_guarantied = true;
|
||||||
|
|
||||||
|
coll: *HTMLCollection,
|
||||||
|
index: u32 = 0,
|
||||||
|
|
||||||
|
pub const Return = struct {
|
||||||
|
value: ?Union,
|
||||||
|
done: bool,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn _next(self: *HTMLCollectionIterator, allocator: std.mem.Allocator) !Return {
|
||||||
|
const e = try self.coll._item(allocator, self.index);
|
||||||
|
if (e == null) {
|
||||||
|
return Return{
|
||||||
|
.value = null,
|
||||||
|
.done = true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
self.index += 1;
|
||||||
|
return Return{
|
||||||
|
.value = e,
|
||||||
|
.done = false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// WEB IDL https://dom.spec.whatwg.org/#htmlcollection
|
// WEB IDL https://dom.spec.whatwg.org/#htmlcollection
|
||||||
// HTMLCollection is re implemented in zig here because libdom
|
// HTMLCollection is re implemented in zig here because libdom
|
||||||
// dom_html_collection expects a comparison function callback as arguement.
|
// dom_html_collection expects a comparison function callback as arguement.
|
||||||
@@ -370,6 +398,12 @@ pub const HTMLCollection = struct {
|
|||||||
return try self.walker.get_next(self.root.?, null);
|
return try self.walker.get_next(self.root.?, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn _symbol_iterator(self: *HTMLCollection) HTMLCollectionIterator {
|
||||||
|
return HTMLCollectionIterator{
|
||||||
|
.coll = self,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// get_length computes the collection's length dynamically according to
|
/// get_length computes the collection's length dynamically according to
|
||||||
/// the current root structure.
|
/// the current root structure.
|
||||||
// TODO: nodes retrieved must be de-referenced.
|
// TODO: nodes retrieved must be de-referenced.
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ const Document = @import("document.zig").Document;
|
|||||||
const DocumentType = @import("document_type.zig").DocumentType;
|
const DocumentType = @import("document_type.zig").DocumentType;
|
||||||
const DocumentFragment = @import("document_fragment.zig").DocumentFragment;
|
const DocumentFragment = @import("document_fragment.zig").DocumentFragment;
|
||||||
const HTMLCollection = @import("html_collection.zig").HTMLCollection;
|
const HTMLCollection = @import("html_collection.zig").HTMLCollection;
|
||||||
|
const HTMLCollectionIterator = @import("html_collection.zig").HTMLCollectionIterator;
|
||||||
|
|
||||||
// HTML
|
// HTML
|
||||||
const HTML = @import("../html/html.zig");
|
const HTML = @import("../html/html.zig");
|
||||||
@@ -34,6 +35,7 @@ pub const Interfaces = generate.Tuple(.{
|
|||||||
DocumentType,
|
DocumentType,
|
||||||
DocumentFragment,
|
DocumentFragment,
|
||||||
HTMLCollection,
|
HTMLCollection,
|
||||||
|
HTMLCollectionIterator,
|
||||||
|
|
||||||
HTML.Interfaces,
|
HTML.Interfaces,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user