Skip to content

Commit b98bdea

Browse files
committed
window.length dynamically
1 parent 221274b commit b98bdea

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/browser/dom/nodelist.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub const NodeList = struct {
110110
try self.nodes.append(alloc, node);
111111
}
112112

113-
pub fn get_length(self: *NodeList) u32 {
113+
pub fn get_length(self: *const NodeList) u32 {
114114
return @intCast(self.nodes.items.len);
115115
}
116116

src/browser/html/window.zig

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const MediaQueryList = @import("media_query_list.zig").MediaQueryList;
3434
const Performance = @import("../dom/performance.zig").Performance;
3535
const CSSStyleDeclaration = @import("../cssom/CSSStyleDeclaration.zig");
3636
const Screen = @import("screen.zig").Screen;
37+
const domcss = @import("../dom/css.zig");
3738
const Css = @import("../css/css.zig").Css;
3839

3940
const Function = Env.Function;
@@ -134,9 +135,16 @@ pub const Window = struct {
134135
pub fn get_frames(self: *Window) *Window {
135136
return self;
136137
}
137-
// TODO: frames
138-
pub fn get_length(_: *Window) u32 {
139-
return 0;
138+
139+
// Retrieve the numbre of frames/iframes from the DOM dynamically.
140+
pub fn get_length(self: *const Window, page: *Page) !u32 {
141+
const frames = try domcss.querySelectorAll(
142+
page.call_arena,
143+
parser.documentHTMLToNode(self.document),
144+
"frame,iframe",
145+
);
146+
147+
return frames.get_length();
140148
}
141149

142150
pub fn get_top(self: *Window) *Window {

0 commit comments

Comments
 (0)