spread new stringToPersistedFunction

This commit is contained in:
Halil Durak
2026-03-10 19:16:20 +03:00
parent 9d2ba52160
commit ba3da32ce6
2 changed files with 10 additions and 15 deletions

View File

@@ -387,22 +387,17 @@ pub fn getAttributeFunction(
} }
const attr = element.getAttributeSafe(.wrap(@tagName(listener_type))) orelse return null; const attr = element.getAttributeSafe(.wrap(@tagName(listener_type))) orelse return null;
const callback = page.js.stringToPersistedFunction(attr) catch |err| switch (err) { const function = page.js.stringToPersistedFunction(attr, &.{"event"}, &.{}) catch |err| {
error.OutOfMemory => return err, // Not a valid expression; log this to find out if its something we should be supporting.
else => { log.warn(.js, "Html.getAttributeFunction", .{
// Not a valid expression; log this to find out if its something we should be supporting. .expression = attr,
log.warn(.js, "Html.getAttributeFunction", .{ .err = err,
.expression = attr, });
.err = err, return null;
});
return null;
},
}; };
try self.setAttributeListener(listener_type, callback, page); try self.setAttributeListener(listener_type, function, page);
return function;
return callback;
} }
pub fn hasAttributeFunction(self: *HtmlElement, listener_type: GlobalEventHandler, page: *const Page) bool { pub fn hasAttributeFunction(self: *HtmlElement, listener_type: GlobalEventHandler, page: *const Page) bool {

View File

@@ -50,7 +50,7 @@ pub const Build = struct {
pub fn complete(node: *Node, page: *Page) !void { pub fn complete(node: *Node, page: *Page) !void {
const el = node.as(Element); const el = node.as(Element);
const on_load = el.getAttributeSafe(comptime .wrap("onload")) orelse return; const on_load = el.getAttributeSafe(comptime .wrap("onload")) orelse return;
if (page.js.stringToPersistedFunction(on_load)) |func| { if (page.js.stringToPersistedFunction(on_load, &.{"event"}, &.{})) |func| {
page.window._on_load = func; page.window._on_load = func;
} else |err| { } else |err| {
log.err(.js, "body.onload", .{ .err = err, .str = on_load }); log.err(.js, "body.onload", .{ .err = err, .str = on_load });