Closed surma closed 3 months ago
I think we did it in this way initially assuming that all use-cases would want to return high-level Rust types from the callback, but taking a close look what you're suggesting, it doesn't seem like the right assumption and makes sense to me also because wrap_callback
immediately converts the JSValue
to a JSValueRef
in which case if you want to pass an existing JSValueRef
the process feels somewhat inefficient. I think that we could make it so that it works for both use cases, and let the caller decide what return type they are after depending on the use-case.
Another example of where it would be useful to be able to return a JSValueRef
would be if someone wants to return another function from their function. See this Zulip chat message for where this has come up.
Now that https://github.com/bytecodealliance/javy/pull/618 is merged, this is no longer an issue. I'll go ahead and close this issue.
Currently, the closure passed to
wrap_callback
isimpl FnMut(&Self, JSValueRef<'_>, &[JSValueRef<'_>]) -> Result<JSValue> + 'static
.This has worked well so far, however, this makes it impossible to return an already existing value and maintain referential equality. For example:
As
JSValue
is a context-independent representation of a JS value, would it make sense for a callback to always return a context-specific value, which can be easily created from a givenJSValue
usingto_qjs_value()
?(Side-note: Would be great to also implement
PartialEq
forJSValueRef
.)