add trycatch to Intersection and Performance Observers

This commit is contained in:
Karl Seguin
2026-01-13 12:55:10 +08:00
parent d9d8f68bf8
commit 4841f8cc8f
3 changed files with 16 additions and 4 deletions

View File

@@ -17,6 +17,8 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
const std = @import("std");
const js = @import("../js/js.zig");
const log = @import("../../log.zig");
const Page = @import("../Page.zig");
const Element = @import("Element.zig");
const DOMRect = @import("DOMRect.zig");
@@ -238,7 +240,11 @@ pub fn deliverEntries(self: *IntersectionObserver, page: *Page) !void {
}
const entries = try self.takeRecords(page);
try self._callback.call(void, .{ entries, self });
var result: js.Function.Result = undefined;
self._callback.tryCall(void, .{ entries, self }, &result) catch |err| {
log.err(.page, "IntsctObserver.deliverEntries", .{ .err = result.exception, .stack = result.stack });
return err;
};
}
pub const IntersectionObserverEntry = struct {

View File

@@ -19,6 +19,8 @@
const std = @import("std");
const js = @import("../js/js.zig");
const log = @import("../../log.zig");
const Page = @import("../Page.zig");
const Performance = @import("Performance.zig");
@@ -149,7 +151,11 @@ pub inline fn hasRecords(self: *const PerformanceObserver) bool {
/// Runs the PerformanceObserver's callback with records; emptying it out.
pub fn dispatch(self: *PerformanceObserver, page: *Page) !void {
const records = try self.takeRecords(page);
_ = try self._callback.call(void, .{ EntryList{ ._entries = records }, self });
var result: js.Function.Result = undefined;
self._callback.tryCall(void, .{ EntryList{ ._entries = records }, self }, &result) catch |err| {
log.err(.page, "PerfObserver.dispatch", .{ .err = result.exception, .stack = result.stack });
return err;
};
}
pub const JsApi = struct {