Skip to content

Commit 02cd5e9

Browse files
committed
event_target: handle window target
1 parent a51c200 commit 02cd5e9

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/dom/event_target.zig

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const EventHandler = @import("../events/event.zig").EventHandler;
2929

3030
const DOMException = @import("exceptions.zig").DOMException;
3131
const Nod = @import("node.zig");
32+
const Window = @import("../html/window.zig").Window;
3233

3334
// EventTarget interfaces
3435
pub const Union = Nod.Union;
@@ -40,9 +41,10 @@ pub const EventTarget = struct {
4041
pub const mem_guarantied = true;
4142

4243
pub fn toInterface(et: *parser.EventTarget) !Union {
43-
// NOTE: for now we state that all EventTarget are Nodes
44-
// TODO: handle other types (eg. Window)
45-
return Nod.Node.toInterface(@as(*parser.Node, @ptrCast(et)));
44+
return switch (try parser.eventTargetGetType(et)) {
45+
.window => .{ .Window = @as(*Window, @ptrCast(et)) },
46+
.node => Nod.Node.toInterface(@as(*parser.Node, @ptrCast(et))),
47+
};
4648
}
4749

4850
// JS funcs

src/html/window.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub const Window = struct {
5757
return Window{
5858
.target = target orelse "",
5959
.navigator = navigator orelse .{},
60+
.base = .{ .et_type = @intFromEnum(parser.EventTargetType.window) },
6061
};
6162
}
6263

0 commit comments

Comments
 (0)