Give EventManager.dispatch and explicit error set

This allows potentially recursive callers to use an implicit error set return.
This commit is contained in:
Karl Seguin
2026-02-11 12:50:59 +08:00
parent f54246eac1
commit 97d53b81a7
2 changed files with 13 additions and 2 deletions

View File

@@ -157,7 +157,18 @@ pub fn remove(self: *EventManager, target: *EventTarget, typ: []const u8, callba
}
}
pub fn dispatch(self: *EventManager, target: *EventTarget, event: *Event) !void {
// Dispatching can be recursive from the compiler's point of view, so we need to
// give it an explicit error set so that other parts of the code can use and
// inferred error.
const DispatchError = error{
OutOfMemory,
StringTooLarge,
JSExecCallback,
CompilationError,
ExecutionError,
JsException,
};
pub fn dispatch(self: *EventManager, target: *EventTarget, event: *Event) DispatchError!void {
if (comptime IS_DEBUG) {
log.debug(.event, "eventManager.dispatch", .{ .type = event._type_string.str(), .bubbles = event._bubbles });
}

View File

@@ -98,7 +98,7 @@ pub fn setOnSelectionChange(self: *Input, listener: ?js.Function) !void {
}
}
fn dispatchSelectionChangeEvent(self: *Input, page: *Page) anyerror!void {
fn dispatchSelectionChangeEvent(self: *Input, page: *Page) !void {
const event = try Event.init("selectionchange", .{ .bubbles = true }, page);
defer if (!event._v8_handoff) event.deinit(false);
try page._event_manager.dispatch(self.asElement().asEventTarget(), event);