Skip to content

Conversation

@karlseguin
Copy link
Collaborator

Crypto.getRandomValues should mutate the given parameter as well as return the value. This return value must be the same (JsObject) as the input parameter.

There might be more magical ways to solve this, but I opted for both the simplest and most flexible: adding a toZig function to JsObject which does what js.zig does internally when mapping js values to Zig (and, of course, it uses the same code).

This allows a caller to receive a JsObject (not too common, but we already do that in a few places) and return that same JsObject (again, not too common, but we do have support for returning JsObject directly already). With the main addition that the JsObjet can now be turned into a Zig type by the caller.

Crypto.getRandomValues should mutate the given parameter as well as return
the value. This return value must be the same (JsObject) as the input parameter.

There might be more magical ways to solve this, but I opted for both the
simplest and most flexible: adding a `toZig` function to JsObject which does
what js.zig does internally when mapping js values to Zig (and, of course, it
uses the same code).

This allows a caller to receive a JsObject (not too common, but we already do
that in a few places) and return that same JsObject (again, not too common, but
we do have support for returning JsObject directly already). With the main
addition that the JsObjet can now be turned into a Zig type by the caller.
@karlseguin karlseguin merged commit 8de27b3 into main Jun 26, 2025
11 checks passed
@karlseguin karlseguin deleted the crypto_get_random_values_fix branch June 26, 2025 03:43
@github-actions github-actions bot locked and limited conversation to collaborators Jun 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants