event_target: handle window target

This commit is contained in:
Pierre Tachoire
2025-01-21 13:49:09 +01:00
parent a51c20068f
commit 02cd5e98f9
2 changed files with 6 additions and 3 deletions

View File

@@ -29,6 +29,7 @@ const EventHandler = @import("../events/event.zig").EventHandler;
const DOMException = @import("exceptions.zig").DOMException;
const Nod = @import("node.zig");
const Window = @import("../html/window.zig").Window;
// EventTarget interfaces
pub const Union = Nod.Union;
@@ -40,9 +41,10 @@ pub const EventTarget = struct {
pub const mem_guarantied = true;
pub fn toInterface(et: *parser.EventTarget) !Union {
// NOTE: for now we state that all EventTarget are Nodes
// TODO: handle other types (eg. Window)
return Nod.Node.toInterface(@as(*parser.Node, @ptrCast(et)));
return switch (try parser.eventTargetGetType(et)) {
.window => .{ .Window = @as(*Window, @ptrCast(et)) },
.node => Nod.Node.toInterface(@as(*parser.Node, @ptrCast(et))),
};
}
// JS funcs

View File

@@ -57,6 +57,7 @@ pub const Window = struct {
return Window{
.target = target orelse "",
.navigator = navigator orelse .{},
.base = .{ .et_type = @intFromEnum(parser.EventTargetType.window) },
};
}