-
Notifications
You must be signed in to change notification settings - Fork 685
Support for ArrayBuffer::isMutableBuffer() and ArrayBuffer::getMutableBuffer() #1578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The team discussed this and we think it is a good idea. Thanks for proposing it! It is now in the short term TODO list. |
Thank you! 🙏 |
Question; does every Or does this only apply to |
Technically, today no ArrayBuffers have a I don't think we envisioned that it would, but at the same time I think that it could work. Do you have a motivating use case? |
Well, there's a nice use-case: mrousavy/nitro#601 I cannot access |
Uh oh!
There was an error while loading. Please reload this page.
Problem
In Nitro, array buffers are supported types for native modules.
Imagine the following native nitro module:
On the native side of
getEncryptionKey
, we can safely access theArrayBuffer
's data without any problems just fine because it is synchronous and we are running on the JS thread:..but as soon as we make this function asynchronous:
We can no longer safely access the
ArrayBuffer
's data because we are running on a separate Thread.I think it'd be a cool API to get access to the underlying
std::shared_ptr<jsi::MutableBuffer>
if it has one (not everyArrayBuffer
is created with one):Solution
jsi::ArrayBuffer::isMutableBuffer(..)
jsi::ArrayBuffer::getMutableBuffer(..)
jsi::ArrayBuffer::asMutableBuffer(..)
(?)Additional Context
In Nitro, I currently solved it like this:
nitro::ArrayBuffer
base classnitro::NativeArrayBuffer
class, which allows you to access data from any Thread and is owningnitro::JSArrayBuffer
class, which only allows you to access data on the JS ThreadIf I receive an
ArrayBuffer
from JS, it is currently always anitro::JSArrayBuffer
. I would love to look into it and unwrap thejsi::MutableBuffer
from it so I can optionally also pass the user anitro::NativeArrayBuffer
instead though.The text was updated successfully, but these errors were encountered: