mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-15 07:48:58 +00:00
HTMLDocument: applets return empty collection
This commit is contained in:
@@ -17,10 +17,12 @@ const Matcher = union(enum) {
|
|||||||
matchByClassName: MatchByClassName,
|
matchByClassName: MatchByClassName,
|
||||||
matchByLinks: MatchByLinks,
|
matchByLinks: MatchByLinks,
|
||||||
matchTrue: struct {},
|
matchTrue: struct {},
|
||||||
|
matchFalse: struct {},
|
||||||
|
|
||||||
pub fn match(self: Matcher, node: *parser.Node) !bool {
|
pub fn match(self: Matcher, node: *parser.Node) !bool {
|
||||||
switch (self) {
|
switch (self) {
|
||||||
inline .matchTrue => return true,
|
inline .matchTrue => return true,
|
||||||
|
inline .matchFalse => return false,
|
||||||
inline .matchByTagName => |case| return case.match(node),
|
inline .matchByTagName => |case| return case.match(node),
|
||||||
inline .matchByClassName => |case| return case.match(node),
|
inline .matchByClassName => |case| return case.match(node),
|
||||||
inline .matchByName => |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 {
|
pub fn deinit(self: Matcher, alloc: std.mem.Allocator) void {
|
||||||
switch (self) {
|
switch (self) {
|
||||||
inline .matchTrue => return,
|
inline .matchTrue => return,
|
||||||
|
inline .matchFalse => return,
|
||||||
inline .matchByTagName => |case| return case.deinit(alloc),
|
inline .matchByTagName => |case| return case.deinit(alloc),
|
||||||
inline .matchByClassName => |case| return case.deinit(alloc),
|
inline .matchByClassName => |case| return case.deinit(alloc),
|
||||||
inline .matchByName => |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
|
// MatchByLinks matches the a and area elements in the Document that have href
|
||||||
// attributes.
|
// attributes.
|
||||||
// https://html.spec.whatwg.org/#dom-document-links
|
// https://html.spec.whatwg.org/#dom-document-links
|
||||||
@@ -204,6 +216,7 @@ pub fn HTMLCollectionByLinks(
|
|||||||
const Walker = union(enum) {
|
const Walker = union(enum) {
|
||||||
walkerDepthFirst: WalkerDepthFirst,
|
walkerDepthFirst: WalkerDepthFirst,
|
||||||
walkerChildren: WalkerChildren,
|
walkerChildren: WalkerChildren,
|
||||||
|
walkerNone: WalkerNone,
|
||||||
|
|
||||||
pub fn get_next(self: Walker, root: *parser.Node, cur: ?*parser.Node) !?*parser.Node {
|
pub fn get_next(self: Walker, root: *parser.Node, cur: ?*parser.Node) !?*parser.Node {
|
||||||
switch (self) {
|
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
|
// 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.
|
||||||
|
|||||||
@@ -126,6 +126,10 @@ pub const HTMLDocument = struct {
|
|||||||
return try collection.HTMLCollectionByTagName(alloc, try rootNode(self), "script", false);
|
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 {
|
pub fn get_links(self: *parser.DocumentHTML) !collection.HTMLCollection {
|
||||||
return try collection.HTMLCollectionByLinks(try rootNode(self), false);
|
return try collection.HTMLCollectionByLinks(try rootNode(self), false);
|
||||||
}
|
}
|
||||||
@@ -164,6 +168,7 @@ pub fn testExecFn(
|
|||||||
.{ .src = "document.scripts.length", .ex = "0" },
|
.{ .src = "document.scripts.length", .ex = "0" },
|
||||||
.{ .src = "document.forms.length", .ex = "0" },
|
.{ .src = "document.forms.length", .ex = "0" },
|
||||||
.{ .src = "document.links.length", .ex = "1" },
|
.{ .src = "document.links.length", .ex = "1" },
|
||||||
|
.{ .src = "document.applets.length", .ex = "0" },
|
||||||
.{ .src = "document.currentScript", .ex = "null" },
|
.{ .src = "document.currentScript", .ex = "null" },
|
||||||
};
|
};
|
||||||
try checkCases(js_env, &getters);
|
try checkCases(js_env, &getters);
|
||||||
|
|||||||
Reference in New Issue
Block a user