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

@@ -934,8 +934,8 @@ pub const JsApi = struct {
pub const compatMode = bridge.accessor(Document.getCompatMode, null, .{}); pub const compatMode = bridge.accessor(Document.getCompatMode, null, .{});
pub const referrer = bridge.accessor(Document.getReferrer, null, .{}); pub const referrer = bridge.accessor(Document.getReferrer, null, .{});
pub const domain = bridge.accessor(Document.getDomain, null, .{}); pub const domain = bridge.accessor(Document.getDomain, null, .{});
pub const createElement = bridge.function(Document.createElement, .{.dom_exception = true}); pub const createElement = bridge.function(Document.createElement, .{ .dom_exception = true });
pub const createElementNS = bridge.function(Document.createElementNS, .{.dom_exception = true}); pub const createElementNS = bridge.function(Document.createElementNS, .{ .dom_exception = true });
pub const createDocumentFragment = bridge.function(Document.createDocumentFragment, .{}); pub const createDocumentFragment = bridge.function(Document.createDocumentFragment, .{});
pub const createComment = bridge.function(Document.createComment, .{}); pub const createComment = bridge.function(Document.createComment, .{});
pub const createTextNode = bridge.function(Document.createTextNode, .{}); pub const createTextNode = bridge.function(Document.createTextNode, .{});

View File

@@ -17,6 +17,8 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
const std = @import("std"); const std = @import("std");
const js = @import("../js/js.zig"); const js = @import("../js/js.zig");
const log = @import("../../log.zig");
const Page = @import("../Page.zig"); const Page = @import("../Page.zig");
const Element = @import("Element.zig"); const Element = @import("Element.zig");
const DOMRect = @import("DOMRect.zig"); const DOMRect = @import("DOMRect.zig");
@@ -238,7 +240,11 @@ pub fn deliverEntries(self: *IntersectionObserver, page: *Page) !void {
} }
const entries = try self.takeRecords(page); 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 { pub const IntersectionObserverEntry = struct {

View File

@@ -19,6 +19,8 @@
const std = @import("std"); const std = @import("std");
const js = @import("../js/js.zig"); const js = @import("../js/js.zig");
const log = @import("../../log.zig");
const Page = @import("../Page.zig"); const Page = @import("../Page.zig");
const Performance = @import("Performance.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. /// Runs the PerformanceObserver's callback with records; emptying it out.
pub fn dispatch(self: *PerformanceObserver, page: *Page) !void { pub fn dispatch(self: *PerformanceObserver, page: *Page) !void {
const records = try self.takeRecords(page); 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 { pub const JsApi = struct {