mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-04-03 16:10:29 +00:00
Create Zig wrapper generator for js.Function creation
This allows us to leverage the Caller.Function.call method, which does type mapping, caching, etc... and allows the Zig function callback to be written like any other Zig WebAPI function.
This commit is contained in:
@@ -82,13 +82,17 @@ pub fn createTypedArray(self: *const Local, comptime array_type: js.ArrayType, s
|
||||
return .init(self, size);
|
||||
}
|
||||
|
||||
pub fn newFunctionWithData(
|
||||
pub fn newCallback(
|
||||
self: *const Local,
|
||||
comptime callback: *const fn (?*const v8.FunctionCallbackInfo) callconv(.c) void,
|
||||
data: *anyopaque,
|
||||
callback: anytype,
|
||||
data: anytype,
|
||||
) js.Function {
|
||||
const external = self.isolate.createExternal(data);
|
||||
const handle = v8.v8__Function__New__DEFAULT2(self.handle, callback, @ptrCast(external)).?;
|
||||
const handle = v8.v8__Function__New__DEFAULT2(self.handle, struct {
|
||||
fn wrap(info_handle: ?*const js.v8.FunctionCallbackInfo) callconv(.c) void {
|
||||
Caller.Function.call(@TypeOf(data), info_handle.?, callback, .{ .embedded_receiver = true });
|
||||
}
|
||||
}.wrap, @ptrCast(external)).?;
|
||||
return .{ .local = self, .handle = handle };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user