window: partial implementation for indexed_get

This commit is contained in:
Pierre Tachoire
2025-08-06 18:28:53 +02:00
parent b98bdeaae7
commit 1b7abf9972

View File

@@ -136,6 +136,24 @@ pub const Window = struct {
return self;
}
pub fn indexed_get(self: *Window, index: u32, has_value: *bool, page: *Page) !*Window {
const frames = try domcss.querySelectorAll(
page.call_arena,
parser.documentHTMLToNode(self.document),
"frame,iframe",
);
if (index >= frames.nodes.items.len) {
has_value.* = false;
return undefined;
}
has_value.* = true;
// TODO return the correct frame's window
// frames.nodes.items[indexed]
return error.TODO;
}
// Retrieve the numbre of frames/iframes from the DOM dynamically.
pub fn get_length(self: *const Window, page: *Page) !u32 {
const frames = try domcss.querySelectorAll(
@@ -553,3 +571,26 @@ test "Browser.HTML.Window" {
}, .{});
}
}
test "Browser.HTML.Window.frames" {
var runner = try testing.jsRunner(testing.tracking_allocator, .{ .html =
\\<body>
\\ <iframe
\\ src="https://httpbin.io/html"
\\ title="iframea">
\\ </iframe>
\\ <iframe
\\ src="https://httpbin.io/html"
\\ title="iframeb">
\\ </iframe>
\\</body>
});
defer runner.deinit();
try runner.testCases(&.{
.{ "frames.length", "2" },
.{ "try { frames[1] } catch (e) { e }", "Error: TODO" }, // TODO fixme
.{ "frames[3]", "undefined" },
}, .{});
}