Skip to content

Commit 1b7abf9

Browse files
committed
window: partial implementation for indexed_get
1 parent b98bdea commit 1b7abf9

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/browser/html/window.zig

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,24 @@ pub const Window = struct {
136136
return self;
137137
}
138138

139+
pub fn indexed_get(self: *Window, index: u32, has_value: *bool, page: *Page) !*Window {
140+
const frames = try domcss.querySelectorAll(
141+
page.call_arena,
142+
parser.documentHTMLToNode(self.document),
143+
"frame,iframe",
144+
);
145+
146+
if (index >= frames.nodes.items.len) {
147+
has_value.* = false;
148+
return undefined;
149+
}
150+
151+
has_value.* = true;
152+
// TODO return the correct frame's window
153+
// frames.nodes.items[indexed]
154+
return error.TODO;
155+
}
156+
139157
// Retrieve the numbre of frames/iframes from the DOM dynamically.
140158
pub fn get_length(self: *const Window, page: *Page) !u32 {
141159
const frames = try domcss.querySelectorAll(
@@ -553,3 +571,26 @@ test "Browser.HTML.Window" {
553571
}, .{});
554572
}
555573
}
574+
575+
test "Browser.HTML.Window.frames" {
576+
var runner = try testing.jsRunner(testing.tracking_allocator, .{ .html =
577+
\\<body>
578+
\\ <iframe
579+
\\ src="https://httpbin.io/html"
580+
\\ title="iframea">
581+
\\ </iframe>
582+
\\ <iframe
583+
\\ src="https://httpbin.io/html"
584+
\\ title="iframeb">
585+
\\ </iframe>
586+
\\</body>
587+
});
588+
589+
defer runner.deinit();
590+
591+
try runner.testCases(&.{
592+
.{ "frames.length", "2" },
593+
.{ "try { frames[1] } catch (e) { e }", "Error: TODO" }, // TODO fixme
594+
.{ "frames[3]", "undefined" },
595+
}, .{});
596+
}

0 commit comments

Comments
 (0)