Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/netsurf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ const c = @cImport({
const mimalloc = @import("mimalloc.zig");

const Callback = @import("jsruntime").Callback;
const CallbackResult = @import("jsruntime").CallbackResult;
const EventToInterface = @import("events/event.zig").Event.toInterface;

const log = std.log.scoped(.netsurf);

// init initializes netsurf lib.
// init starts a mimalloc heap arena for the netsurf session. The caller must
// call deinit() to free the arena memory.
Expand Down Expand Up @@ -534,13 +537,24 @@ const event_handler = struct {
if (data) |d| {
const func = event_handler_cbk(d);

// TODO get the allocator by another way?
var res = CallbackResult.init(func.nat_ctx.alloc);
defer res.deinit();

if (event) |evt| {
func.call(.{
func.trycall(.{
EventToInterface(evt) catch unreachable,
}) catch unreachable;
}, &res) catch {};
} else {
func.call(.{event}) catch unreachable;
func.trycall(.{event}, &res) catch {};
}

// in case of function error, we log the result and the trace.
if (!res.success) {
log.info("event handler error: {s}", .{res.result orelse "unknown"});
log.debug("{s}", .{res.stack orelse "no stack trace"});
}

// NOTE: we can not call func.deinit here
// b/c the handler can be called several times
// either on this dispatch event or in anoter one
Expand Down