diff --git a/src/dom/html_collection.zig b/src/dom/html_collection.zig
index 6421282a..1f04ae84 100644
--- a/src/dom/html_collection.zig
+++ b/src/dom/html_collection.zig
@@ -17,10 +17,12 @@ const Matcher = union(enum) {
matchByClassName: MatchByClassName,
matchByLinks: MatchByLinks,
matchTrue: struct {},
+ matchFalse: struct {},
pub fn match(self: Matcher, node: *parser.Node) !bool {
switch (self) {
inline .matchTrue => return true,
+ inline .matchFalse => return false,
inline .matchByTagName => |case| return case.match(node),
inline .matchByClassName => |case| return case.match(node),
inline .matchByName => |case| return case.match(node),
@@ -31,6 +33,7 @@ const Matcher = union(enum) {
pub fn deinit(self: Matcher, alloc: std.mem.Allocator) void {
switch (self) {
inline .matchTrue => return,
+ inline .matchFalse => return,
inline .matchByTagName => |case| return case.deinit(alloc),
inline .matchByClassName => |case| return case.deinit(alloc),
inline .matchByName => |case| return case.deinit(alloc),
@@ -173,6 +176,15 @@ pub fn HTMLCollectionChildren(
};
}
+pub fn HTMLCollectionEmpty() !HTMLCollection {
+ return HTMLCollection{
+ .root = null,
+ .walker = Walker{ .walkerNone = .{} },
+ .matcher = Matcher{ .matchFalse = .{} },
+ .include_root = false,
+ };
+}
+
// MatchByLinks matches the a and area elements in the Document that have href
// attributes.
// https://html.spec.whatwg.org/#dom-document-links
@@ -204,6 +216,7 @@ pub fn HTMLCollectionByLinks(
const Walker = union(enum) {
walkerDepthFirst: WalkerDepthFirst,
walkerChildren: WalkerChildren,
+ walkerNone: WalkerNone,
pub fn get_next(self: Walker, root: *parser.Node, cur: ?*parser.Node) !?*parser.Node {
switch (self) {
@@ -277,6 +290,12 @@ pub const WalkerChildren = struct {
}
};
+pub const WalkerNone = struct {
+ pub fn get_next(_: WalkerNone, _: *parser.Node, _: ?*parser.Node) !?*parser.Node {
+ return null;
+ }
+};
+
// WEB IDL https://dom.spec.whatwg.org/#htmlcollection
// HTMLCollection is re implemented in zig here because libdom
// dom_html_collection expects a comparison function callback as arguement.
diff --git a/src/html/document.zig b/src/html/document.zig
index 4e933ed5..2e1e52b1 100644
--- a/src/html/document.zig
+++ b/src/html/document.zig
@@ -126,6 +126,10 @@ pub const HTMLDocument = struct {
return try collection.HTMLCollectionByTagName(alloc, try rootNode(self), "script", false);
}
+ pub fn get_applets(_: *parser.DocumentHTML) !collection.HTMLCollection {
+ return try collection.HTMLCollectionEmpty();
+ }
+
pub fn get_links(self: *parser.DocumentHTML) !collection.HTMLCollection {
return try collection.HTMLCollectionByLinks(try rootNode(self), false);
}
@@ -164,6 +168,7 @@ pub fn testExecFn(
.{ .src = "document.scripts.length", .ex = "0" },
.{ .src = "document.forms.length", .ex = "0" },
.{ .src = "document.links.length", .ex = "1" },
+ .{ .src = "document.applets.length", .ex = "0" },
.{ .src = "document.currentScript", .ex = "null" },
};
try checkCases(js_env, &getters);