From 2698a334158faf6810156c75821bcca5d377eeee Mon Sep 17 00:00:00 2001 From: sjorsdonkers <72333389+sjorsdonkers@users.noreply.github.com> Date: Fri, 25 Apr 2025 12:22:58 +0200 Subject: [PATCH 1/2] Persist more types --- src/v8.zig | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/v8.zig b/src/v8.zig index b384f99..2c2056b 100644 --- a/src/v8.zig +++ b/src/v8.zig @@ -934,6 +934,23 @@ pub fn Persistent(comptime T: type) type { }; } + pub fn castToFunctionTemplate(self: Self) FunctionTemplate { + return .{ + .handle = @as(*const c.FunctionTemplate, @ptrCast(self.handle)), + }; + } + pub fn castToObjectTemplate(self: Self) ObjectTemplate { + return .{ + .handle = @as(*const c.ObjectTemplate, @ptrCast(self.handle)), + }; + } + + pub fn castToContext(self: Self) Context { + return .{ + .handle = @as(*const c.Context, @ptrCast(self.handle)), + }; + } + pub fn toValue(self: Self) Value { return .{ .handle = self.handle, @@ -2068,7 +2085,7 @@ pub const Value = struct { } pub fn isBigUint64Array(self: Self) bool { - return c.v8__Value__IsBigUint64Array (self.handle); + return c.v8__Value__IsBigUint64Array(self.handle); } pub fn isFloat32Array(self: Self) bool { From eb8c98608e74f86e112808de12d84886d800c2fb Mon Sep 17 00:00:00 2001 From: sjorsdonkers <72333389+sjorsdonkers@users.noreply.github.com> Date: Fri, 25 Apr 2025 16:01:53 +0200 Subject: [PATCH 2/2] Recover persistent cast --- src/v8.zig | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/v8.zig b/src/v8.zig index 2c2056b..dd360ed 100644 --- a/src/v8.zig +++ b/src/v8.zig @@ -951,6 +951,15 @@ pub fn Persistent(comptime T: type) type { }; } + /// recoverCast is not meant to create a new Persistent, but instead to recover one for which we know that it is a Persistent. + /// This can be used on an object that has previously been `castTo___`. This allows the user to store and operate on the + /// underlying type without needing to extract it from the Persistent. Casting it back to Persistent allows us to reset it. + pub fn recoverCast(data: T) Self { + return .{ + .handle = @as(handleT, @ptrCast(data.handle)), + }; + } + pub fn toValue(self: Self) Value { return .{ .handle = self.handle,