Skip to content

Commit eb8c986

Browse files
committed
Recover persistent cast
1 parent 2698a33 commit eb8c986

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/v8.zig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,15 @@ pub fn Persistent(comptime T: type) type {
951951
};
952952
}
953953

954+
/// recoverCast is not meant to create a new Persistent, but instead to recover one for which we know that it is a Persistent.
955+
/// This can be used on an object that has previously been `castTo___`. This allows the user to store and operate on the
956+
/// underlying type without needing to extract it from the Persistent. Casting it back to Persistent allows us to reset it.
957+
pub fn recoverCast(data: T) Self {
958+
return .{
959+
.handle = @as(handleT, @ptrCast(data.handle)),
960+
};
961+
}
962+
954963
pub fn toValue(self: Self) Value {
955964
return .{
956965
.handle = self.handle,

0 commit comments

Comments
 (0)